forked from Imagelibrary/binutils-gdb
binutils/
200x-xx-xx 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. ld/testsuite/ * 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.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user