aboutsummaryrefslogtreecommitdiff
path: root/binutils/nm.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2022-05-18 13:15:22 +0100
committerNick Clifton <nickc@redhat.com>2022-05-18 13:15:22 +0100
commit2c3cc81e068464b5a3d5bf19a9cf3cf3dd6b7b55 (patch)
tree5d5ae06c550788f2885c324e074395f6f10a971e /binutils/nm.c
parentc76d61da4a65eaadca861bf6c77d579a5cc3f422 (diff)
downloadbinutils-2c3cc81e068464b5a3d5bf19a9cf3cf3dd6b7b55.zip
binutils-2c3cc81e068464b5a3d5bf19a9cf3cf3dd6b7b55.tar.gz
binutils-2c3cc81e068464b5a3d5bf19a9cf3cf3dd6b7b55.tar.bz2
Add a --no-weak option to nm.
PR 29135 * nm.c (non_weak): New variable. (filter_symbols): When non-weak is true, ignore weak symbols. (long_options): Add --no-weak. (usage): Mention --no-weak. (main): Handle -W/--no-weak. * doc/binutils.texi: Document new feature. * NEWS: Mention the new feature. * testsuite/binutils-all/nm.exp: Add test of new feature. * testsuite/binutils-all/no-weak.s: New test source file.
Diffstat (limited to 'binutils/nm.c')
-rw-r--r--binutils/nm.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/binutils/nm.c b/binutils/nm.c
index 9edaa8d..60e4d85 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -176,6 +176,7 @@ static const char *print_format_string = NULL;
static int do_demangle = 0; /* Pretty print C++ symbol names. */
static int external_only = 0; /* Print external symbols only. */
static int defined_only = 0; /* Print defined symbols only. */
+static int non_weak = 0; /* Ignore weak symbols. */
static int no_sort = 0; /* Don't sort; print syms in order found. */
static int print_debug_syms = 0;/* Print debugger-only symbols too. */
static int print_armap = 0; /* Describe __.SYMDEF data in archive files. */
@@ -281,6 +282,7 @@ static struct option long_options[] =
{"undefined-only", no_argument, 0, 'u'},
{"unicode", required_argument, NULL, OPTION_UNICODE},
{"version", no_argument, &show_version, 1},
+ {"no-weak", no_argument, 0, 'W'},
{"with-symbol-versions", no_argument, &with_symbol_versions, 1},
{"without-symbol-versions", no_argument, &with_symbol_versions, 0},
{0, no_argument, 0, 0}
@@ -365,6 +367,8 @@ usage (FILE *stream, int status)
--unicode={default|show|invalid|hex|escape|highlight}\n\
Specify how to treat UTF-8 encoded unicode characters\n"));
fprintf (stream, _("\
+ -W, --no-weak Ignore weak symbols\n"));
+ fprintf (stream, _("\
--with-symbol-versions Display version strings after symbol names\n"));
fprintf (stream, _("\
-X 32_64 (ignored)\n"));
@@ -808,6 +812,8 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
| BSF_GNU_UNIQUE)) != 0
|| bfd_is_und_section (sym->section)
|| bfd_is_com_section (sym->section));
+ else if (non_weak)
+ keep = ((sym->flags & BSF_WEAK) == 0);
else
keep = 1;
@@ -2052,7 +2058,7 @@ main (int argc, char **argv)
fatal (_("fatal error: libbfd ABI mismatch"));
set_default_bfd_target ();
- while ((c = getopt_long (argc, argv, "aABCDef:gHhjJlnopPrSst:uU:vVvX:",
+ while ((c = getopt_long (argc, argv, "aABCDef:gHhjJlnopPrSst:uU:vVvWX:",
long_options, (int *) 0)) != EOF)
{
switch (c)
@@ -2171,6 +2177,9 @@ main (int argc, char **argv)
case 'V':
show_version = 1;
break;
+ case 'W':
+ non_weak = 1;
+ break;
case 'X':
/* Ignored for (partial) AIX compatibility. On AIX, the
argument has values 32, 64, or 32_64, and specifies that