public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Fix objcopy on prelinked MIPS binaries
@ 2007-10-25  1:07 Joseph S. Myers
  2007-10-25  7:35 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph S. Myers @ 2007-10-25  1:07 UTC (permalink / raw)
  To: binutils

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fix objcopy on prelinked MIPS binaries
  2007-10-25  1:07 Fix objcopy on prelinked MIPS binaries Joseph S. Myers
@ 2007-10-25  7:35 ` Alan Modra
  2007-10-25 13:42   ` Thiemo Seufer
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2007-10-25  7:35 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: binutils

On Wed, Oct 24, 2007 at 11:36:30PM +0000, Joseph S. Myers wrote:
> 	* elfxx-mips.c (_bfd_mips_elf_modify_segment_map): Do not add
> 	PT_NULL header when not linking.

Looks reasonable to me.  Please remove ATTRIBUTE_UNUSED when
committing.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fix objcopy on prelinked MIPS binaries
  2007-10-25  7:35 ` Alan Modra
@ 2007-10-25 13:42   ` Thiemo Seufer
  2007-10-25 14:08     ` Joseph S. Myers
  0 siblings, 1 reply; 5+ messages in thread
From: Thiemo Seufer @ 2007-10-25 13:42 UTC (permalink / raw)
  To: Joseph S. Myers, binutils

Alan Modra wrote:
> On Wed, Oct 24, 2007 at 11:36:30PM +0000, Joseph S. Myers wrote:
> > 	* elfxx-mips.c (_bfd_mips_elf_modify_segment_map): Do not add
> > 	PT_NULL header when not linking.
> 
> Looks reasonable to me.  Please remove ATTRIBUTE_UNUSED when
> committing.

I think this should go to the 2.18 branch as well, so it's included in
case there's a point release done.


Thiemo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fix objcopy on prelinked MIPS binaries
  2007-10-25 13:42   ` Thiemo Seufer
@ 2007-10-25 14:08     ` Joseph S. Myers
  2007-10-25 14:32       ` Daniel Jacobowitz
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph S. Myers @ 2007-10-25 14:08 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils

On Thu, 25 Oct 2007, Thiemo Seufer wrote:

> Alan Modra wrote:
> > On Wed, Oct 24, 2007 at 11:36:30PM +0000, Joseph S. Myers wrote:
> > > 	* elfxx-mips.c (_bfd_mips_elf_modify_segment_map): Do not add
> > > 	PT_NULL header when not linking.
> > 
> > Looks reasonable to me.  Please remove ATTRIBUTE_UNUSED when
> > committing.
> 
> I think this should go to the 2.18 branch as well, so it's included in
> case there's a point release done.

I think it would cause extra test failures there without

2007-09-24  Daniel Jacobowitz  <dan@codesourcery.com>

        * elf.c (assign_file_positions_for_load_sections): Trust
        p_align_valid.
        (copy_elf_program_header): Copy PT_NULL segments.

which isn't currently on the branch.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fix objcopy on prelinked MIPS binaries
  2007-10-25 14:08     ` Joseph S. Myers
@ 2007-10-25 14:32       ` Daniel Jacobowitz
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2007-10-25 14:32 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Thiemo Seufer, binutils

On Thu, Oct 25, 2007 at 01:42:22PM +0000, Joseph S. Myers wrote:
> I think it would cause extra test failures there without
> 
> 2007-09-24  Daniel Jacobowitz  <dan@codesourcery.com>
> 
>         * elf.c (assign_file_positions_for_load_sections): Trust
>         p_align_valid.
>         (copy_elf_program_header): Copy PT_NULL segments.
> 
> which isn't currently on the branch.

Feel free to apply that one too.  I'm not sure if there will be a new
release off the branch, but if there is, that would be reasonable to apply.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-25 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-25  1:07 Fix objcopy on prelinked MIPS binaries Joseph S. Myers
2007-10-25  7:35 ` Alan Modra
2007-10-25 13:42   ` Thiemo Seufer
2007-10-25 14:08     ` Joseph S. Myers
2007-10-25 14:32       ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).