diff options
author | Nick Clifton <nickc@redhat.com> | 2003-11-11 17:50:26 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2003-11-11 17:50:26 +0000 |
commit | 5fe11841a8220a0aab42940d4ec675ff5caed4d2 (patch) | |
tree | 52aaca849a3f4fef88a2d25ebf2df0613af4bd4a | |
parent | 68e39e739b62c65d09250e1098fa03621c2ea360 (diff) | |
download | gdb-5fe11841a8220a0aab42940d4ec675ff5caed4d2.zip gdb-5fe11841a8220a0aab42940d4ec675ff5caed4d2.tar.gz gdb-5fe11841a8220a0aab42940d4ec675ff5caed4d2.tar.bz2 |
Add new feature to objcopy/strip. The -w switch allows wildcards to be used
in symbol names.
-rw-r--r-- | binutils/ChangeLog | 18 | ||||
-rw-r--r-- | binutils/Makefile.am | 2 | ||||
-rw-r--r-- | binutils/Makefile.in | 8 | ||||
-rw-r--r-- | binutils/NEWS | 3 | ||||
-rw-r--r-- | binutils/doc/binutils.texi | 34 | ||||
-rw-r--r-- | binutils/objcopy.c | 42 |
6 files changed, 97 insertions, 10 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index cf6ff87..e6beaaf 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,21 @@ +2003-11-11 Wang Li <charles@linux.net.cn> + + * objcopy.c (wildcard): New variable. True if wildcard pattern + matching is allowed in symbol names. + (strip_options): Add -w option to enable wildcard pattern + matching. + (copy_options): Likewise. + (copy_usage): Mention new switch. + (strip_usage): Likewise. + (is_specified_symbol): If performing wildcard matches use fnmatch + to compare symbol names with entries on the symbol list. + (strip_main): Accept -w switch. + (copy_main): Likewise. + * Makefile.am: Add dependency on fnmatch.h for objcopy.c + * Makefile.in: Regenerate. + * doc/binutils.texi: Document new switch. + * NEWS: Mention new switch. + 2003-11-11 Alan Modra <amodra@bigpond.net.au> * objdump.c: Revert rev 1.81 commit. diff --git a/binutils/Makefile.am b/binutils/Makefile.am index 61adfbc..2a07cc5 100644 --- a/binutils/Makefile.am +++ b/binutils/Makefile.am @@ -440,7 +440,7 @@ not-strip.o: not-strip.c objcopy.o: objcopy.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \ $(INCDIR)/symcat.h $(INCDIR)/progress.h bucomm.h config.h \ $(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h \ - budbg.h $(INCDIR)/filenames.h + budbg.h $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h objdump.o: objdump.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \ $(INCDIR)/symcat.h ../bfd/bfdver.h $(INCDIR)/progress.h \ bucomm.h config.h $(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h \ diff --git a/binutils/Makefile.in b/binutils/Makefile.in index 191d11b..23aa0ba 100644 --- a/binutils/Makefile.in +++ b/binutils/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation @@ -442,7 +442,7 @@ configure.in deflex.c defparse.c nlmheader.c rclex.c rcparse.c DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = tar +TAR = gtar GZIP_ENV = --best SOURCES = $(nlmconv_SOURCES) $(srconv_SOURCES) $(sysdump_SOURCES) $(coffdump_SOURCES) $(dlltool_SOURCES) $(windres_SOURCES) $(dllwrap_SOURCES) $(size_SOURCES) $(objdump_SOURCES) $(ar_SOURCES) $(strings_SOURCES) $(ranlib_SOURCES) $(objcopy_SOURCES) $(addr2line_SOURCES) $(readelf_SOURCES) $(nm_new_SOURCES) $(strip_new_SOURCES) $(cxxfilt_SOURCES) OBJECTS = $(nlmconv_OBJECTS) $(srconv_OBJECTS) $(sysdump_OBJECTS) $(coffdump_OBJECTS) $(dlltool_OBJECTS) $(windres_OBJECTS) $(dllwrap_OBJECTS) $(size_OBJECTS) $(objdump_OBJECTS) $(ar_OBJECTS) $(strings_OBJECTS) $(ranlib_OBJECTS) $(objcopy_OBJECTS) $(addr2line_OBJECTS) $(readelf_OBJECTS) $(nm_new_OBJECTS) $(strip_new_OBJECTS) $(cxxfilt_OBJECTS) @@ -870,7 +870,7 @@ distclean-generic: -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: - -test -z "arlex.cdeflex.crclex.carparse.harparse.cdefparse.hdefparse.cnlmheader.hnlmheader.crcparse.hrcparse.c" || rm -f arlex.c deflex.c rclex.c arparse.h arparse.c defparse.h defparse.c nlmheader.h nlmheader.c rcparse.h rcparse.c + -test -z "arlexldeflexlrclexlarparseharparsecdefparsehdefparsecnlmheaderhnlmheadercrcparsehrcparsec" || rm -f arlexl deflexl rclexl arparseh arparsec defparseh defparsec nlmheaderh nlmheaderc rcparseh rcparsec mostlyclean-am: mostlyclean-hdr mostlyclean-binPROGRAMS \ mostlyclean-noinstPROGRAMS mostlyclean-compile \ mostlyclean-libtool mostlyclean-tags \ @@ -1168,7 +1168,7 @@ not-strip.o: not-strip.c objcopy.o: objcopy.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \ $(INCDIR)/symcat.h $(INCDIR)/progress.h bucomm.h config.h \ $(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h $(INCDIR)/libiberty.h \ - budbg.h $(INCDIR)/filenames.h + budbg.h $(INCDIR)/filenames.h $(INCDIR)/fnmatch.h objdump.o: objdump.c ../bfd/bfd.h $(INCDIR)/ansidecl.h \ $(INCDIR)/symcat.h ../bfd/bfdver.h $(INCDIR)/progress.h \ bucomm.h config.h $(INCDIR)/bin-bugs.h $(INCDIR)/fopen-same.h \ diff --git a/binutils/NEWS b/binutils/NEWS index 13c3335..a72826ef 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* objcopy and strip can now take wildcard patterns in symbol names specified on + the command line provided that the --wildcard switch is used to enable them. + * readelf can now parse archives. * objdump now accepts --debugging-tags to print the debug information in a diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index f940d9f..22b74fc 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -939,6 +939,7 @@ objcopy [@option{-F} @var{bfdname}|@option{--target=}@var{bfdname}] [@option{-G} @var{symbolname}|@option{--keep-global-symbol=}@var{symbolname}] [@option{-L} @var{symbolname}|@option{--localize-symbol=}@var{symbolname}] [@option{-W} @var{symbolname}|@option{--weaken-symbol=}@var{symbolname}] + [@option{-w}|@option{--wildcard}] [@option{-x}|@option{--discard-all}] [@option{-X}|@option{--discard-locals}] [@option{-b} @var{byte}|@option{--byte=}@var{byte}] @@ -1105,6 +1106,22 @@ visible externally. This option may be given more than once. @itemx --weaken-symbol=@var{symbolname} Make symbol @var{symbolname} weak. This option may be given more than once. +@item -w +@itemx --wildcard +Permit regular expressions in @var{symbolname}s used in other command +line options. The question mark (?), asterisk (*), backslash (\) and +square brackets ([]) operators can be used anywhere in the symbol +name. If the first character of the symbol name is the exclamation +point (!) then the sense of the switch is reversed for that symbol. +For example: + +@smallexample + -w -W !foo -W fo* +@end smallexample + +would cause objcopy to weaken all symbols that start with ``fo'' +except for the symbol ``foo''. + @item -x @itemx --discard-all Do not copy non-global symbols from the source file. @@ -2117,6 +2134,7 @@ strip [@option{-F} @var{bfdname} |@option{--target=}@var{bfdname}] [@option{-S}|@option{-g}|@option{-d}|@option{--strip-debug}] [@option{-K} @var{symbolname} |@option{--keep-symbol=}@var{symbolname}] [@option{-N} @var{symbolname} |@option{--strip-symbol=}@var{symbolname}] + [@option{-w}|@option{--wildcard}] [@option{-x}|@option{--discard-all}] [@option{-X} |@option{--discard-locals}] [@option{-R} @var{sectionname} |@option{--remove-section=}@var{sectionname}] [@option{-o} @var{file}] [@option{-p}|@option{--preserve-dates}] @@ -2203,6 +2221,22 @@ argument may be specified. @itemx --preserve-dates Preserve the access and modification dates of the file. +@item -w +@itemx --wildcard +Permit regular expressions in @var{symbolname}s used in other command +line options. The question mark (?), asterisk (*), backslash (\) and +square brackets ([]) operators can be used anywhere in the symbol +name. If the first character of the symbol name is the exclamation +point (!) then the sense of the switch is reversed for that symbol. +For example: + +@smallexample + -w -K !foo -K fo* +@end smallexample + +would cause strip to only keep symbols that start with the letters +``fo'', but to discard the symbol ``foo''. + @item -x @itemx --discard-all Remove non-global symbols. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 8796dd6..6807aac 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -27,6 +27,7 @@ #include "libiberty.h" #include "budbg.h" #include "filenames.h" +#include "fnmatch.h" #include <sys/stat.h> /* A list of symbols to explicitly strip out, or to keep. A linked @@ -180,6 +181,9 @@ static bfd_boolean change_leading_char = FALSE; /* Whether to remove the leading character from global symbol names. */ static bfd_boolean remove_leading_char = FALSE; +/* Whether to permit wildcard in symbol comparasion. */ +static bfd_boolean wildcard = FALSE; + /* List of symbols to strip, keep, localize, keep-global, weaken, or redefine. */ static struct symlist *strip_specific_list = NULL; @@ -261,6 +265,7 @@ static struct option strip_options[] = {"target", required_argument, 0, 'F'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, + {"wildcard", no_argument, 0, 'w'}, {0, no_argument, 0, 0} }; @@ -331,6 +336,7 @@ static struct option copy_options[] = {"weaken", no_argument, 0, OPTION_WEAKEN}, {"weaken-symbol", required_argument, 0, 'W'}, {"weaken-symbols", required_argument, 0, OPTION_WEAKEN_SYMBOLS}, + {"wildcard", no_argument, 0, 'w'}, {0, no_argument, 0, 0} }; @@ -390,6 +396,7 @@ copy_usage (FILE *stream, int exit_status) -G --keep-global-symbol <name> Localize all symbols except <name>\n\ -W --weaken-symbol <name> Force symbol <name> to be marked as a weak\n\ --weaken Force all global symbols to be marked as weak\n\ + -w --wildcard Permit wildcard in symbol comparasion\n\ -x --discard-all Remove all non-global symbols\n\ -X --discard-locals Remove any compiler-generated symbols\n\ -i --interleave <number> Only copy one out of every <number> bytes\n\ @@ -459,6 +466,7 @@ strip_usage (FILE *stream, int exit_status) --strip-unneeded Remove all symbols not needed by relocations\n\ -N --strip-symbol=<name> Do not copy symbol <name>\n\ -K --keep-symbol=<name> Only copy symbol <name>\n\ + -w --wildcard Permit wildcard in symbol comparasion\n\ -x --discard-all Remove all non-global symbols\n\ -X --discard-locals Remove any compiler-generated symbols\n\ -v --verbose List all object files modified\n\ @@ -696,9 +704,26 @@ is_specified_symbol (const char *name, struct symlist *list) { struct symlist *tmp_list; - for (tmp_list = list; tmp_list; tmp_list = tmp_list->next) - if (strcmp (name, tmp_list->name) == 0) - return TRUE; + if (wildcard) + { + for (tmp_list = list; tmp_list; tmp_list = tmp_list->next) + if (*(tmp_list->name) != '!') + { + if (!fnmatch (tmp_list->name, name, 0)) + return TRUE; + } + else + { + if (fnmatch (tmp_list->name + 1, name, 0)) + return TRUE; + } + } + else + { + for (tmp_list = list; tmp_list; tmp_list = tmp_list->next) + if (strcmp (name, tmp_list->name) == 0) + return TRUE; + } return FALSE; } @@ -2151,7 +2176,7 @@ strip_main (int argc, char *argv[]) struct section_list *p; char *output_file = NULL; - while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVv", + while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVvw", strip_options, (int *) 0)) != EOF) { switch (c) @@ -2214,6 +2239,9 @@ strip_main (int argc, char *argv[]) case 0: /* We've been given a long option. */ break; + case 'w': + wildcard = TRUE; + break; case 'H': case 'h': strip_usage (stdout, 0); @@ -2298,7 +2326,7 @@ copy_main (int argc, char *argv[]) struct section_list *p; struct stat statbuf; - while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:", + while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:w", copy_options, (int *) 0)) != EOF) { switch (c) @@ -2393,6 +2421,10 @@ copy_main (int argc, char *argv[]) preserve_dates = TRUE; break; + case 'w': + wildcard = TRUE; + break; + case 'x': discard_locals = LOCALS_ALL; break; |