When linking udev on mips, ld segfaults if --gc-sections is used (which is the default in the recent versions). Here is the corresponding backtrace, it seems osec->used_by_bfd equals to NULL, so the segfaults appear when dereferencing osec->used_by_bfd->this_hdr.sh_type. This happens with binutils from HEAD. (gdb) bt #0 0x00481840 in _bfd_elf_init_private_section_data (ibfd=<value optimized out>, isec=0x806d10, obfd=0x5da970, osec=0x5c4db8, link_info=0x5cb658) at elf.c:6279 #1 0x00411588 in lang_add_section (ptr=0x7fd410f8, section=0x806d10, output=0x5cc580) at ldlang.c:2360 #2 0x0042b534 in mips_add_stub_section (stub_sec_name=0x79a638 ".text.stub.1", input_section=0x778448, output_section=0x5c4db8) at eelf32btsmip.c:263 #3 0x00463a98 in mips_elf_add_la25_intro (h=<value optimized out>, data=0x7fd411e0) at elfxx-mips.c:1599 #4 mips_elf_add_la25_stub (h=<value optimized out>, data=0x7fd411e0) at elfxx-mips.c:1710 #5 mips_elf_check_symbols (h=<value optimized out>, data=0x7fd411e0) at elfxx-mips.c:1740 #6 0x0044cbf0 in bfd_hash_traverse (table=0x5dcb98, func=0x463694 <mips_elf_check_symbols>, info=0x7fd411e0) at hash.c:656 #7 0x0046a084 in _bfd_mips_elf_always_size_sections (output_bfd=0x5da970, info=0x5cb658) at elfxx-mips.c:8428 #8 0x0049718c in bfd_elf_size_dynamic_sections (output_bfd=0x5da970, soname=0x0, rpath=0x0, filter_shlib=0x0, audit=0x0, depaudit=0x0, auxiliary_filters=0x0, info=0x5cb658, sinterpptr=0x7fd41318, verdefs=0x0) at elflink.c:5598 #9 0x0042b828 in gldelf32btsmip_before_allocation () at eelf32btsmip.c:1598 #10 mips_before_allocation () at eelf32btsmip.c:299 #11 0x00416670 in lang_process () at ldlang.c:6653 #12 0x00402e34 in main (argc=21, argv=0x7fd41534) at ./ldmain.c:462 (gdb) print osec->used_by_bfd $1 = (void *) 0x0
Created attachment 5768 [details] tarball containing objects to reproduce the issue Run testcase.sh to reproduce the issue. Note that removing --gc-sections will make the link to fail, as I removed all .o that were not necessary to make the segfault happen (in order to keep the sire reasonable).
Created attachment 5773 [details] Add checks to catch garbage collected sections.
Hi Aurelien, Please could you try out the uploaded patch and let me know if it works for you. Cheers Nick
Hi Nick, Thanks a lot for the quick patch, I confirm that it fixes the issue I reported. Cheers, Aurelien
CVSROOT: /cvs/src Module name: src Changes by: nickc@sourceware.org 2011-06-09 10:36:21 Modified files: ld : ChangeLog ld/emultempl : mipself.em bfd : ChangeLog elf.c elfxx-mips.c Log message: PR ld/12845 * elf.c (_bfd_elf_init_private_section_data): Add an assertion that the output section has an allocated bfd_elf_section_data structure. * elfxx-mips.c (mips_elf_check_symbols): Do not create a stub for symbols in sections that have been removed by garbage collection. * emultempl/mipself.em (mips_add_stub_section): Do not add stubs for sections that have been removed by garbage collection. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2343&r2=1.2344 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/emultempl/mipself.em.diff?cvsroot=src&r1=1.12&r2=1.13 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5377&r2=1.5378 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf.c.diff?cvsroot=src&r1=1.538&r2=1.539 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elfxx-mips.c.diff?cvsroot=src&r1=1.285&r2=1.286
Hi Aurelien, Excellent - I have checked the patch in. Cheers Nick
Thanks!