From: Nick Clifton Date: Tue, 11 Nov 2003 17:50:26 +0000 (+0000) Subject: Add new feature to objcopy/strip. The -w switch allows wildcards to be used X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5fe11841a8220a0aab42940d4ec675ff5caed4d2;p=binutils-gdb.git Add new feature to objcopy/strip. The -w switch allows wildcards to be used in symbol names. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index cf6ff87cdb4..e6beaaf900d 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,21 @@ +2003-11-11 Wang Li + + * 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 * objdump.c: Revert rev 1.81 commit. diff --git a/binutils/Makefile.am b/binutils/Makefile.am index 61adfbc2995..2a07cc5d7b1 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 191d11b8446..23aa0baa28d 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 13c3335e17b..a72826ef873 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 f940d9fa04f..22b74fc4c96 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 8796dd6e020..6807aac049a 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 /* 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 Localize all symbols except \n\ -W --weaken-symbol Force symbol 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 Only copy one out of every 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= Do not copy symbol \n\ -K --keep-symbol= Only copy symbol \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;