Skip to contentSkip to conversation

sparc32: Fix div, udiv, mul, umul, rem, urem breakage

PATCH NAK Martin Habets 4 participants 10 messages Feb 11, 2006 – Feb 15, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc32: Fix div, udiv, mul, umul, rem, urem breakage

Rusty,

Thanks for explaining. As far as I remember this all started with the cleanup of an ugly #define, but I could be wrong there.

Dave,

The following patch changes the use of "_Div" to "div", etc, to resolve the following kind of warnings from depmod:
WARNING: /lib/modules/2.6.16-rc2-mph2/kernel/crypto/crc32c.ko needs unknown symbol div

The patch eliminates the need for another-special-case in modpost and depmod. Do you remember why this approach wasn't taken immediately? Please apply.

Quoted 11 lines · Rusty Russell

(1) it's just a warning, and it doesn't actually effect anything.
(2) Someone decided to be clever in arch/sparc/kernel/sparc_ksyms.c between 2.6.13 and 2.6.14. Rather than mangle ".div" to "div", they decided to mangle it to "_Div". The problem is that depmod knows about skipping the ".": it's done for other architectures. It has no idea about this new mangling.

2.6.12 did it the obvious way, 2.6.13 used asm, and 2.6.14 the new scheme. One wonders what was wrong with 2.6.12, but I haven't been following closely.

Quoted 6 lines

Now, possibly there was a legitimate reason not to pollute the namespace with these symbols, but they could probably have been made static without great concern.

Hope that clarifies,
Rusty.

Best regards,
Martin

---

arch/sparc/kernel/sparc_ksyms.c renamed from arch/sparc/kernel/sparc_ksyms.c.orig +12 -12
@@ -94,12 +94,12 @@
 /* Alias functions whose names begin with "." and export the aliases.
  * The module references will be fixed up by module_frob_arch_sections.
  */
-extern int _Div(int, int);
-extern int _Mul(int, int);
-extern int _Rem(int, int);
-extern unsigned _Udiv(unsigned, unsigned);
-extern unsigned _Umul(unsigned, unsigned);
-extern unsigned _Urem(unsigned, unsigned);
+extern int div(int, int);
+extern int mul(int, int);
+extern int rem(int, int);
+extern unsigned udiv(unsigned, unsigned);
+extern unsigned umul(unsigned, unsigned);
+extern unsigned urem(unsigned, unsigned);
 
 /* used by various drivers */
 EXPORT_SYMBOL(sparc_cpu_model);
@@ -309,12 +309,12 @@
 EXPORT_SYMBOL(__muldi3);
 EXPORT_SYMBOL(__divdi3);
 
-EXPORT_SYMBOL(_Rem);
-EXPORT_SYMBOL(_Urem);
-EXPORT_SYMBOL(_Mul);
-EXPORT_SYMBOL(_Umul);
-EXPORT_SYMBOL(_Div);
-EXPORT_SYMBOL(_Udiv);
+EXPORT_SYMBOL(rem);
+EXPORT_SYMBOL(urem);
+EXPORT_SYMBOL(mul);
+EXPORT_SYMBOL(umul);
+EXPORT_SYMBOL(div);
+EXPORT_SYMBOL(udiv);
 
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 EXPORT_SYMBOL(do_BUG);
scripts/mod/modpost.c renamed from scripts/mod/modpost.c.orig +0 -6
@@ -370,12 +370,6 @@
 			/* Ignore register directives. */
 			if (ELF_ST_TYPE(sym->st_info) = STT_SPARC_REGISTER)
 				break;
- 			if (symname[0] = '.') {
- 				char *munged = strdup(symname);
- 				munged[0] = '_';
- 				munged[1] = toupper(munged[1]);
- 				symname = munged;
- 			}
 		}
 #endif
 		
arch/sparc/kernel/module.c renamed from arch/sparc/kernel/module.c.orig +1 -2
@@ -66,8 +66,7 @@
 			else {
 				char *name = strtab + sym[i].st_name;
 				if (name[0] = '.') {
-					name[0] = '_';
-					name[1] = toupper(name[1]);
+					memmove(name, name+1, strlen(name));
 				}
 			}
 		}
arch/sparc/lib/mul.S renamed from arch/sparc/lib/mul.S.orig +2 -2
@@ -16,9 +16,9 @@
  */
 
 	.globl .mul
-	.globl _Mul
+	.globl mul
 .mul:
-_Mul:	/* needed for export */
+mul:	/* needed for export */
 	mov	%o0, %y		! multiplier -> Y
 	andncc	%o0, 0xfff, %g0	! test bits 12..31
 	be	Lmul_shortway	! if zero, can do it the short way
arch/sparc/lib/rem.S renamed from arch/sparc/lib/rem.S.orig +2 -2
@@ -43,9 +43,9 @@
 
 
 	.globl .rem
-	.globl _Rem
+	.globl rem
 .rem:
-_Rem:	/* needed for export */
+rem:	/* needed for export */
 	! compute sign of result; if neither is negative, no problem
 	orcc	%o1, %o0, %g0	! either negative?
 	bge	2f			! no, go do the divide
arch/sparc/lib/sdiv.S renamed from arch/sparc/lib/sdiv.S.orig +2 -2
@@ -43,9 +43,9 @@
 
 
 	.globl .div
-	.globl _Div
+	.globl div
 .div:
-_Div:	/* needed for export */
+div:	/* needed for export */
 	! compute sign of result; if neither is negative, no problem
 	orcc	%o1, %o0, %g0	! either negative?
 	bge	2f			! no, go do the divide
arch/sparc/lib/udiv.S renamed from arch/sparc/lib/udiv.S.orig +2 -2
@@ -43,9 +43,9 @@
 
 
 	.globl .udiv
-	.globl _Udiv
+	.globl udiv
 .udiv:
-_Udiv:	/* needed for export */
+udiv:	/* needed for export */
 
 	! Ready to divide.  Compute size of quotient; scale comparand.
 	orcc	%o1, %g0, %o5
arch/sparc/lib/umul.S renamed from arch/sparc/lib/umul.S.orig +2 -2
@@ -21,9 +21,9 @@
  */
 
 	.globl .umul
-	.globl _Umul
+	.globl umul
 .umul:
-_Umul:	/* needed for export */
+umul:	/* needed for export */
 	or	%o0, %o1, %o4
 	mov	%o0, %y		! multiplier -> Y
 
arch/sparc/lib/urem.S renamed from arch/sparc/lib/urem.S.orig +2 -2
@@ -41,9 +41,9 @@
  */
 
 	.globl .urem
-	.globl _Urem
+	.globl urem
 .urem:
-_Urem:	/* needed for export */
+urem:	/* needed for export */
 
 	! Ready to divide.  Compute size of quotient; scale comparand.
 	orcc	%o1, %g0, %o5
#2 lore raw
In reply to Martin Habets
Quoted 5 lines · William Lee Irwin III
Quoted 2 lines · Martin Habets

Thanks for explaining. As far as I remember this all started with the cleanup of an ugly #define, but I could be wrong there.

NAK.

a) namespace pollution()
b) it was a lot more than ugly #define, RTFArchives, please

#4 lore raw
In reply to Martin Habets
Quoted 4 lines · Martin Habets

Rusty,

Thanks for explaining. As far as I remember this all started with the cleanup of an ugly #define, but I could be wrong there.

It seems so, as Al so comprehensively explained. It was binutils breakage. You might find something like this (note: untested!) preferable. Other archs may well want EXPORT_SYMBOL_AS for special effects anyway.

Make sparc use the same "remove the dot" mangling as other archs, which depmod already understands. Avoid namespace pollution (not really a problem, but ugly) by using an __export_ alias: it needs to be a global symbol as attempts to craft an alias in the sparc_ksyms.c was rejected by various recent binutils versions:

http://marc.theaimsgroup.com/?l=linux-sparc&m2102634105866&w=2
http://marc.theaimsgroup.com/?l=linux-sparc&m2630905813914&w=2

arch/sparc/kernel/module.c +2 -4
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/kernel/module.c working-2.6.16-rc2-git6-sparcsyms/arch/sparc/kernel/module.c
@@ -65,10 +65,8 @@ int module_frob_arch_sections(Elf_Ehdr *
 				sym[i].st_shndx = SHN_ABS;
 			else {
 				char *name = strtab + sym[i].st_name;
-				if (name[0] = '.') {
-					name[0] = '_';
-					name[1] = toupper(name[1]);
-				}
+				if (name[0] = '.')
+					memmove(name, name+1, strlen(name));
 			}
 		}
 	}
arch/sparc/kernel/sparc_ksyms.c +17 -16
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/kernel/sparc_ksyms.c working-2.6.16-rc2-git6-sparcsyms/arch/sparc/kernel/sparc_ksyms.c
@@ -91,15 +91,23 @@ extern void ___rw_read_enter(void);
 extern void ___rw_read_exit(void);
 extern void ___rw_write_enter(void);
 
-/* Alias functions whose names begin with "." and export the aliases.
- * The module references will be fixed up by module_frob_arch_sections.
- */
-extern int _Div(int, int);
-extern int _Mul(int, int);
-extern int _Rem(int, int);
-extern unsigned _Udiv(unsigned, unsigned);
-extern unsigned _Umul(unsigned, unsigned);
-extern unsigned _Urem(unsigned, unsigned);
+/* depmod already trims "." from names to do name matches (for PPC
+ * etc), so we want to use the same scheme.  But simply aliasing div
+ * to .div here breaks on some binutils versions (eg. 2.16.91.0.3).
+ * Putting a global "div" in the asm files works, but we don't want to
+ * pollute the namespace.  So we export "div" via "__export_div". */
+extern int __export_div(int, int);
+extern int __export_mul(int, int);
+extern int __export_rem(int, int);
+extern unsigned __export_udiv(unsigned, unsigned);
+extern unsigned __export_umul(unsigned, unsigned);
+extern unsigned __export_urem(unsigned, unsigned);
+__EXPORT_SYMBOL_AS(__export_div, "div", "");
+__EXPORT_SYMBOL_AS(__export_mul, "mul", "");
+__EXPORT_SYMBOL_AS(__export_rem, "rem", "");
+__EXPORT_SYMBOL_AS(__export_udiv, "udiv", "");
+__EXPORT_SYMBOL_AS(__export_umul, "umul", "");
+__EXPORT_SYMBOL_AS(__export_urem, "urem", "");
 
 /* used by various drivers */
 EXPORT_SYMBOL(sparc_cpu_model);
@@ -309,13 +317,6 @@ EXPORT_SYMBOL(__lshrdi3);
 EXPORT_SYMBOL(__muldi3);
 EXPORT_SYMBOL(__divdi3);
 
-EXPORT_SYMBOL(_Rem);
-EXPORT_SYMBOL(_Urem);
-EXPORT_SYMBOL(_Mul);
-EXPORT_SYMBOL(_Umul);
-EXPORT_SYMBOL(_Div);
-EXPORT_SYMBOL(_Udiv);
-
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 EXPORT_SYMBOL(do_BUG);
 #endif
arch/sparc/lib/mul.S +2 -2
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/lib/mul.S working-2.6.16-rc2-git6-sparcsyms/arch/sparc/lib/mul.S
@@ -16,9 +16,9 @@
  */
 
 	.globl .mul
-	.globl _Mul
+	.globl __export_mul
 .mul:
-_Mul:	/* needed for export */
+__export_mul:
 	mov	%o0, %y		! multiplier -> Y
 	andncc	%o0, 0xfff, %g0	! test bits 12..31
 	be	Lmul_shortway	! if zero, can do it the short way
arch/sparc/lib/rem.S +2 -2
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/lib/rem.S working-2.6.16-rc2-git6-sparcsyms/arch/sparc/lib/rem.S
@@ -43,9 +43,9 @@
 
 
 	.globl .rem
-	.globl _Rem
+	.globl __export_rem
 .rem:
-_Rem:	/* needed for export */
+__export_rem:
 	! compute sign of result; if neither is negative, no problem
 	orcc	%o1, %o0, %g0	! either negative?
 	bge	2f			! no, go do the divide
arch/sparc/lib/sdiv.S +2 -2
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/lib/sdiv.S working-2.6.16-rc2-git6-sparcsyms/arch/sparc/lib/sdiv.S
@@ -43,9 +43,9 @@
 
 
 	.globl .div
-	.globl _Div
+	.globl __export_div
 .div:
-_Div:	/* needed for export */
+__export_div:
 	! compute sign of result; if neither is negative, no problem
 	orcc	%o1, %o0, %g0	! either negative?
 	bge	2f			! no, go do the divide
arch/sparc/lib/umul.S +2 -2
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/lib/umul.S working-2.6.16-rc2-git6-sparcsyms/arch/sparc/lib/umul.S
@@ -21,9 +21,9 @@
  */
 
 	.globl .umul
-	.globl _Umul
+	.globl __export_umul
 .umul:
-_Umul:	/* needed for export */
+__export_umul:
 	or	%o0, %o1, %o4
 	mov	%o0, %y		! multiplier -> Y
 
arch/sparc/lib/urem.S +2 -2
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/arch/sparc/lib/urem.S working-2.6.16-rc2-git6-sparcsyms/arch/sparc/lib/urem.S
@@ -41,9 +41,9 @@
  */
 
 	.globl .urem
-	.globl _Urem
+	.globl __export_urem
 .urem:
-_Urem:	/* needed for export */
+__export_urem:
 
 	! Ready to divide.  Compute size of quotient; scale comparand.
 	orcc	%o1, %g0, %o5
include/linux/module.h +4 -4
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.6.16-rc2-git6/include/linux/module.h working-2.6.16-rc2-git6-sparcsyms/include/linux/module.h
@@ -182,21 +182,21 @@ void *__symbol_get_gpl(const char *symbo
 #endif
 
 /* For every exported symbol, place a struct in the __ksymtab section */
-#define __EXPORT_SYMBOL(sym, sec)				\
+#define __EXPORT_SYMBOL_AS(sym, name, sec)			\
 	__CRC_SYMBOL(sym, sec)					\
 	static const char __kstrtab_##sym[]			\
 	__attribute__((section("__ksymtab_strings")))		\
-	= MODULE_SYMBOL_PREFIX #sym;                    	\
+	= MODULE_SYMBOL_PREFIX name;                    	\
 	static const struct kernel_symbol __ksymtab_##sym	\
 	__attribute_used__					\
 	__attribute__((section("__ksymtab" sec), unused))	\
 	= { (unsigned long)&sym, __kstrtab_##sym }
 
 #define EXPORT_SYMBOL(sym)					\
-	__EXPORT_SYMBOL(sym, "")
+	__EXPORT_SYMBOL_AS(sym, __stringify(sym), "")
 
 #define EXPORT_SYMBOL_GPL(sym)					\
-	__EXPORT_SYMBOL(sym, "_gpl")
+	__EXPORT_SYMBOL_AS(sym, __stringify(sym), "_gpl")
 
 #endif
 
Signature · 1 line
 ccontrol: http://ozlabs.org/~rusty/ccontrol
#5 lore raw
In reply to Martin Habets
Quoted 5 lines · Rusty Russell

It seems so, as Al so comprehensively explained. It was binutils breakage. You might find something like this (note: untested!) preferable. Other archs may well want EXPORT_SYMBOL_AS for special effects anyway.

Quoted 7 lines

Make sparc use the same "remove the dot" mangling as other archs, which depmod already understands. Avoid namespace pollution (not really a problem, but ugly) by using an __export_ alias: it needs to be a global symbol as attempts to craft an alias in the sparc_ksyms.c was rejected by various recent binutils versions:

ewww...

You do realize that your "remove the dot" is ppc-only? I.e. just as much of a special case as sparc-only mapping.

Seriously, fix in depmod is considerably smaller that what you've just posted, not to mention being conceptually simpler.

#6 lore raw
In reply to Martin Habets
Quoted 14 lines · Al Viro
Quoted 5 lines · Rusty Russell

It seems so, as Al so comprehensively explained. It was binutils breakage. You might find something like this (note: untested!) preferable. Other archs may well want EXPORT_SYMBOL_AS for special effects anyway.

Quoted 7 lines

Make sparc use the same "remove the dot" mangling as other archs, which depmod already understands. Avoid namespace pollution (not really a problem, but ugly) by using an __export_ alias: it needs to be a global symbol as attempts to craft an alias in the sparc_ksyms.c was rejected by various recent binutils versions:

Quoted 4 lines

ewww...

You do realize that your "remove the dot" is ppc-only? I.e. just as much of a special case as sparc-only mapping.

No Al. Since day 1 we've had this in module-init-tools. It was used by both PPC and Sparc.

Sparc stopped using it to work around sparc-specific binutils bugs. I'm naturally resistent to (more) arch-specific hacks in depmod. In the kernel, arch-specifics get testing, in module-init-tools they don't.

Quoted 2 lines

Seriously, fix in depmod is considerably smaller that what you've just posted, not to mention being conceptually simpler.

You're exactly right. By this logic, I look forward to you fixing binutils.

Glad we resolved that!
Rusty.

Signature · 1 line
 ccontrol: http://ozlabs.org/~rusty/ccontrol
#7 lore raw
In reply to Martin Habets
Quoted 5 lines · Rusty Russell
Quoted 2 lines

You do realize that your "remove the dot" is ppc-only? I.e. just as much of a special case as sparc-only mapping.

No Al. Since day 1 we've had this in module-init-tools. It was used by both PPC and Sparc.

... by PPC to deal with odd mangling of everything, in sparc - as a kludge for several libgcc symbols.

Quoted 3 lines

Sparc stopped using it to work around sparc-specific binutils bugs. I'm naturally resistent to (more) arch-specific hacks in depmod. In the kernel, arch-specifics get testing, in module-init-tools they don't.

It's not about sparc-specific binutils bug. At all. The thing responsible for that is gcc, not binutils.

Quoted 5 lines
Quoted 2 lines

Seriously, fix in depmod is considerably smaller that what you've just posted, not to mention being conceptually simpler.

You're exactly right. By this logic, I look forward to you fixing binutils.

What the hell does it have to do with binutils? There are two unrelated things:
* on ppc, gcc -S prepends . to public symbols - i.e. if foo.c
defines bar(), you'll get .bar in foo.s.
* on sparc, names used for primitives implemented in libgcc (and
emitted by gcc when generating a call of such primitive) start with .

Both sit in gcc; the only place where binutils had ever entered the picture was stricter handling of weak aliases. That broke original kludges in sparc_ksyms, but it's completely unrelated to problem with mangling on sparc.

If you are suggesting to rename symbols in sparc libgcc - sorry, can't do. They are part of ABI, for all practical purposes.

What I really don't get is why do we want to bother with mangling at all. I.e. why not define MODULE_SYMBOL_PREFIX to "." on ppc and be done with that? And do an equivalent of EXPORT_SYMBOL() for use in .s, which would be very useful thing in its own right...

#8 lore raw
In reply to Martin Habets

On Sun, 2006-02-12 at 03:14 +0000, Al Viro wrote:
[snip condescending rant]

Quoted 2 lines

And do an equivalent of EXPORT_SYMBOL() for use in .s, which would be very useful thing in its own right...

So you're going to do this and fix binutils? Great! Send me the patch when you're done.

Rusty.

Signature · 1 line
 ccontrol: http://ozlabs.org/~rusty/ccontrol
#9 lore raw
In reply to Martin Habets

So is anyone coming up with other patches regarding this? I like the idea of having an asm equivalent of EXPORT_SYMBOL().

If no other fixes are forthcoming, please apply either Rusty's patch or mine. I'd still prefer mine because it's simpler, which for me outweighs the namespace pollution issue.

Martin

Quoted 8 lines · Rusty Russell

On Sun, 2006-02-12 at 03:14 +0000, Al Viro wrote:
[snip condescending rant]

Quoted 2 lines

And do an equivalent of EXPORT_SYMBOL() for use in .s, which would be very useful thing in its own right...

So you're going to do this and fix binutils? Great! Send me the patch when you're done.