public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Problem with objcopy phdrs and patch
@ 2004-05-05 19:01 David Heine
  2004-05-05 19:06 ` David Heine
  0 siblings, 1 reply; 7+ messages in thread
From: David Heine @ 2004-05-05 19:01 UTC (permalink / raw)
  To: binutils

I've run into problems with objcopy mapping PHDRS into a segment from a 
file that did not originally map PHDRS into a segment.  This only occurs 
when removing the last section from an object file on configurations 
with small MAXPAGESIZE.

I tracked the problem down to a FIXME in elf.c:5241
         /* Only set up the segments if there are no more SEC_ALLOC
            sections.  FIXME: This won't do the right thing if objcopy is
            used to remove the last SEC_ALLOC section, since objcopy
            won't call this routine in that case.  */

The problem is that the PHDRS are not copied from the input file, and 
when they are recreated, the default algorithm that regenerates the 
segments can map the FILEHDR and PHDRS into the first segment.

I was hoping to be able to reuse the "bfd_copy_private_bfd_data" hook to 
be able to copy PHDRS.  However, the PHDRs must be set up before setting 
section content and objcopy calls "bfd_copy_private_bfd_data" late (ref 
objcopy.c:1485).
    /* Allow the BFD backend to copy any private data it understands
      from the input BFD to the output BFD.  This is done last to
      permit the routine to look at the filtered symbol table, which is
      important for the ECOFF code at least.  */

I'm proposing a new bfd interface "bfd_copy_private_header_data" that 
should be called after setting up section data for each of the sections 
that will copy over phdr data.  I'm including a proposed patch for 
binutils and bfd and a Changelog for each.

I did not see a mechanism in the binutils testsuite to cleanly call the 
gnu linker, so I'm including a manual testcase to demonstrate the 
failure.  Use an elf target with small page sizes like avr-elf.
 > cat simple.s
         .section .first_data, "a"
         .p2align 2
         .word 0x1000
         .section .second_data, "a"
         .p2align 2
         .word 0x2000
 > cat simple.t
MEMORY {  MEM : ORIGIN = 0x40000000, LENGTH = 0x5000 }
PHDRS {  P1 PT_LOAD; }
SECTIONS {
   .text : { *(.literal .text) } > MEM : P1
   .data : { *(.data) } > MEM : P1
   .bss : { *(.bss) } > MEM : P1
   .first_data : { *(.first_data) } > MEM :P1
   .second_data : { *(.second_data) } > MEM :P1
}

 > as -o simple.o simple.s
 > ld -T simple.t -o simple.exe simple.o
 > objcopy -j .first_data simple.exe simple-first.bfd
 > objdump -p simple-first.bfd | grep "LOAD off.*0x00000000"

On failure, this will generate one line indicating the first  PHDR that 
maps FILEHDR and PHDR in the first segment at a virtual address just 
before the defined MEM address. It passes if no line is generated.




binutils ChangeLog

2004-05-05  David Heine  <dlheine@tensilica.com>

     * objcopy.c (setup_bfd_headers): New function.
     (copy_object): Call setup_bfd_headers.


bfd ChangeLog

2004-05-05  David Heine  <dlheine@tensilica.com>

     * bfd.c (bfd_copy_private_header_data): Define.
     * elf-bfd.h (_bfd_elf_copy_private_header_data): Declare.
     * elf.c (_bfd_elf_copy_private_section_data): Remove code to set up
     segments by calling copy_private_bfd_data.
     (_bfd_elf_copy_private_header_data): Define.
     * elf-xxtarget.h (bfd_elfNN_bfd_copy_private_header_data): Define.
     * libbfd-in.h (_bfd_generic_bfd_copy_private_header_data): Define.
     * targets.c (BFD_JUMP_TABLE_COPY): Add
     _bfd_copy_private_header_data.
     * bfd-in2.h: Regenerate.
     * libbfd.h: Regenerate.

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

* Re: Problem with objcopy phdrs and patch
  2004-05-05 19:01 Problem with objcopy phdrs and patch David Heine
@ 2004-05-05 19:06 ` David Heine
  2004-05-13 17:50   ` Bob Wilson
  0 siblings, 1 reply; 7+ messages in thread
From: David Heine @ 2004-05-05 19:06 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 797 bytes --]

Here is the proposed patch and Changelog


binutils ChangeLog

2004-05-05  David Heine

     * objcopy.c (setup_bfd_headers): New function.
     (copy_object): Call setup_bfd_headers.


bfd ChangeLog

2004-05-05  David Heine

     * bfd.c (bfd_copy_private_header_data): Define.
     * elf-bfd.h (_bfd_elf_copy_private_header_data): Declare.
     * elf.c (_bfd_elf_copy_private_section_data): Remove code to set up
     segments by calling copy_private_bfd_data.\
     (_bfd_elf_copy_private_header_data): Define.
     * elf-xxtarget.h (bfd_elfNN_bfd_copy_private_header_data): Define.
     * libbfd-in.h (_bfd_generic_bfd_copy_private_header_data): Define.
     * targets.c (BFD_JUMP_TABLE_COPY): Add
     _bfd_copy_private_header_data.
     * bfd-in2.h: Regenerate.
     * libbfd.h: Regenerate.

[-- Attachment #2: bfd-private-headers.diff --]
[-- Type: text/plain, Size: 8152 bytes --]

Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.276
diff -u -r1.276 bfd-in2.h
--- bfd-in2.h	5 May 2004 14:33:13 -0000	1.276
+++ bfd-in2.h	5 May 2004 16:38:03 -0000
@@ -3945,6 +3945,11 @@
 
 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
 
+bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
+
+#define bfd_copy_private_header_data(ibfd, obfd) \
+     BFD_SEND (obfd, _bfd_copy_private_header_data, \
+               (ibfd, obfd))
 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
 
 #define bfd_copy_private_bfd_data(ibfd, obfd) \
@@ -4225,6 +4230,7 @@
   NAME##_bfd_merge_private_bfd_data, \
   NAME##_bfd_copy_private_section_data, \
   NAME##_bfd_copy_private_symbol_data, \
+  NAME##_bfd_copy_private_header_data, \
   NAME##_bfd_set_private_flags, \
   NAME##_bfd_print_private_bfd_data
 
@@ -4242,6 +4248,10 @@
      to another.  */
   bfd_boolean (*_bfd_copy_private_symbol_data)
     (bfd *, asymbol *, bfd *, asymbol *);
+  /* Called to copy BFD private header data from one object file
+     to another.  */
+  bfd_boolean (*_bfd_copy_private_header_data)
+    (bfd *, bfd *);
   /* Called to set private backend flags.  */
   bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
 
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.61
diff -u -r1.61 bfd.c
--- bfd.c	30 Apr 2004 14:23:39 -0000	1.61
+++ bfd.c	5 May 2004 16:38:03 -0000
@@ -982,6 +982,29 @@
 
 /*
 FUNCTION
+	bfd_copy_private_header_data
+
+SYNOPSIS
+	bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
+
+DESCRIPTION
+	Copy private BFD header information from the BFD @var{ibfd} to the
+	the BFD @var{obfd}.  This copies information that may require
+	sections to exist, but does not require symbol tables.  Return
+	<<true>> on success, <<false>> on error.
+	Possible error returns are:
+
+	o <<bfd_error_no_memory>> -
+	Not enough memory exists to create private data for @var{obfd}.
+
+.#define bfd_copy_private_header_data(ibfd, obfd) \
+.     BFD_SEND (obfd, _bfd_copy_private_header_data, \
+.		(ibfd, obfd))
+
+*/
+
+/*
+FUNCTION
 	bfd_copy_private_bfd_data
 
 SYNOPSIS
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.139
diff -u -r1.139 elf-bfd.h
--- elf-bfd.h	30 Apr 2004 14:23:39 -0000	1.139
+++ elf-bfd.h	5 May 2004 16:38:03 -0000
@@ -1376,6 +1376,8 @@
   (bfd *, asection *, void *);
 extern void _bfd_elf_link_just_syms
   (asection *, struct bfd_link_info *);
+extern bfd_boolean _bfd_elf_copy_private_header_data
+  (bfd *, bfd *);
 extern bfd_boolean _bfd_elf_copy_private_symbol_data
   (bfd *, asymbol *, bfd *, asymbol *);
 extern bfd_boolean _bfd_elf_copy_private_section_data
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.224
diff -u -r1.224 elf.c
--- elf.c	30 Apr 2004 15:04:30 -0000	1.224
+++ elf.c	5 May 2004 16:38:03 -0000
@@ -5234,24 +5234,6 @@
       || obfd->xvec->flavour != bfd_target_elf_flavour)
     return TRUE;
 
-  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
-    {
-	asection *s;
-
-	/* Only set up the segments if there are no more SEC_ALLOC
-	   sections.  FIXME: This won't do the right thing if objcopy is
-	   used to remove the last SEC_ALLOC section, since objcopy
-	   won't call this routine in that case.  */
-	for (s = isec->next; s != NULL; s = s->next)
-	  if ((s->flags & SEC_ALLOC) != 0)
-	    break;
-	if (s == NULL)
-	  {
-	    if (! copy_private_bfd_data (ibfd, obfd))
-	      return FALSE;
-	  }
-    }
-
   ihdr = &elf_section_data (isec)->this_hdr;
   ohdr = &elf_section_data (osec)->this_hdr;
 
@@ -5270,6 +5252,29 @@
   elf_group_name (osec) = elf_group_name (isec);
 
   osec->use_rela_p = isec->use_rela_p;
+
+  return TRUE;
+}
+
+/* Copy private header information.  */
+
+bfd_boolean
+_bfd_elf_copy_private_header_data (bfd *ibfd, bfd *obfd)
+{
+  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+    return TRUE;
+
+  /* Copy over private BFD data if it has not already been copied.
+     This must be done here, rather than in the copy_private_bfd_data
+     entry point, because the latter is called after the section
+     contents have been set, which means that the program headers have
+     already been worked out.  */
+  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
+    {
+      if (! copy_private_bfd_data (ibfd, obfd))
+	return FALSE;
+    }
 
   return TRUE;
 }
Index: elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.64
diff -u -r1.64 elfxx-target.h
--- elfxx-target.h	30 Apr 2004 14:23:39 -0000	1.64
+++ elfxx-target.h	5 May 2004 16:38:03 -0000
@@ -158,6 +158,10 @@
 #define bfd_elfNN_bfd_copy_private_section_data \
   _bfd_elf_copy_private_section_data
 #endif
+#ifndef bfd_elfNN_bfd_copy_private_header_data
+#define bfd_elfNN_bfd_copy_private_header_data \
+  _bfd_elf_copy_private_header_data
+#endif
 #ifndef bfd_elfNN_bfd_copy_private_bfd_data
 #define bfd_elfNN_bfd_copy_private_bfd_data \
   _bfd_elf_copy_private_bfd_data
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.33
diff -u -r1.33 libbfd-in.h
--- libbfd-in.h	30 Apr 2004 14:23:39 -0000	1.33
+++ libbfd-in.h	5 May 2004 16:38:03 -0000
@@ -212,6 +212,8 @@
   ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
 #define _bfd_generic_bfd_copy_private_symbol_data \
   ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
+#define _bfd_generic_bfd_copy_private_header_data \
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
 #define _bfd_generic_bfd_print_private_bfd_data \
   ((bfd_boolean (*) (bfd *, void *)) bfd_true)
 
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.108
diff -u -r1.108 libbfd.h
--- libbfd.h	30 Apr 2004 14:23:40 -0000	1.108
+++ libbfd.h	5 May 2004 16:38:03 -0000
@@ -217,6 +217,8 @@
   ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
 #define _bfd_generic_bfd_copy_private_symbol_data \
   ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
+#define _bfd_generic_bfd_copy_private_header_data \
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
 #define _bfd_generic_bfd_print_private_bfd_data \
   ((bfd_boolean (*) (bfd *, void *)) bfd_true)
 
@@ -696,9 +698,9 @@
 extern bfd *bfd_last_cache;
 
 #define bfd_cache_lookup(x) \
-    ((x)==bfd_last_cache? \
-      (FILE*) (bfd_last_cache->iostream): \
-       bfd_cache_lookup_worker(x))
+    ((x) == bfd_last_cache ? \
+      (FILE *) (bfd_last_cache->iostream): \
+       bfd_cache_lookup_worker (x))
 bfd_boolean bfd_cache_init (bfd *abfd);
 
 bfd_boolean bfd_cache_close (bfd *abfd);
Index: targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.108
diff -u -r1.108 targets.c
--- targets.c	30 Apr 2004 14:23:39 -0000	1.108
+++ targets.c	5 May 2004 16:38:03 -0000
@@ -265,6 +265,7 @@
 .  NAME##_bfd_merge_private_bfd_data, \
 .  NAME##_bfd_copy_private_section_data, \
 .  NAME##_bfd_copy_private_symbol_data, \
+.  NAME##_bfd_copy_private_header_data, \
 .  NAME##_bfd_set_private_flags, \
 .  NAME##_bfd_print_private_bfd_data
 .
@@ -282,6 +283,10 @@
 .     to another.  *}
 .  bfd_boolean (*_bfd_copy_private_symbol_data)
 .    (bfd *, asymbol *, bfd *, asymbol *);
+.  {* Called to copy BFD private header data from one object file
+.     to another.  *}
+.  bfd_boolean (*_bfd_copy_private_header_data)
+.    (bfd *, bfd *);
 .  {* Called to set private backend flags.  *}
 .  bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
 .

[-- Attachment #3: binutils-private-headers.diff --]
[-- Type: text/plain, Size: 1610 bytes --]

Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.67
diff -u -r1.67 objcopy.c
--- objcopy.c	27 Apr 2004 06:31:16 -0000	1.67
+++ objcopy.c	5 May 2004 16:30:09 -0000
@@ -377,6 +377,7 @@
 
 /* Forward declarations.  */
 static void setup_section (bfd *, asection *, void *);
+static void setup_bfd_headers (bfd *, bfd *);
 static void copy_section (bfd *, asection *, void *);
 static void get_sections (bfd *, asection *, void *);
 static int compare_section_lma (const void *, const void *);
@@ -1178,6 +1179,8 @@
      any output is done.  Thus, we traverse all sections multiple times.  */
   bfd_map_over_sections (ibfd, setup_section, obfd);
 
+  setup_bfd_headers (ibfd, obfd);
+
   if (add_sections != NULL)
     {
       struct section_add *padd;
@@ -1806,6 +1809,32 @@
       }
 
   return old_name;
+}
+
+/* Once each of the sections is copied, we may still need to do some
+   finalization work for private section headers.  Do that here.  */
+
+static void
+setup_bfd_headers (bfd *ibfd, bfd *obfd)
+{
+  const char *err;
+
+  /* Allow the BFD backend to copy any private data it understands
+     from the input section to the output section.  */
+  if (! bfd_copy_private_header_data (ibfd, obfd))
+    {
+      err = _("private header data");
+      goto loser;
+    }
+
+  /* All went well.  */
+  return;
+
+loser:
+  non_fatal (_("%s: error in %s: %s"),
+	     bfd_get_filename (ibfd),
+	     err, bfd_errmsg (bfd_get_error ()));
+  status = 1;
 }
 
 /* Create a section in OBFD with the same

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

* Re: Problem with objcopy phdrs and patch
  2004-05-05 19:06 ` David Heine
@ 2004-05-13 17:50   ` Bob Wilson
  2004-05-13 23:50     ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Bob Wilson @ 2004-05-13 17:50 UTC (permalink / raw)
  To: binutils

I haven't seen any response to the patch David Heine proposed to fix this 
problem, so I thought I'd follow up to make sure it wasn't overlooked.  Judging 
from the "FIXME" comment, the current code is obviously broken, and David's 
patch seems like a reasonable solution.  I'd be happy to apply the patch if 
someone will approve it.

Thanks,
Bob

David Heine wrote:
> I've run into problems with objcopy mapping PHDRS into a segment from a file that did not originally map PHDRS into a segment. This only occurs when removing the last section from an object file on configurations with small MAXPAGESIZE.
> 
> I tracked the problem down to a FIXME in elf.c:5241
>         /* Only set up the segments if there are no more SEC_ALLOC
>            sections.  FIXME: This won't do the right thing if objcopy is
>            used to remove the last SEC_ALLOC section, since objcopy
>            won't call this routine in that case.  */


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

* Re: Problem with objcopy phdrs and patch
  2004-05-13 17:50   ` Bob Wilson
@ 2004-05-13 23:50     ` Alan Modra
  2004-05-14 16:31       ` Bob Wilson
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2004-05-13 23:50 UTC (permalink / raw)
  To: Bob Wilson, David Heine; +Cc: binutils

On Thu, May 13, 2004 at 10:49:49AM -0700, Bob Wilson wrote:
> I haven't seen any response to the patch David Heine proposed to fix this 
> problem, so I thought I'd follow up to make sure it wasn't overlooked.  
> Judging from the "FIXME" comment, the current code is obviously broken, and 
> David's patch seems like a reasonable solution.  I'd be happy to apply the 
> patch if someone will approve it.

No, the patch is *not* OK.  David hasn't compiled bfd with
--enable-targets=all.  Changing struct bfd_target usually entails quite
a lot of mechanical work..  I'll approve the patch once that has been
done.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: Problem with objcopy phdrs and patch
  2004-05-13 23:50     ` Alan Modra
@ 2004-05-14 16:31       ` Bob Wilson
  2004-05-15  0:44         ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Bob Wilson @ 2004-05-14 16:31 UTC (permalink / raw)
  To: Alan Modra; +Cc: David Heine, binutils

[-- Attachment #1: Type: text/plain, Size: 1759 bytes --]


Alan Modra wrote:
> No, the patch is *not* OK.  David hasn't compiled bfd with
> --enable-targets=all.  Changing struct bfd_target usually entails quite
> a lot of mechanical work..  I'll approve the patch once that has been
> done.

Oops.  I've never made a change like this before and I'm afraid it shows.... 
Since you described the work as mechanical, I went ahead and added the missing 
pieces to David's patch.  It now builds with --enable-targets=all.  OK?

--Bob

bfd ChangeLog:

2004-05-14  David Heine  <dlheine@tensilica.com>

	* aout-target.h (MY_bfd_copy_private_header_data): Define.
	* aout-tic30.c (MY_bfd_copy_private_header_data): Define.
	* bfd.c (bfd_copy_private_header_data): Define.
	* coffcode.h (coff_bfd_copy_private_header_data): Define.
	* elf-bfd.h (_bfd_elf_copy_private_header_data): Declare.
	* elf.c (_bfd_elf_copy_private_section_data): Remove code to set up
	segments by calling copy_private_bfd_data.
	(_bfd_elf_copy_private_header_data): Define.
	* elf-xxtarget.h (bfd_elfNN_bfd_copy_private_header_data): Define.
	* libbfd-in.h (_bfd_generic_bfd_copy_private_header_data): Define.
	* libecoff.h (_bfd_ecoff_bfd_copy_private_header_data): Define.
	* mach-o.c (bfd_mach_o_bfd_copy_private_header_data): Define.
	* mmo.c (mmo_bfd_copy_private_header_data): Define.
	* ppcboot.c (ppcboot_bfd_copy_private_header_data): Define.
	* som.c (som_bfd_copy_private_header_data): Define.
	* targets.c (BFD_JUMP_TABLE_COPY): Add _bfd_copy_private_header_data.
	* vms.c (vms_bfd_copy_private_header_data): Define.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

binutils ChangeLog:

2004-05-14  David Heine  <dlheine@tensilica.com>

         * objcopy.c (setup_bfd_headers): New function.
	(copy_object): Call setup_bfd_headers.


[-- Attachment #2: bfd-cp-priv-hdr.diff --]
[-- Type: text/plain, Size: 14486 bytes --]

Index: aout-target.h
===================================================================
RCS file: /cvs/src/src/bfd/aout-target.h,v
retrieving revision 1.23
diff -u -r1.23 aout-target.h
--- aout-target.h	30 Apr 2004 14:23:39 -0000	1.23
+++ aout-target.h	14 May 2004 16:21:03 -0000
@@ -559,6 +559,10 @@
 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef MY_bfd_copy_private_header_data
+#define MY_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef MY_bfd_print_private_bfd_data
 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
 #endif
Index: aout-tic30.c
===================================================================
RCS file: /cvs/src/src/bfd/aout-tic30.c,v
retrieving revision 1.22
diff -u -r1.22 aout-tic30.c
--- aout-tic30.c	30 Apr 2004 14:23:39 -0000	1.22
+++ aout-tic30.c	14 May 2004 16:21:03 -0000
@@ -1016,6 +1016,10 @@
 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef MY_bfd_copy_private_header_data
+#define MY_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef MY_bfd_print_private_bfd_data
 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
 #endif
Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.276
diff -u -r1.276 bfd-in2.h
--- bfd-in2.h	5 May 2004 14:33:13 -0000	1.276
+++ bfd-in2.h	14 May 2004 16:21:03 -0000
@@ -3945,6 +3945,11 @@
 
 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
 
+bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
+
+#define bfd_copy_private_header_data(ibfd, obfd) \
+     BFD_SEND (obfd, _bfd_copy_private_header_data, \
+               (ibfd, obfd))
 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
 
 #define bfd_copy_private_bfd_data(ibfd, obfd) \
@@ -4225,6 +4230,7 @@
   NAME##_bfd_merge_private_bfd_data, \
   NAME##_bfd_copy_private_section_data, \
   NAME##_bfd_copy_private_symbol_data, \
+  NAME##_bfd_copy_private_header_data, \
   NAME##_bfd_set_private_flags, \
   NAME##_bfd_print_private_bfd_data
 
@@ -4242,6 +4248,10 @@
      to another.  */
   bfd_boolean (*_bfd_copy_private_symbol_data)
     (bfd *, asymbol *, bfd *, asymbol *);
+  /* Called to copy BFD private header data from one object file
+     to another.  */
+  bfd_boolean (*_bfd_copy_private_header_data)
+    (bfd *, bfd *);
   /* Called to set private backend flags.  */
   bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
 
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.61
diff -u -r1.61 bfd.c
--- bfd.c	30 Apr 2004 14:23:39 -0000	1.61
+++ bfd.c	14 May 2004 16:21:03 -0000
@@ -982,6 +982,29 @@
 
 /*
 FUNCTION
+	bfd_copy_private_header_data
+
+SYNOPSIS
+	bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
+
+DESCRIPTION
+	Copy private BFD header information from the BFD @var{ibfd} to the
+	the BFD @var{obfd}.  This copies information that may require
+	sections to exist, but does not require symbol tables.  Return
+	<<true>> on success, <<false>> on error.
+	Possible error returns are:
+
+	o <<bfd_error_no_memory>> -
+	Not enough memory exists to create private data for @var{obfd}.
+
+.#define bfd_copy_private_header_data(ibfd, obfd) \
+.     BFD_SEND (obfd, _bfd_copy_private_header_data, \
+.		(ibfd, obfd))
+
+*/
+
+/*
+FUNCTION
 	bfd_copy_private_bfd_data
 
 SYNOPSIS
Index: coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.104
diff -u -r1.104 coffcode.h
--- coffcode.h	7 May 2004 15:08:48 -0000	1.104
+++ coffcode.h	14 May 2004 16:21:03 -0000
@@ -5511,6 +5511,10 @@
 #define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef coff_bfd_copy_private_header_data
+#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef coff_bfd_copy_private_section_data
 #define coff_bfd_copy_private_section_data  _bfd_generic_bfd_copy_private_section_data
 #endif
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.140
diff -u -r1.140 elf-bfd.h
--- elf-bfd.h	11 May 2004 17:08:37 -0000	1.140
+++ elf-bfd.h	14 May 2004 16:21:03 -0000
@@ -1379,6 +1379,8 @@
   (bfd *, asection *, void *);
 extern void _bfd_elf_link_just_syms
   (asection *, struct bfd_link_info *);
+extern bfd_boolean _bfd_elf_copy_private_header_data
+  (bfd *, bfd *);
 extern bfd_boolean _bfd_elf_copy_private_symbol_data
   (bfd *, asymbol *, bfd *, asymbol *);
 extern bfd_boolean _bfd_elf_copy_private_section_data
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.225
diff -u -r1.225 elf.c
--- elf.c	11 May 2004 17:08:37 -0000	1.225
+++ elf.c	14 May 2004 16:21:04 -0000
@@ -5290,24 +5290,6 @@
       || obfd->xvec->flavour != bfd_target_elf_flavour)
     return TRUE;
 
-  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
-    {
-	asection *s;
-
-	/* Only set up the segments if there are no more SEC_ALLOC
-	   sections.  FIXME: This won't do the right thing if objcopy is
-	   used to remove the last SEC_ALLOC section, since objcopy
-	   won't call this routine in that case.  */
-	for (s = isec->next; s != NULL; s = s->next)
-	  if ((s->flags & SEC_ALLOC) != 0)
-	    break;
-	if (s == NULL)
-	  {
-	    if (! copy_private_bfd_data (ibfd, obfd))
-	      return FALSE;
-	  }
-    }
-
   ihdr = &elf_section_data (isec)->this_hdr;
   ohdr = &elf_section_data (osec)->this_hdr;
 
@@ -5326,6 +5308,29 @@
   elf_group_name (osec) = elf_group_name (isec);
 
   osec->use_rela_p = isec->use_rela_p;
+
+  return TRUE;
+}
+
+/* Copy private header information.  */
+
+bfd_boolean
+_bfd_elf_copy_private_header_data (bfd *ibfd, bfd *obfd)
+{
+  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+    return TRUE;
+
+  /* Copy over private BFD data if it has not already been copied.
+     This must be done here, rather than in the copy_private_bfd_data
+     entry point, because the latter is called after the section
+     contents have been set, which means that the program headers have
+     already been worked out.  */
+  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
+    {
+      if (! copy_private_bfd_data (ibfd, obfd))
+	return FALSE;
+    }
 
   return TRUE;
 }
Index: elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.64
diff -u -r1.64 elfxx-target.h
--- elfxx-target.h	30 Apr 2004 14:23:39 -0000	1.64
+++ elfxx-target.h	14 May 2004 16:21:04 -0000
@@ -158,6 +158,10 @@
 #define bfd_elfNN_bfd_copy_private_section_data \
   _bfd_elf_copy_private_section_data
 #endif
+#ifndef bfd_elfNN_bfd_copy_private_header_data
+#define bfd_elfNN_bfd_copy_private_header_data \
+  _bfd_elf_copy_private_header_data
+#endif
 #ifndef bfd_elfNN_bfd_copy_private_bfd_data
 #define bfd_elfNN_bfd_copy_private_bfd_data \
   _bfd_elf_copy_private_bfd_data
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.33
diff -u -r1.33 libbfd-in.h
--- libbfd-in.h	30 Apr 2004 14:23:39 -0000	1.33
+++ libbfd-in.h	14 May 2004 16:21:04 -0000
@@ -212,6 +212,8 @@
   ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
 #define _bfd_generic_bfd_copy_private_symbol_data \
   ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
+#define _bfd_generic_bfd_copy_private_header_data \
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
 #define _bfd_generic_bfd_print_private_bfd_data \
   ((bfd_boolean (*) (bfd *, void *)) bfd_true)
 
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.108
diff -u -r1.108 libbfd.h
--- libbfd.h	30 Apr 2004 14:23:40 -0000	1.108
+++ libbfd.h	14 May 2004 16:21:04 -0000
@@ -217,6 +217,8 @@
   ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
 #define _bfd_generic_bfd_copy_private_symbol_data \
   ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
+#define _bfd_generic_bfd_copy_private_header_data \
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
 #define _bfd_generic_bfd_print_private_bfd_data \
   ((bfd_boolean (*) (bfd *, void *)) bfd_true)
 
@@ -696,9 +698,9 @@
 extern bfd *bfd_last_cache;
 
 #define bfd_cache_lookup(x) \
-    ((x)==bfd_last_cache? \
-      (FILE*) (bfd_last_cache->iostream): \
-       bfd_cache_lookup_worker(x))
+    ((x) == bfd_last_cache ? \
+      (FILE *) (bfd_last_cache->iostream): \
+       bfd_cache_lookup_worker (x))
 bfd_boolean bfd_cache_init (bfd *abfd);
 
 bfd_boolean bfd_cache_close (bfd *abfd);
Index: libecoff.h
===================================================================
RCS file: /cvs/src/src/bfd/libecoff.h,v
retrieving revision 1.15
diff -u -r1.15 libecoff.h
--- libecoff.h	24 Apr 2004 06:12:24 -0000	1.15
+++ libecoff.h	14 May 2004 16:21:04 -0000
@@ -1,5 +1,5 @@
 /* BFD ECOFF object file private structure.
-   Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003
+   Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
@@ -248,6 +248,9 @@
 
 #define _bfd_ecoff_bfd_copy_private_symbol_data \
   _bfd_generic_bfd_copy_private_symbol_data
+
+#define _bfd_ecoff_bfd_copy_private_header_data \
+  _bfd_generic_bfd_copy_private_header_data
 
 #define _bfd_ecoff_bfd_print_private_bfd_data \
   _bfd_generic_bfd_print_private_bfd_data
Index: mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.8
diff -u -r1.8 mach-o.c
--- mach-o.c	30 Apr 2004 14:23:39 -0000	1.8
+++ mach-o.c	14 May 2004 16:21:04 -0000
@@ -70,6 +70,7 @@
 #define bfd_mach_o_bfd_merge_sections bfd_generic_merge_sections
 #define bfd_mach_o_bfd_is_group_section bfd_generic_is_group_section
 #define bfd_mach_o_bfd_discard_group bfd_generic_discard_group
+#define bfd_mach_o_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
 
 static bfd_boolean bfd_mach_o_bfd_copy_private_symbol_data
   PARAMS ((bfd *, asymbol *, bfd *, asymbol *));
Index: mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.17
diff -u -r1.17 mmo.c
--- mmo.c	30 Apr 2004 14:23:39 -0000	1.17
+++ mmo.c	14 May 2004 16:21:04 -0000
@@ -3306,6 +3306,7 @@
 #define mmo_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
 #define mmo_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
 #define mmo_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
+#define mmo_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
 #define mmo_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
 #define mmo_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
 
Index: ppcboot.c
===================================================================
RCS file: /cvs/src/src/bfd/ppcboot.c,v
retrieving revision 1.17
diff -u -r1.17 ppcboot.c
--- ppcboot.c	30 Apr 2004 14:23:40 -0000	1.17
+++ ppcboot.c	14 May 2004 16:21:04 -0000
@@ -484,6 +484,7 @@
 #define ppcboot_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
 #define ppcboot_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
 #define ppcboot_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
+#define ppcboot_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
 #define ppcboot_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
 #define ppcboot_bfd_print_private_bfd_dat ppcboot_bfd_print_private_bfd_data
 
Index: som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.41
diff -u -r1.41 som.c
--- som.c	2 May 2004 06:21:08 -0000	1.41
+++ som.c	14 May 2004 16:21:05 -0000
@@ -192,6 +192,8 @@
   PARAMS ((bfd *, asection *, bfd *, asection *));
 static bfd_boolean som_bfd_copy_private_bfd_data
   PARAMS ((bfd *, bfd *));
+#define som_bfd_copy_private_header_data \
+  _bfd_generic_bfd_copy_private_header_data
 #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
 #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
 static bfd_boolean som_bfd_is_local_label_name
Index: targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.109
diff -u -r1.109 targets.c
--- targets.c	6 May 2004 02:46:29 -0000	1.109
+++ targets.c	14 May 2004 16:21:05 -0000
@@ -265,6 +265,7 @@
 .  NAME##_bfd_merge_private_bfd_data, \
 .  NAME##_bfd_copy_private_section_data, \
 .  NAME##_bfd_copy_private_symbol_data, \
+.  NAME##_bfd_copy_private_header_data, \
 .  NAME##_bfd_set_private_flags, \
 .  NAME##_bfd_print_private_bfd_data
 .
@@ -282,6 +283,10 @@
 .     to another.  *}
 .  bfd_boolean (*_bfd_copy_private_symbol_data)
 .    (bfd *, asymbol *, bfd *, asymbol *);
+.  {* Called to copy BFD private header data from one object file
+.     to another.  *}
+.  bfd_boolean (*_bfd_copy_private_header_data)
+.    (bfd *, bfd *);
 .  {* Called to set private backend flags.  *}
 .  bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
 .
Index: vms.c
===================================================================
RCS file: /cvs/src/src/bfd/vms.c,v
retrieving revision 1.28
diff -u -r1.28 vms.c
--- vms.c	30 Apr 2004 14:23:40 -0000	1.28
+++ vms.c	14 May 2004 16:21:05 -0000
@@ -168,6 +168,8 @@
 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
 #define vms_bfd_is_group_section bfd_generic_is_group_section
 #define vms_bfd_discard_group bfd_generic_discard_group
+#define vms_bfd_copy_private_header_data \
+  _bfd_generic_bfd_copy_private_header_data
 \f
 /*===========================================================================*/
 

[-- Attachment #3: binutils-cp-priv-hdr.diff --]
[-- Type: text/plain, Size: 1611 bytes --]

Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.67
diff -u -r1.67 objcopy.c
--- objcopy.c	27 Apr 2004 06:31:16 -0000	1.67
+++ objcopy.c	14 May 2004 16:21:16 -0000
@@ -377,6 +377,7 @@
 
 /* Forward declarations.  */
 static void setup_section (bfd *, asection *, void *);
+static void setup_bfd_headers (bfd *, bfd *);
 static void copy_section (bfd *, asection *, void *);
 static void get_sections (bfd *, asection *, void *);
 static int compare_section_lma (const void *, const void *);
@@ -1178,6 +1179,8 @@
      any output is done.  Thus, we traverse all sections multiple times.  */
   bfd_map_over_sections (ibfd, setup_section, obfd);
 
+  setup_bfd_headers (ibfd, obfd);
+
   if (add_sections != NULL)
     {
       struct section_add *padd;
@@ -1806,6 +1809,32 @@
       }
 
   return old_name;
+}
+
+/* Once each of the sections is copied, we may still need to do some
+   finalization work for private section headers.  Do that here.  */
+
+static void
+setup_bfd_headers (bfd *ibfd, bfd *obfd)
+{
+  const char *err;
+
+  /* Allow the BFD backend to copy any private data it understands
+     from the input section to the output section.  */
+  if (! bfd_copy_private_header_data (ibfd, obfd))
+    {
+      err = _("private header data");
+      goto loser;
+    }
+
+  /* All went well.  */
+  return;
+
+loser:
+  non_fatal (_("%s: error in %s: %s"),
+	     bfd_get_filename (ibfd),
+	     err, bfd_errmsg (bfd_get_error ()));
+  status = 1;
 }
 
 /* Create a section in OBFD with the same

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

* Re: Problem with objcopy phdrs and patch
  2004-05-14 16:31       ` Bob Wilson
@ 2004-05-15  0:44         ` Alan Modra
  2004-05-17 16:44           ` Bob Wilson
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2004-05-15  0:44 UTC (permalink / raw)
  To: Bob Wilson; +Cc: David Heine, binutils

On Fri, May 14, 2004 at 09:31:48AM -0700, Bob Wilson wrote:
> Oops.  I've never made a change like this before and I'm afraid it 
> shows.... Since you described the work as mechanical, I went ahead and 
> added the missing pieces to David's patch.  It now builds with 
> --enable-targets=all.  OK?

Hmm, I should have mentioned that you need --enable-64-bit-bfd also if
your host and target are both 32 bit; The list of files changed looked
suspiciously small.  I see you caught som.c, which I missed in my last
change in this area.  Good!  :)  However, there's no mention of
coff-rs6000.c and coff64-rs6000.c in the patch.  I think you'll need a
change there too.

Otherwise OK.  Further mechanical change to rs6000 files pre-approved,
plus any other missing changes if --enable-64-bit-bfd shows some are
needed.  Thanks!

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: Problem with objcopy phdrs and patch
  2004-05-15  0:44         ` Alan Modra
@ 2004-05-17 16:44           ` Bob Wilson
  0 siblings, 0 replies; 7+ messages in thread
From: Bob Wilson @ 2004-05-17 16:44 UTC (permalink / raw)
  To: Alan Modra; +Cc: David Heine, binutils

[-- Attachment #1: Type: text/plain, Size: 2376 bytes --]

Alan Modra wrote:
> Hmm, I should have mentioned that you need --enable-64-bit-bfd also if
> your host and target are both 32 bit; The list of files changed looked
> suspiciously small.  I see you caught som.c, which I missed in my last
> change in this area.  Good!  :)  However, there's no mention of
> coff-rs6000.c and coff64-rs6000.c in the patch.  I think you'll need a
> change there too.
> 
> Otherwise OK.  Further mechanical change to rs6000 files pre-approved,
> plus any other missing changes if --enable-64-bit-bfd shows some are
> needed.  Thanks!

You were right about the coff*-rs6000 files.  I fixed them and there were no 
other problems exposed by the --enable-64-bit-bfd build.  Here are the revised 
patches that I've committed.

--Bob

bfd ChangeLog:

2004-05-17  David Heine  <dlheine@tensilica.com>

         * aout-target.h (MY_bfd_copy_private_header_data): Define.
         * aout-tic30.c (MY_bfd_copy_private_header_data): Define.
         * bfd.c (bfd_copy_private_header_data): Define.
         * coff-rs6000.c (rs6000coff_vec, pmac_xcoff_vec): Add entries for new
         interface.
         * coff64-rs6000.c (rs6000coff64_vec, aix5coff64_vec): Likewise.
         * coffcode.h (coff_bfd_copy_private_header_data): Define.
         * elf-bfd.h (_bfd_elf_copy_private_header_data): Declare.
         * elf.c (_bfd_elf_copy_private_section_data): Remove code to set up
         segments by calling copy_private_bfd_data.
         (_bfd_elf_copy_private_header_data): Define.
         * elfxx-target.h (bfd_elfNN_bfd_copy_private_header_data): Define.
         * libbfd-in.h (_bfd_generic_bfd_copy_private_header_data): Define.
         * libecoff.h (_bfd_ecoff_bfd_copy_private_header_data): Define.
         * mach-o.c (bfd_mach_o_bfd_copy_private_header_data): Define.
         * mmo.c (mmo_bfd_copy_private_header_data): Define.
         * ppcboot.c (ppcboot_bfd_copy_private_header_data): Define.
         * som.c (som_bfd_copy_private_header_data): Define.
         * targets.c (BFD_JUMP_TABLE_COPY): Add _bfd_copy_private_header_data.
         * vms.c (vms_bfd_copy_private_header_data): Define.
         * bfd-in2.h: Regenerate.
         * libbfd.h: Regenerate.

binutils ChangeLog:

2004-05-17  David Heine  <dlheine@tensilica.com>

         * objcopy.c (setup_bfd_headers): New function.
         (copy_object): Call setup_bfd_headers.


[-- Attachment #2: bfd-cp-priv-hdr.diff --]
[-- Type: text/plain, Size: 16559 bytes --]

Index: aout-target.h
===================================================================
RCS file: /cvs/src/src/bfd/aout-target.h,v
retrieving revision 1.23
diff -u -r1.23 aout-target.h
--- aout-target.h	30 Apr 2004 14:23:39 -0000	1.23
+++ aout-target.h	17 May 2004 16:18:25 -0000
@@ -559,6 +559,10 @@
 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef MY_bfd_copy_private_header_data
+#define MY_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef MY_bfd_print_private_bfd_data
 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
 #endif
Index: aout-tic30.c
===================================================================
RCS file: /cvs/src/src/bfd/aout-tic30.c,v
retrieving revision 1.22
diff -u -r1.22 aout-tic30.c
--- aout-tic30.c	30 Apr 2004 14:23:39 -0000	1.22
+++ aout-tic30.c	17 May 2004 16:18:26 -0000
@@ -1016,6 +1016,10 @@
 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef MY_bfd_copy_private_header_data
+#define MY_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef MY_bfd_print_private_bfd_data
 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
 #endif
Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.276
diff -u -r1.276 bfd-in2.h
--- bfd-in2.h	5 May 2004 14:33:13 -0000	1.276
+++ bfd-in2.h	17 May 2004 16:18:26 -0000
@@ -3945,6 +3945,11 @@
 
 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
 
+bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
+
+#define bfd_copy_private_header_data(ibfd, obfd) \
+     BFD_SEND (obfd, _bfd_copy_private_header_data, \
+               (ibfd, obfd))
 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
 
 #define bfd_copy_private_bfd_data(ibfd, obfd) \
@@ -4225,6 +4230,7 @@
   NAME##_bfd_merge_private_bfd_data, \
   NAME##_bfd_copy_private_section_data, \
   NAME##_bfd_copy_private_symbol_data, \
+  NAME##_bfd_copy_private_header_data, \
   NAME##_bfd_set_private_flags, \
   NAME##_bfd_print_private_bfd_data
 
@@ -4242,6 +4248,10 @@
      to another.  */
   bfd_boolean (*_bfd_copy_private_symbol_data)
     (bfd *, asymbol *, bfd *, asymbol *);
+  /* Called to copy BFD private header data from one object file
+     to another.  */
+  bfd_boolean (*_bfd_copy_private_header_data)
+    (bfd *, bfd *);
   /* Called to set private backend flags.  */
   bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
 
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.61
diff -u -r1.61 bfd.c
--- bfd.c	30 Apr 2004 14:23:39 -0000	1.61
+++ bfd.c	17 May 2004 16:18:26 -0000
@@ -982,6 +982,29 @@
 
 /*
 FUNCTION
+	bfd_copy_private_header_data
+
+SYNOPSIS
+	bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
+
+DESCRIPTION
+	Copy private BFD header information from the BFD @var{ibfd} to the
+	the BFD @var{obfd}.  This copies information that may require
+	sections to exist, but does not require symbol tables.  Return
+	<<true>> on success, <<false>> on error.
+	Possible error returns are:
+
+	o <<bfd_error_no_memory>> -
+	Not enough memory exists to create private data for @var{obfd}.
+
+.#define bfd_copy_private_header_data(ibfd, obfd) \
+.     BFD_SEND (obfd, _bfd_copy_private_header_data, \
+.		(ibfd, obfd))
+
+*/
+
+/*
+FUNCTION
 	bfd_copy_private_bfd_data
 
 SYNOPSIS
Index: coff-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-rs6000.c,v
retrieving revision 1.59
diff -u -r1.59 coff-rs6000.c
--- coff-rs6000.c	30 Apr 2004 14:23:39 -0000	1.59
+++ coff-rs6000.c	17 May 2004 16:18:26 -0000
@@ -4142,6 +4142,7 @@
     ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
+    ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
     ((bfd_boolean (*) (bfd *, void * )) bfd_true),
 
@@ -4386,6 +4387,7 @@
     ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
+    ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
     ((bfd_boolean (*) (bfd *, void * )) bfd_true),
 
Index: coff64-rs6000.c
===================================================================
RCS file: /cvs/src/src/bfd/coff64-rs6000.c,v
retrieving revision 1.50
diff -u -r1.50 coff64-rs6000.c
--- coff64-rs6000.c	30 Apr 2004 14:23:39 -0000	1.50
+++ coff64-rs6000.c	17 May 2004 16:18:26 -0000
@@ -2683,6 +2683,7 @@
     ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
+    ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
     ((bfd_boolean (*) (bfd *, void * )) bfd_true),
 
@@ -2928,6 +2929,7 @@
     ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
     ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
+    ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
     ((bfd_boolean (*) (bfd *, void * )) bfd_true),
 
Index: coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.104
diff -u -r1.104 coffcode.h
--- coffcode.h	7 May 2004 15:08:48 -0000	1.104
+++ coffcode.h	17 May 2004 16:18:27 -0000
@@ -5511,6 +5511,10 @@
 #define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
 #endif
 
+#ifndef coff_bfd_copy_private_header_data
+#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
+#endif
+
 #ifndef coff_bfd_copy_private_section_data
 #define coff_bfd_copy_private_section_data  _bfd_generic_bfd_copy_private_section_data
 #endif
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.140
diff -u -r1.140 elf-bfd.h
--- elf-bfd.h	11 May 2004 17:08:37 -0000	1.140
+++ elf-bfd.h	17 May 2004 16:18:27 -0000
@@ -1379,6 +1379,8 @@
   (bfd *, asection *, void *);
 extern void _bfd_elf_link_just_syms
   (asection *, struct bfd_link_info *);
+extern bfd_boolean _bfd_elf_copy_private_header_data
+  (bfd *, bfd *);
 extern bfd_boolean _bfd_elf_copy_private_symbol_data
   (bfd *, asymbol *, bfd *, asymbol *);
 extern bfd_boolean _bfd_elf_copy_private_section_data
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.225
diff -u -r1.225 elf.c
--- elf.c	11 May 2004 17:08:37 -0000	1.225
+++ elf.c	17 May 2004 16:18:28 -0000
@@ -5290,24 +5290,6 @@
       || obfd->xvec->flavour != bfd_target_elf_flavour)
     return TRUE;
 
-  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
-    {
-	asection *s;
-
-	/* Only set up the segments if there are no more SEC_ALLOC
-	   sections.  FIXME: This won't do the right thing if objcopy is
-	   used to remove the last SEC_ALLOC section, since objcopy
-	   won't call this routine in that case.  */
-	for (s = isec->next; s != NULL; s = s->next)
-	  if ((s->flags & SEC_ALLOC) != 0)
-	    break;
-	if (s == NULL)
-	  {
-	    if (! copy_private_bfd_data (ibfd, obfd))
-	      return FALSE;
-	  }
-    }
-
   ihdr = &elf_section_data (isec)->this_hdr;
   ohdr = &elf_section_data (osec)->this_hdr;
 
@@ -5326,6 +5308,29 @@
   elf_group_name (osec) = elf_group_name (isec);
 
   osec->use_rela_p = isec->use_rela_p;
+
+  return TRUE;
+}
+
+/* Copy private header information.  */
+
+bfd_boolean
+_bfd_elf_copy_private_header_data (bfd *ibfd, bfd *obfd)
+{
+  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+    return TRUE;
+
+  /* Copy over private BFD data if it has not already been copied.
+     This must be done here, rather than in the copy_private_bfd_data
+     entry point, because the latter is called after the section
+     contents have been set, which means that the program headers have
+     already been worked out.  */
+  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
+    {
+      if (! copy_private_bfd_data (ibfd, obfd))
+	return FALSE;
+    }
 
   return TRUE;
 }
Index: elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.64
diff -u -r1.64 elfxx-target.h
--- elfxx-target.h	30 Apr 2004 14:23:39 -0000	1.64
+++ elfxx-target.h	17 May 2004 16:18:28 -0000
@@ -158,6 +158,10 @@
 #define bfd_elfNN_bfd_copy_private_section_data \
   _bfd_elf_copy_private_section_data
 #endif
+#ifndef bfd_elfNN_bfd_copy_private_header_data
+#define bfd_elfNN_bfd_copy_private_header_data \
+  _bfd_elf_copy_private_header_data
+#endif
 #ifndef bfd_elfNN_bfd_copy_private_bfd_data
 #define bfd_elfNN_bfd_copy_private_bfd_data \
   _bfd_elf_copy_private_bfd_data
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.33
diff -u -r1.33 libbfd-in.h
--- libbfd-in.h	30 Apr 2004 14:23:39 -0000	1.33
+++ libbfd-in.h	17 May 2004 16:18:28 -0000
@@ -212,6 +212,8 @@
   ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
 #define _bfd_generic_bfd_copy_private_symbol_data \
   ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
+#define _bfd_generic_bfd_copy_private_header_data \
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
 #define _bfd_generic_bfd_print_private_bfd_data \
   ((bfd_boolean (*) (bfd *, void *)) bfd_true)
 
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.108
diff -u -r1.108 libbfd.h
--- libbfd.h	30 Apr 2004 14:23:40 -0000	1.108
+++ libbfd.h	17 May 2004 16:18:28 -0000
@@ -217,6 +217,8 @@
   ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true)
 #define _bfd_generic_bfd_copy_private_symbol_data \
   ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true)
+#define _bfd_generic_bfd_copy_private_header_data \
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
 #define _bfd_generic_bfd_print_private_bfd_data \
   ((bfd_boolean (*) (bfd *, void *)) bfd_true)
 
@@ -696,9 +698,9 @@
 extern bfd *bfd_last_cache;
 
 #define bfd_cache_lookup(x) \
-    ((x)==bfd_last_cache? \
-      (FILE*) (bfd_last_cache->iostream): \
-       bfd_cache_lookup_worker(x))
+    ((x) == bfd_last_cache ? \
+      (FILE *) (bfd_last_cache->iostream): \
+       bfd_cache_lookup_worker (x))
 bfd_boolean bfd_cache_init (bfd *abfd);
 
 bfd_boolean bfd_cache_close (bfd *abfd);
Index: libecoff.h
===================================================================
RCS file: /cvs/src/src/bfd/libecoff.h,v
retrieving revision 1.15
diff -u -r1.15 libecoff.h
--- libecoff.h	24 Apr 2004 06:12:24 -0000	1.15
+++ libecoff.h	17 May 2004 16:18:28 -0000
@@ -1,5 +1,5 @@
 /* BFD ECOFF object file private structure.
-   Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003
+   Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
@@ -248,6 +248,9 @@
 
 #define _bfd_ecoff_bfd_copy_private_symbol_data \
   _bfd_generic_bfd_copy_private_symbol_data
+
+#define _bfd_ecoff_bfd_copy_private_header_data \
+  _bfd_generic_bfd_copy_private_header_data
 
 #define _bfd_ecoff_bfd_print_private_bfd_data \
   _bfd_generic_bfd_print_private_bfd_data
Index: mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.8
diff -u -r1.8 mach-o.c
--- mach-o.c	30 Apr 2004 14:23:39 -0000	1.8
+++ mach-o.c	17 May 2004 16:18:28 -0000
@@ -70,6 +70,7 @@
 #define bfd_mach_o_bfd_merge_sections bfd_generic_merge_sections
 #define bfd_mach_o_bfd_is_group_section bfd_generic_is_group_section
 #define bfd_mach_o_bfd_discard_group bfd_generic_discard_group
+#define bfd_mach_o_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
 
 static bfd_boolean bfd_mach_o_bfd_copy_private_symbol_data
   PARAMS ((bfd *, asymbol *, bfd *, asymbol *));
Index: mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.17
diff -u -r1.17 mmo.c
--- mmo.c	30 Apr 2004 14:23:39 -0000	1.17
+++ mmo.c	17 May 2004 16:18:28 -0000
@@ -3306,6 +3306,7 @@
 #define mmo_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
 #define mmo_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
 #define mmo_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
+#define mmo_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
 #define mmo_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
 #define mmo_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
 
Index: ppcboot.c
===================================================================
RCS file: /cvs/src/src/bfd/ppcboot.c,v
retrieving revision 1.17
diff -u -r1.17 ppcboot.c
--- ppcboot.c	30 Apr 2004 14:23:40 -0000	1.17
+++ ppcboot.c	17 May 2004 16:18:28 -0000
@@ -484,6 +484,7 @@
 #define ppcboot_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
 #define ppcboot_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
 #define ppcboot_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
+#define ppcboot_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
 #define ppcboot_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
 #define ppcboot_bfd_print_private_bfd_dat ppcboot_bfd_print_private_bfd_data
 
Index: som.c
===================================================================
RCS file: /cvs/src/src/bfd/som.c,v
retrieving revision 1.42
diff -u -r1.42 som.c
--- som.c	14 May 2004 17:42:47 -0000	1.42
+++ som.c	17 May 2004 16:18:29 -0000
@@ -192,6 +192,8 @@
   PARAMS ((bfd *, asection *, bfd *, asection *));
 static bfd_boolean som_bfd_copy_private_bfd_data
   PARAMS ((bfd *, bfd *));
+#define som_bfd_copy_private_header_data \
+  _bfd_generic_bfd_copy_private_header_data
 #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
 #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
 static bfd_boolean som_bfd_is_local_label_name
Index: targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.109
diff -u -r1.109 targets.c
--- targets.c	6 May 2004 02:46:29 -0000	1.109
+++ targets.c	17 May 2004 16:18:29 -0000
@@ -265,6 +265,7 @@
 .  NAME##_bfd_merge_private_bfd_data, \
 .  NAME##_bfd_copy_private_section_data, \
 .  NAME##_bfd_copy_private_symbol_data, \
+.  NAME##_bfd_copy_private_header_data, \
 .  NAME##_bfd_set_private_flags, \
 .  NAME##_bfd_print_private_bfd_data
 .
@@ -282,6 +283,10 @@
 .     to another.  *}
 .  bfd_boolean (*_bfd_copy_private_symbol_data)
 .    (bfd *, asymbol *, bfd *, asymbol *);
+.  {* Called to copy BFD private header data from one object file
+.     to another.  *}
+.  bfd_boolean (*_bfd_copy_private_header_data)
+.    (bfd *, bfd *);
 .  {* Called to set private backend flags.  *}
 .  bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
 .
Index: vms.c
===================================================================
RCS file: /cvs/src/src/bfd/vms.c,v
retrieving revision 1.28
diff -u -r1.28 vms.c
--- vms.c	30 Apr 2004 14:23:40 -0000	1.28
+++ vms.c	17 May 2004 16:18:29 -0000
@@ -168,6 +168,8 @@
 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
 #define vms_bfd_is_group_section bfd_generic_is_group_section
 #define vms_bfd_discard_group bfd_generic_discard_group
+#define vms_bfd_copy_private_header_data \
+  _bfd_generic_bfd_copy_private_header_data
 \f
 /*===========================================================================*/
 

[-- Attachment #3: binutils-cp-priv-hdr.diff --]
[-- Type: text/plain, Size: 1611 bytes --]

Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.67
diff -u -r1.67 objcopy.c
--- objcopy.c	27 Apr 2004 06:31:16 -0000	1.67
+++ objcopy.c	17 May 2004 16:24:38 -0000
@@ -377,6 +377,7 @@
 
 /* Forward declarations.  */
 static void setup_section (bfd *, asection *, void *);
+static void setup_bfd_headers (bfd *, bfd *);
 static void copy_section (bfd *, asection *, void *);
 static void get_sections (bfd *, asection *, void *);
 static int compare_section_lma (const void *, const void *);
@@ -1178,6 +1179,8 @@
      any output is done.  Thus, we traverse all sections multiple times.  */
   bfd_map_over_sections (ibfd, setup_section, obfd);
 
+  setup_bfd_headers (ibfd, obfd);
+
   if (add_sections != NULL)
     {
       struct section_add *padd;
@@ -1806,6 +1809,32 @@
       }
 
   return old_name;
+}
+
+/* Once each of the sections is copied, we may still need to do some
+   finalization work for private section headers.  Do that here.  */
+
+static void
+setup_bfd_headers (bfd *ibfd, bfd *obfd)
+{
+  const char *err;
+
+  /* Allow the BFD backend to copy any private data it understands
+     from the input section to the output section.  */
+  if (! bfd_copy_private_header_data (ibfd, obfd))
+    {
+      err = _("private header data");
+      goto loser;
+    }
+
+  /* All went well.  */
+  return;
+
+loser:
+  non_fatal (_("%s: error in %s: %s"),
+	     bfd_get_filename (ibfd),
+	     err, bfd_errmsg (bfd_get_error ()));
+  status = 1;
 }
 
 /* Create a section in OBFD with the same

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

end of thread, other threads:[~2004-05-17 16:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-05 19:01 Problem with objcopy phdrs and patch David Heine
2004-05-05 19:06 ` David Heine
2004-05-13 17:50   ` Bob Wilson
2004-05-13 23:50     ` Alan Modra
2004-05-14 16:31       ` Bob Wilson
2004-05-15  0:44         ` Alan Modra
2004-05-17 16:44           ` Bob Wilson

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).