sparc: cannot load any modules with 2.6.17-rc3
PATCH 1/1 sparc: cannot load any modules with 2.6.17-rc3
Quoted 11 lines · David S. Miller
From: Martin Habets <[email protected]>
Date: Tue, 9 May 2006 22:27:22 +0100Quoted 3 lines
Sadly, no. I can try to do some of the easier things, but fixing something like the esp driver without the esp&dma datasheets is beyond me I'm afraid :).
http://en.wikipedia.org/wiki/NCR_53C9x
The DMA programming manual is really not that necessary to understand the chip.
Thanks! I'm studying that now and will continue pokin around in there.
Quoted 7 lines
Quoted 5 lines
Yes, these actually fail to load. Maybe it's a memory corruption in
module.c
somehow: if I make too many debugging changes inapply_relocate_add()the problem disappears.
I'm trying different things now to make it show me the failing section and symbol when it fails. I'll post again once I have more details.Are you using Debian's gcc-4.1 compiler to build kernels?
I found it. A stupid mistake by me set things off all wrong :(. The original error
Unknown relocation: 17
actually means 0x17, which is R_SPARC_UA32. Sure enough the objdump output showed that all along, and module.c has no support for it. Since this is related binutils, I'm on version 2.16.1 of that. Got the issue with gcc-3.3.5 and gcc-3.4.4.
The patch below add support for this type, considering that the documentation has:
"Resembles R_SPARC_32, except that it refers to an unaligned word. The word to be relocated must be treated as four separate bytes with arbitrary alignment, not as a word aligned according to the architecture requirements."
It also has a debugging change of mine, not sure if that is suitable for the mainstream kernel. If not I can supply a patch without that part.
Thanks again for all the help!
Signature · 36 lines
Martin Signed-off-by: Martin Habets <[email protected]> --- 2.6.17-rc3/arch/sparc/kernel/module.c.orig 2006-05-11 17:21:02.000000000 +0100 +++ 2.6.17-rc3/arch/sparc/kernel/module.c 2006-05-11 18:30:09.000000000 +0100 @@ -100,6 +100,7 @@ for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { Elf32_Addr v; + u8 *uv; /* This is where to make the change */ location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr @@ -140,10 +141,19 @@ ((v >> 10) & 0x3fffff); break; + case R_SPARC_UA32: /* Like R_SPARC_32 but unaligned */ + uv = (u8 *) v; + location[0] = uv[0]; + location[1] = uv[1]; + location[2] = uv[2]; + location[3] = uv[3]; + break; + default: - printk(KERN_ERR "module %s: Unknown relocation: %x", + printk(KERN_ERR "module %s: Unknown relocation: %x relsec=%d i=%d\n", me->name, - (int) (ELF32_R_TYPE(rel[i].r_info))); + (int) (ELF32_R_TYPE(rel[i].r_info)), + relsec, i); return -ENOEXEC; }; }
David S. Miller
maintainerFrom: Martin Habets <[email protected]>
Date: Thu, 11 May 2006 19:07:32 +0100
Review
Quoted 8 lines
(quoted diff) +8
-0+ case R_SPARC_UA32: /* Like R_SPARC_32 but unaligned */ + uv = (u8 *) v; + location[0] = uv[0]; + location[1] = uv[1]; + location[2] = uv[2]; + location[3] = uv[3]; + break; +
This is not correct.
The relocation puts "value v" at "location" not "data at address v" at "location", the latter of which is what your patch is trying to do.
Simply adding "case R_SPARC_UA32:" right under "case R_SPARC_32:" would work just fine since the R_SPARC_32 code already handles arbitrary alignment of "location" which is the crucial difference between R_SPARC_32 and R_SPARC_UA32.
I still wonder where you're getting that relocation from. It must be emitted by some dwarf2 frame unwind stuff. It's a shame that such bloat is aparently being emitted into objects by default.
Can you send me a sample object that has such a relocation again? I don't want to add support for this relocation if it really is not needed. I'm hoping we can add a compiler option that will make this cruft not get output by the compiler since it is superfluous and of no use in the kernel build.
Thanks.
Quoted 14 lines · David S. Miller
From: Martin Habets <[email protected]>
Date: Thu, 11 May 2006 19:07:32 +0100Review
Quoted 8 lines
(quoted diff) +8
-0+ case R_SPARC_UA32: /* Like R_SPARC_32 but unaligned */ + uv = (u8 *) v; + location[0] = uv[0]; + location[1] = uv[1]; + location[2] = uv[2]; + location[3] = uv[3]; + break; +This is not correct.
Quoted 2 lines
The relocation puts "value v" at "location" not "data at address v" at "location", the latter of which is what your patch is trying to do.
Hmm, yeah. It did not feel right after a night's sleep.
Quoted 8 lines
Simply adding "case
R_SPARC_UA32:" right under "caseR_SPARC_32:" would work just fine since theR_SPARC_32code already handles arbitrary alignment of "location" which is the crucial difference betweenR_SPARC_32andR_SPARC_UA32.I still wonder where you're getting that relocation from. It must be emitted by some dwarf2 frame unwind stuff. It's a shame that such bloat is aparently being emitted into objects by default.
I've checked the .ko files, R_SPARC_UA32 is only used in the '.rela.eh_frame' section.
The build command is:
gcc -Wp,-MD,lib/.crc32.o.d -nostdinc -isystem /usr/lib/gcc-lib/sparc-linux/3.3.5/include -D__KERNEL__
-Iinclude -include include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -O2 -fomit-frame-pointer -fasynchronous-unwind-tables -m32 -pipe -mno-fpu
-fcall-used-g5 -fcall-used-g7 -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(crc32)"
-D"KBUILD_MODNAME=KBUILD_STR(crc32)" -c -o lib/crc32.o lib/crc32.c
The -fasynchronous-unwind-tables caught my eye. Leaving it out caused the '.rela.eh_frame' section not to be generated at all (module loads ok as well). I've tried -funwind-tables, but that generated the same '.rela.eh_frame' section as with -fasynchronous-unwind-tables.
Quoted 5 lines
Can you send me a sample object that has such a relocation again? I don't want to add support for this relocation if it really is not needed. I'm hoping we can add a compiler option that will make this cruft not get output by the compiler since it is superfluous and of no use in the kernel build.
I've uploaded the following to http://www.mph.eclipse.co.uk/pub/linux/
crc32.o
crc32.ko
crc32.2
these are all generated using the standard build options (without any modifications by me).
Signature · 1 line
Martin
Quoted 4 lines · Martin Habets
Quoted 3 lines
I still wonder where you're getting that relocation from. It must be emitted by some dwarf2 frame unwind stuff. It's a shame that such bloat is aparently being emitted into objects by default.
...
Quoted 2 lines
The -fasynchronous-unwind-tables caught my eye. Leaving it out caused the '.rela.eh_frame' section not to be generated at all (module loads ok as well).
The -fasynchronous-unwind-tables is turned on because I had CONFIG_UNWIND_INFO=y
set in my .config. This is in the 'kernel hacking' section, so I don't expect it to be on by default. I'm rebuilding now with that option turned off, which will take a while.
Seems to me modules should still load even if this option is on. I also expect a similar patch is needed for sparc64.
Thanks,
Martin
---
arch/sparc/kernel/module.c renamed from arch/sparc/kernel/module.c.orig +1 -0
@@ -113,6 +113,7 @@switch (ELF32_R_TYPE (rel[i].r_info)) {case R_SPARC_32 : +case R_SPARC_UA32 :/* Like R_SPARC_32 but unaligned */ location[0 ] = v >>24 ; location[1 ] = v >>16 ; location[2 ] = v >>8 ;
David S. Miller
maintainerFrom: Martin Habets <[email protected]>
Date: Fri, 12 May 2006 14:02:03 +0100
Quoted 2 lines
The -fasynchronous-unwind-tables is turned on because I had
CONFIG_UNWIND_INFO=yset in my .config.
That explains everything :-)
I'll do some test builds and add the necessary relocation support to both sparc32 and sparc64.
Thanks a lot.