This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[committed patch] --build-id fix for merged output section
- From: Roland McGrath <roland at redhat dot com>
- To: binutils at sources dot redhat dot com
- Cc: Alexandre Oliva <aoliva at redhat dot com>
- Date: Wed, 18 Jul 2007 02:51:32 -0700 (PDT)
- Subject: [committed patch] --build-id fix for merged output section
The last version hit an ASSERT when dealing with the synthesized
.note.gnu.build-id section being combined with other input sections into a
single output sections. I committed this on my own authority under the
"obvious fix" rule, since it's obviously better than the previously
approved code I wrote.
Alex sent me a nearly identical fix, but I made it still use
i_shdr->contents if it's set. I can't tell if there is really a case where
it will be set, or if it matters.
Thanks,
Roland
2007-07-18 Roland McGrath <roland@redhat.com>
* emultempl/elf32.em (gld${EMULATION_NAME}_write_build_id_section):
Use ASEC->contents for CONTENTS when missing, and allocate
ASEC->size if needed.
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.181
diff -B -p -u -r1.181 elf32.em
--- ld/emultempl/elf32.em 13 Jul 2007 10:44:26 -0000 1.181
+++ ld/emultempl/elf32.em 18 Jul 2007 09:42:52 -0000
@@ -945,12 +945,12 @@ gld${EMULATION_NAME}_write_build_id_sect
if (i_shdr->contents == NULL)
{
- ASSERT (asec->output_offset == 0);
- i_shdr->contents = xcalloc (i_shdr->sh_size, 1);
- if (i_shdr->contents == NULL)
- return FALSE;
+ if (asec->contents == NULL)
+ asec->contents = xmalloc (asec->size);
+ contents = asec->contents;
}
- contents = i_shdr->contents + asec->output_offset;
+ else
+ contents = i_shdr->contents + asec->output_offset;
e_note = (void *) contents;
size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
@@ -1019,9 +1019,10 @@ gld${EMULATION_NAME}_write_build_id_sect
else
abort (); /* Should have been validated earlier. */
- size = i_shdr->sh_size;
- return (bfd_seek (abfd, i_shdr->sh_offset, SEEK_SET) == 0
- && bfd_bwrite (i_shdr->contents, size, abfd) == size);
+ size = asec->size;
+ return (bfd_seek (abfd,
+ i_shdr->sh_offset + asec->output_offset, SEEK_SET) == 0
+ && bfd_bwrite (contents, size, abfd) == size);
}