Bug 12845 - ld segfaults when using
Summary: ld segfaults when using
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-05 21:53 UTC by Aurelien Jarno
Modified: 2011-06-09 10:54 UTC (History)
1 user (show)

See Also:
Host: mips-unknown-linux-gnu
Target: mips-unknown-linux-gnu
Build: mips-unknown-linux-gnu
Last reconfirmed:


Attachments
tarball containing objects to reproduce the issue (393.28 KB, application/octet-stream)
2011-06-05 21:57 UTC, Aurelien Jarno
Details
Add checks to catch garbage collected sections. (904 bytes, patch)
2011-06-08 16:52 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Aurelien Jarno 2011-06-05 21:53:11 UTC
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
Comment 1 Aurelien Jarno 2011-06-05 21:57:42 UTC
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).
Comment 2 Nick Clifton 2011-06-08 16:52:49 UTC
Created attachment 5773 [details]
Add checks to catch garbage collected sections.
Comment 3 Nick Clifton 2011-06-08 16:53:29 UTC
Hi Aurelien,

  Please could you try out the uploaded patch and let me know if it works for you.

Cheers
  Nick
Comment 4 Aurelien Jarno 2011-06-09 06:28:54 UTC
Hi Nick,

Thanks a lot for the quick patch, I confirm that it fixes the issue I reported.

Cheers,
Aurelien
Comment 5 Sourceware Commits 2011-06-09 10:36:25 UTC
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
Comment 6 Nick Clifton 2011-06-09 10:53:06 UTC
Hi Aurelien,

  Excellent - I have checked the patch in.

Cheers
  Nick
Comment 7 Aurelien Jarno 2011-06-09 10:54:31 UTC
Thanks!