PATCH: PR ld/12451: --build-id doesn't work

H.J. Lu hongjiu.lu@intel.com
Wed Dec 14 00:01:00 GMT 2011


As Jakub points out in

http://sourceware.org/bugzilla/show_bug.cgi?id=12451#c1

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.

I don't believe we always set i_shdr.contents for output binary.  Here
is the patch from Fedora binutils.  OK to install?

Thanks.

H.J.
---
2011-12-14  Nick Clifton  <nickc@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com> 

	PR ld/12451
	* elfcode.h (elf_checksum_contents): Load section contents if
	needed.

diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index b7e0226..5c06bae 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -1099,6 +1099,24 @@ elf_checksum_contents (bfd *abfd,
 
       if (i_shdr.contents)
 	(*process) (i_shdr.contents, i_shdr.sh_size, arg);
+      else
+	{
+	  asection *sec;
+
+	  sec = bfd_section_from_elf_index (abfd, count);
+	  if (sec != NULL)
+	    {
+	      if (sec->contents == NULL)
+		{
+		  /* Force rereading from file.  */
+		  sec->flags &= ~SEC_IN_MEMORY;
+		  if (! bfd_malloc_and_get_section (abfd, sec, & sec->contents))
+		    continue;
+		}
+	      if (sec->contents != NULL)
+		(*process) (sec->contents, i_shdr.sh_size, arg);
+	    }
+	}
     }
 
   return TRUE;



More information about the Binutils mailing list