Bug 12451 - --build-id doesn't work
Summary: --build-id doesn't work
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-01-28 13:45 UTC by Jakub Jelinek
Modified: 2014-05-28 19:46 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2011-01-28 13:45:39 UTC
Apparently ld --build-id behavior changed recently, so it no longer checksums symbol table sections.
A short testcase:
cat > A.java <<\EOF
class A
{  
  public static void main(String args[])
  {
    System.out.println("Hello World!");
  }
}
EOF
sed s/A/B/ A.java > B.java
gcj -C A.java
gcj -C B.java
gcj -shared -fpic -o libAB.so A.class B.class
gcj -o A -fmain=A ./libAB.so -Wl,--build-id
gcj -o B -fmain=B ./libAB.so -Wl,--build-id
objdump -s -j .note.gnu.build-id A B

While with older linkers (e.g. 2.20.51.0.2) the build ids were different between A and B, in CVS head as well as 2.21.51.0.5 the build ids are the same, eventhough the binaries are different (although they have exactly the same code sections, as they call different code they certainly aren't the same).
Comment 1 Jakub Jelinek 2011-01-28 14:33:48 UTC
Actually, it seems upstream binutils probably never handled it right and it seems Fedora had some local patch for it that got dropped as redundant when it actually has never been redundant.
In elf_checksum_contents it checksums contents of sections guarded with
if (i_shdr.contents)
Except, at least in my testing, i_shdr.contents is always NULL so it only checksums section headers, program headers and ELF header.
Comment 2 Andreas Schwab 2011-01-28 15:50:24 UTC
See <https://bugzilla.redhat.com/show_bug.cgi?id=472152> for the original bug report and <https://bugzilla.redhat.com/show_bug.cgi?id=501582> for a follow-up bug.
Comment 3 Nick Clifton 2011-01-31 10:29:07 UTC
Hi Jakub,

> Actually, it seems upstream binutils probably never handled it right and it
> seems Fedora had some local patch for it that got dropped as redundant when it
> actually has never been redundant.

Sorry about that - it was my fault.  I looked at the code and thought 
that the problem had been fixed by some other changes but I failed to 
make sure that this assumption was correct. :-(

Cheers
   Nick
Comment 4 Sourceware Commits 2011-12-14 11:50:18 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2011-12-14 11:50:14

Modified files:
	bfd            : ChangeLog elfcode.h compress.c 

Log message:
	PR ld/12451
	* elfcode.h (elf_checksum_contents): Read in the section's
	contents if they are not already available.
	* compress.c (bfd_get_full_section_contents): Use zmalloc to
	allocate the buffers so that excess bytes are guaranteed to be
	zero.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5542&r2=1.5543
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elfcode.h.diff?cvsroot=src&r1=1.109&r2=1.110
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/compress.c.diff?cvsroot=src&r1=1.9&r2=1.10
Comment 5 Nick Clifton 2011-12-14 11:52:04 UTC
Hi Guys,

  Sorry about dropping the ball on this one.

  I have now checked in the patch to zero the compressed sections when they are loaded and to force the loading of unloaded sections when computing checksums.  This should fix build-ids so that they are now consistent.

Cheers
  Nick
Comment 6 Alan Modra 2012-06-15 03:40:28 UTC
For anyone rummaging through bugzilla, please note the followup: http://sourceware.org/ml/binutils-cvs/2011-12/msg00074.html
Comment 7 Jackie Rosen 2014-02-16 19:42:27 UTC Comment hidden (spam)