in symbol names.
+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.
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 \
-# 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
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)
-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 \
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 \
-*- 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
[@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}]
@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.
[@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}]
@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.
#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
/* 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;
{"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}
};
{"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}
};
-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\
--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\
{
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;
}
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)
case 0:
/* We've been given a long option. */
break;
+ case 'w':
+ wildcard = TRUE;
+ break;
case 'H':
case 'h':
strip_usage (stdout, 0);
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)
preserve_dates = TRUE;
break;
+ case 'w':
+ wildcard = TRUE;
+ break;
+
case 'x':
discard_locals = LOCALS_ALL;
break;