This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix objcopy on prelinked MIPS binaries


When a MIPS binary is linked, a spare PT_NULL program header is inserted 
in case the prelinker needs to add another program header.

If the prelinker does need to add another header (so the PT_NULL is no 
longer present in the prelinked binary), and you try to objcopy or strip 
the prelinked binary, _bfd_mips_elf_modify_segment_map called from 
elf_modify_segment_map called from assign_file_positions_for_load_sections 
tries to add a new PT_NULL on finding the binary doesn't already have one.  
This messes up a series of computations of section addresses because of

  off = bed->s->sizeof_ehdr;
  off += alloc * bed->s->sizeof_phdr;

where alloc is the new increased number of program headers, and so yields 
a series of errors of the form

BFD: output-file: section .interp lma 0x10000134 overlaps previous sections

(where it's decided to add a page alignment and wants that section to go 
at 0x10010134 because of the increased number of program headers).

objcopy should copy the program as-is and not try to insert extra headers 
for future prelinking.  This patch disables the addition of this program 
header in the objcopy case.  Tested with no regressions with cross to 
mips-linux-gnu; OK to commit?

(I don't think the bug this patch fixes is readily testable in the 
binutils testsuite, given that ld won't create a binary without this spare 
header in order to test copying it.)

2007-10-24  Joseph Myers  <joseph@codesourcery.com>

	* elfxx-mips.c (_bfd_mips_elf_modify_segment_map): Do not add
	PT_NULL header when not linking.

Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.216
diff -u -r1.216 elfxx-mips.c
--- bfd/elfxx-mips.c	12 Oct 2007 15:59:19 -0000	1.216
+++ bfd/elfxx-mips.c	24 Oct 2007 22:53:46 -0000
@@ -9555,8 +9555,12 @@
      header instead, and avoid the need to move any sections.
      There is a long tradition of allocating spare dynamic tags,
      so allocating a spare program header seems like a natural
-     extension.  */
-  if (!SGI_COMPAT (abfd)
+     extension.
+
+     If INFO is NULL, we may be copying an already prelinked binary
+     with objcopy or strip, so do not add this header.  */
+  if (info != NULL
+      && !SGI_COMPAT (abfd)
       && bfd_get_section_by_name (abfd, ".dynamic"))
     {
       for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next)

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]