+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.
[@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}]
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}.
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
{
OPTION_READONLY_TEXT,
OPTION_WRITABLE_TEXT,
OPTION_PURE,
- OPTION_IMPURE
+ OPTION_IMPURE,
+ OPTION_EXTRACT_SYMBOL
};
/* Options to handle if running as "strip". */
{"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},
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\
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. */
}
}
+ /* 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
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");
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;
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. */
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. */
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)
{
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;