Bug 10555 - SEGV with "ld --build-id /usr/lib/libc.a"
Summary: SEGV with "ld --build-id /usr/lib/libc.a"
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-24 15:57 UTC by Mark Seaborn
Modified: 2009-08-26 13:08 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build:
Last reconfirmed:


Attachments
Do not seg-fault creating a build-id section when there are no input files. (876 bytes, patch)
2009-08-25 09:20 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Seaborn 2009-08-24 15:57:57 UTC
I have been using a command similar to the following to print ld's default
linker script.  When using binutils 2.19.51.20090805 in the current version of
Ubuntu karmic, the linker script gets truncated and gcc prints a warning about a
segmentation fault (which does not cause gcc to return a non-zero exit code).

$ gcc -static -nostartfiles -nostdlib /usr/lib/libc.a -Wl,-z,noexecstack
-Wl,--verbose
collect2: ld terminated with signal 11 [Segmentation fault]
GNU ld (GNU Binutils for Ubuntu) 2.19.51.20090805
  Supported emulations:
   elf_x86_64
   elf_i386
   i386linux
   elf_l1om
using internal linker script:
==================================================
...

Note that this has to be run in a writable current working directory to
reproduce the problem, because it tries to write an "a.out" file.

The segfault can be reproduced with this more minimal invocation of ld:

$ ld --build-id /usr/lib/libc.a
Segmentation fault

$ dpkg -s binutils | grep Version
Version: 2.19.51.20090805-1ubuntu1
Comment 1 Nick Clifton 2009-08-25 09:20:47 UTC
Created attachment 4148 [details]
Do not seg-fault creating a build-id section when there are no input files.
Comment 2 Nick Clifton 2009-08-25 09:21:23 UTC
Hi Mark,

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

Cheers
  Nick
Comment 3 Mark Seaborn 2009-08-26 11:51:18 UTC
Yes, that patch works for me.  Thanks.
Comment 4 Sourceware Commits 2009-08-26 13:08:19 UTC
Subject: Bug 10555

CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2009-08-26 13:08:07

Modified files:
	ld             : ChangeLog 
	ld/emultempl   : elf32.em 

Log message:
	PR ld/10555
	* emultempl/elf32.em (_after_open): Do not create a
	.note.gnu-build-id section if there are no input files.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2029&r2=1.2030
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/emultempl/elf32.em.diff?cvsroot=src&r1=1.198&r2=1.199

Comment 5 Nick Clifton 2009-08-26 13:08:42 UTC
Hi Mark,

  Great - I have checked the patch in.

Cheers
  Nick

ld/ChangeLog
	PR ld/10555
	* emultempl/elf32.em (_after_open): Do not create a
	.note.gnu-build-id section if there are no input files.