aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binutils/ChangeLog18
-rw-r--r--binutils/NEWS5
-rw-r--r--binutils/doc/binutils.texi16
-rw-r--r--binutils/objcopy.c46
-rw-r--r--ld/testsuite/ChangeLog6
-rw-r--r--ld/testsuite/ld-elf/binutils.exp3
-rw-r--r--ld/testsuite/ld-elf/extract-symbol-1.ld18
-rw-r--r--ld/testsuite/ld-elf/extract-symbol-1.s15
-rw-r--r--ld/testsuite/ld-elf/extract-symbol-1sec.d12
-rw-r--r--ld/testsuite/ld-elf/extract-symbol-1sym.d10
10 files changed, 141 insertions, 8 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 7bbeaf7..61c07e5 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,21 @@
+2007-03-01 Phil Edwards <phil@codesourcery.com>
+ Richard Sandiford <richard@codesourcery.com>
+
+ * NEWS: Mention addition of --extract-symbol.
+ * doc/binutils.texi: Document it.
+ * objcopy.c (extract_symbol): New variable.
+ (OPTION_EXTRACT_SYMBOLS): New command_line_switch.
+ (copy_options): Add an entry for --extract-symbol.
+ (copy_usage): Mention --extract-symbol.
+ (copy_object): Set the start address to zero for --extract-symbol.
+ Do not copy private BFD data in that case.
+ (setup_section): Set the size, LMA and VMA to zero for
+ --extract-symbol. Do not copy private BFD data in that case.
+ (copy_section): Do not copy section contents if --extract-symbol
+ is passed.
+ (copy_main): Set extract_symbol to TRUE if --extract-symbol
+ is passed.
+
2007-03-01 Paul Brook <paul@codesourcery.com>
* MAINTAINERS: Update my entry.
diff --git a/binutils/NEWS b/binutils/NEWS
index d12450e..f63a736 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,10 @@
-*- text -*-
+* Add --extract-symbol command line option to objcopy, which will
+ strip everything out of an ordinary object file or executable except
+ for its symbol table. Files containing just symbols can be useful
+ to some OSes.
+
* Add "-x NAME" to readelf in addition to "-x NUMBER".
* Add -i and -t switches to cxxfilt. -i disables the display of implementation
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 3751d04..1eb854e 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -996,6 +996,7 @@ objcopy [@option{-F} @var{bfdname}|@option{--target=}@var{bfdname}]
[@option{--add-gnu-debuglink=}@var{path-to-file}]
[@option{--keep-file-symbols}]
[@option{--only-keep-debug}]
+ [@option{--extract-symbol}]
[@option{--writable-text}]
[@option{--readonly-text}]
[@option{--pure}]
@@ -1489,6 +1490,21 @@ currently only supports the presence of one filename containing
debugging information, not multiple filenames on a one-per-object-file
basis.
+@item --extract-symbol
+Keep the file's section flags and symbols but remove all section data.
+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.
+@end itemize
+
+This option is used to build a @file{.sym} file for a VxWorks kernel.
+It can also be a useful way of reducing the size of a @option{--just-symbols}
+linker input file.
+
@item -V
@itemx --version
Show the version number of @command{objcopy}.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 06dbb5d..c955e37 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -215,6 +215,9 @@ static char *prefix_symbols_string = 0;
static char *prefix_sections_string = 0;
static char *prefix_alloc_sections_string = 0;
+/* True if --extract-symbol was passed on the command line. */
+static bfd_boolean extract_symbol = FALSE;
+
/* 150 isn't special; it's just an arbitrary non-ASCII char value. */
enum command_line_switch
{
@@ -261,7 +264,8 @@ enum command_line_switch
OPTION_READONLY_TEXT,
OPTION_WRITABLE_TEXT,
OPTION_PURE,
- OPTION_IMPURE
+ OPTION_IMPURE,
+ OPTION_EXTRACT_SYMBOL
};
/* Options to handle if running as "strip". */
@@ -317,6 +321,7 @@ static struct option copy_options[] =
{"debugging", no_argument, 0, OPTION_DEBUGGING},
{"discard-all", no_argument, 0, 'x'},
{"discard-locals", no_argument, 0, 'X'},
+ {"extract-symbol", no_argument, 0, OPTION_EXTRACT_SYMBOL},
{"format", required_argument, 0, 'F'}, /* Obsolete */
{"gap-fill", required_argument, 0, OPTION_GAP_FILL},
{"globalize-symbol", required_argument, 0, OPTION_GLOBALIZE_SYMBOL},
@@ -431,6 +436,7 @@ copy_usage (FILE *stream, int exit_status)
Do not copy symbol <name> unless needed by\n\
relocations\n\
--only-keep-debug Strip everything but the debug information\n\
+ --extract-symbol Remove section contents but keep symbols\n\
-K --keep-symbol <name> Do not strip symbol <name>\n\
--keep-file-symbols Do not strip file symbol(s)\n\
--localize-hidden Turn all ELF hidden symbols into locals\n\
@@ -1310,11 +1316,16 @@ copy_object (bfd *ibfd, bfd *obfd)
bfd_get_archive_filename (ibfd), bfd_get_target (ibfd),
bfd_get_filename (obfd), bfd_get_target (obfd));
- if (set_start_set)
- start = set_start;
+ if (extract_symbol)
+ start = 0;
else
- start = bfd_get_start_address (ibfd);
- start += change_start;
+ {
+ if (set_start_set)
+ start = set_start;
+ else
+ start = bfd_get_start_address (ibfd);
+ start += change_start;
+ }
/* Neither the start address nor the flags
need to be set for a core file. */
@@ -1725,6 +1736,11 @@ copy_object (bfd *ibfd, bfd *obfd)
}
}
+ /* Do not copy backend data if --extract-symbol is passed; anything
+ that needs to look at the section contents will fail. */
+ if (extract_symbol)
+ return TRUE;
+
/* 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
@@ -2184,6 +2200,8 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
size = bfd_section_size (ibfd, isection);
if (copy_byte >= 0)
size = (size + interleave - 1) / interleave;
+ else if (extract_symbol)
+ size = 0;
if (! bfd_set_section_size (obfd, osection, size))
{
err = _("size");
@@ -2198,7 +2216,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
else
vma += change_section_address;
- if (! bfd_set_section_vma (obfd, osection, vma))
+ if (! bfd_set_section_vma (obfd, osection, extract_symbol ? 0 : vma))
{
err = _("vma");
goto loser;
@@ -2217,7 +2235,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
else
lma += change_section_address;
- osection->lma = lma;
+ osection->lma = extract_symbol ? 0 : lma;
/* FIXME: This is probably not enough. If we change the LMA we
may have to recompute the header for the file as well. */
@@ -2236,7 +2254,12 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
bfd_get_section_by_name since some formats allow multiple
sections with the same name. */
isection->output_section = osection;
- isection->output_offset = 0;
+ isection->output_offset = extract_symbol ? vma : 0;
+
+ /* Do not copy backend data if --extract-symbol is passed; anything
+ that needs to look at the section contents will fail. */
+ if (extract_symbol)
+ return;
/* Allow the BFD backend to copy any private data it understands
from the input section to the output section. */
@@ -2354,6 +2377,9 @@ copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
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)
{
@@ -3231,6 +3257,10 @@ copy_main (int argc, char *argv[])
bfd_flags_to_set &= ~D_PAGED;
break;
+ case OPTION_EXTRACT_SYMBOL:
+ extract_symbol = TRUE;
+ break;
+
case 0:
/* We've been given a long option. */
break;
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 72cffce..704fa91 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2007-03-01 Richard Sandiford <richard@codesourcery.com>
+
+ * ld-elf/extract-symbol-1sym.d, ld-elf/extract-symbol-1sec.d,
+ * ld-elf/extract-symbol-1.s, ld-elf/extract-symbol-1.ld: New tests.
+ * ld-elf/binutils.exp: Run them.
+
2007-02-28 Nick Clifton <nickc@redhat.com>
PR ld/3796
diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp
index 7ced42c..6e5caba 100644
--- a/ld/testsuite/ld-elf/binutils.exp
+++ b/ld/testsuite/ld-elf/binutils.exp
@@ -122,3 +122,6 @@ binutils_test objcopy "-z max-page-size=0x100000" tdata2
binutils_test objcopy "" tdata2
binutils_test objcopy "-shared" tdata2
binutils_test objcopy "-z max-page-size=0x100000 -z common-page-size=0x1000" tdata2
+
+run_dump_test extract-symbol-1sec
+run_dump_test extract-symbol-1sym
diff --git a/ld/testsuite/ld-elf/extract-symbol-1.ld b/ld/testsuite/ld-elf/extract-symbol-1.ld
new file mode 100644
index 0000000..a989b26
--- /dev/null
+++ b/ld/testsuite/ld-elf/extract-symbol-1.ld
@@ -0,0 +1,18 @@
+ENTRY(_entry)
+PHDRS
+{
+ data PT_LOAD;
+}
+SECTIONS
+{
+ . = 0x10000;
+ .foo : { *(.foo) } :data
+
+ . = 0x20000;
+ .bar : { *(.bar) } :data
+
+ /DISCARD/ : { *(*) }
+
+ _entry = 0x30000;
+ linker_symbol = 0x40000;
+}
diff --git a/ld/testsuite/ld-elf/extract-symbol-1.s b/ld/testsuite/ld-elf/extract-symbol-1.s
new file mode 100644
index 0000000..0971500
--- /dev/null
+++ b/ld/testsuite/ld-elf/extract-symbol-1.s
@@ -0,0 +1,15 @@
+ .globl B
+ .globl C
+
+ .section .foo,"awx",%progbits
+ .4byte 1,2,3,4
+B:
+ .4byte 5,6,7
+
+ .section .bar,"ax",%nobits
+ .space 0x123
+C:
+ .space 0x302
+
+ .globl D
+ .equ D,0x12345678
diff --git a/ld/testsuite/ld-elf/extract-symbol-1sec.d b/ld/testsuite/ld-elf/extract-symbol-1sec.d
new file mode 100644
index 0000000..d6425c6
--- /dev/null
+++ b/ld/testsuite/ld-elf/extract-symbol-1sec.d
@@ -0,0 +1,12 @@
+#name: --extract-symbol test 1 (sections)
+#source: extract-symbol-1.s
+#ld: -Textract-symbol-1.ld
+#objcopy_linked_file: --extract-symbol
+#objdump: --headers
+#...
+Sections:
+ *Idx +Name +Size +VMA +LMA .*
+ *0 +\.foo +0+ +0+ +0+ .*
+ *CONTENTS, ALLOC, LOAD, CODE
+ *1 +\.bar +0+ +0+ +0+ .*
+ *ALLOC, READONLY, CODE
diff --git a/ld/testsuite/ld-elf/extract-symbol-1sym.d b/ld/testsuite/ld-elf/extract-symbol-1sym.d
new file mode 100644
index 0000000..bf48e5c
--- /dev/null
+++ b/ld/testsuite/ld-elf/extract-symbol-1sym.d
@@ -0,0 +1,10 @@
+#name: --extract-symbol test 1 (symbols)
+#source: extract-symbol-1.s
+#ld: -Textract-symbol-1.ld
+#objcopy_linked_file: --extract-symbol
+#nm: -n
+0*00010010 T B
+0*00020123 T C
+0*00030000 A _entry
+0*00040000 A linker_symbol
+0*12345678 A D