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]

Re: Add an --extract-symbol option to objcopy


On Thu, Mar 01, 2007 at 01:00:13PM +0000, Richard Sandiford wrote:
> This is unfortunately one of those patches that is being submitted
> upstream long after it has been used in the wild (namely for VxWorks).

Also unfortunately, it looks like this option has never worked very
well.  Against binutils built from source just after this was
committed:

$ gcc -o hello /src/tmp/hello.c
$ binutils/objcopy --extract-symbol hello hello.sym
BFD: BFD (GNU Binutils) 2.17.50.20070302 assertion fail /src/binutils-local/bfd/elf.c:5698

We now have http://sourceware.org/bugzilla/show_bug.cgi?id=6774

I've just committed a patch to cure the silly ELF headers that
"objcopy --extract-symbol" generates, but I think some further changes
are necessary.

Firstly, when used on relocatable files I reckon there isn't much
point in keeping the relocations.  Hence the copy_section change
below.  Secondly, I don't see any real purpose in keeping the ELF
program headers when "objcopy --extract-symbol" is used on
executables.  Since we've lost the section contents, the headers ought
to go too.  Fixed by not calling setup_bfd_headers.  Finally, why
should the section vma/lma be set to zero, which changes section
symbol value?

I won't commit any of this without hearing back from vxworks people
that I haven't broken anything for them.  Incidentally it is rather
odd that the --extract-symbols testcase isn't run on vxworks
targets...

binutils/
	* objcopy.c (copy_object): Don't setup_bfd_headers when extract_symbol.
	(setup_section): Don't zero vma and lma when extract_symbol.
	(copy_section): Discard relocations when extract_symbol.
	* doc/binutils.texi: Update --extract-symbol description.
ld/testsuite/
	* ld-elf/extract-symbol-1sec.d: Update.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.122
diff -u -p -r1.122 objcopy.c
--- binutils/objcopy.c	12 Jun 2008 11:57:40 -0000	1.122
+++ binutils/objcopy.c	1 Aug 2008 06:20:06 -0000
@@ -1461,7 +1461,8 @@ copy_object (bfd *ibfd, bfd *obfd)
      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 (!extract_symbol)
+    setup_bfd_headers (ibfd, obfd);
 
   if (add_sections != NULL)
     {
@@ -2298,7 +2299,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
   else
     vma += change_section_address;
 
-  if (! bfd_set_section_vma (obfd, osection, extract_symbol ? 0 : vma))
+  if (! bfd_set_section_vma (obfd, osection, vma))
     {
       err = _("failed to set vma");
       goto loser;
@@ -2317,7 +2318,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
   else
     lma += change_section_address;
 
-  osection->lma = extract_symbol ? 0 : lma;
+  osection->lma = lma;
 
   /* FIXME: This is probably not enough.  If we change the LMA we
      may have to recompute the header for the file as well.  */
@@ -2336,7 +2337,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
      bfd_get_section_by_name since some formats allow multiple
      sections with the same name.  */
   isection->output_section = osection;
-  isection->output_offset = extract_symbol ? vma : 0;
+  isection->output_offset = 0;
 
   /* Do not copy backend data if --extract-symbol is passed; anything
      that needs to look at the section contents will fail.  */
@@ -2400,6 +2401,9 @@ copy_section (bfd *ibfd, sec_ptr isectio
   if (size == 0 || osection == 0)
     return;
 
+  if (extract_symbol)
+    return;
+
   p = find_section_list (bfd_get_section_name (ibfd, isection), FALSE);
 
   /* Core files do not need to be relocated.  */
@@ -2460,9 +2464,6 @@ copy_section (bfd *ibfd, sec_ptr isectio
 	free (relpp);
     }
 
-  if (extract_symbol)
-    return;
-
   if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
       && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
     {
Index: binutils/doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.129
diff -u -p -r1.129 binutils.texi
--- binutils/doc/binutils.texi	12 Jun 2008 11:57:40 -0000	1.129
+++ binutils/doc/binutils.texi	1 Aug 2008 06:20:11 -0000
@@ -1540,7 +1540,6 @@ Keep the file's section flags and symbol
 Specifically, the option:
 
 @itemize
-@item sets the virtual and load addresses of every section to zero;
 @item removes the contents of all sections;
 @item sets the size of every section to zero; and
 @item sets the file's start address to zero.
Index: ld/testsuite/ld-elf/extract-symbol-1sec.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/extract-symbol-1sec.d,v
retrieving revision 1.2
diff -u -p -r1.2 extract-symbol-1sec.d
--- ld/testsuite/ld-elf/extract-symbol-1sec.d	7 Mar 2007 10:25:11 -0000	1.2
+++ ld/testsuite/ld-elf/extract-symbol-1sec.d	1 Aug 2008 06:20:33 -0000
@@ -7,7 +7,7 @@
 #...
 Sections:
  *Idx +Name +Size +VMA +LMA .*
- *0 +\.foo +0+ +0+ +0+ .*
+ *0 +\.foo +0+ +0+10000 +0+10000 .*
  *CONTENTS, ALLOC, LOAD, CODE
- *1 +\.bar +0+ +0+ +0+ .*
+ *1 +\.bar +0+ +0+20000 +0+20000 .*
  *ALLOC, READONLY, CODE


-- 
Alan Modra
Australia Development Lab, IBM


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