]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add a --no-weak option to nm.
authorNick Clifton <nickc@redhat.com>
Wed, 18 May 2022 12:15:22 +0000 (13:15 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 18 May 2022 12:15:22 +0000 (13:15 +0100)
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.

binutils/ChangeLog
binutils/NEWS
binutils/doc/binutils.texi
binutils/nm.c
binutils/testsuite/binutils-all/nm.exp
binutils/testsuite/binutils-all/no-weak.s [new file with mode: 0644]

index ab65d20aca1912f74ec78e4a489f5c072ecc95db..6697697b9d0633dc7e16bbae6318e14452e00f49 100644 (file)
@@ -1,3 +1,16 @@
+2022-05-18  Nick Clifton  <nickc@redhat.com>
+
+       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.
+
 2022-04-25  Nick Clifton  <nickc@redhat.com>
 
        PR 29072
index c266bb9c3de171155a7f62345b596750640737dd..3043a7a7f3c3b9e49b2cb03e80ef695eb6bb3ff5 100644 (file)
@@ -1,7 +1,9 @@
 -*- text -*-
+* Add --no-weak/-W option to nm to make it ignore weak symbols.
 
 * Add an option to objdump and readelf to prevent attempts to access debuginfod
   servers when following links.
+
 * objcopy --weaken, --weaken-symbol, and --weaken-symbols now make ELF
   STB_GNU_UNIQUE symbols weak.
 
index 292588c241d14041cab1dd8410742f86c25da43d..81be746a17bf9407fbdc38940d45f2b438fdc9b6 100644 (file)
@@ -819,6 +819,7 @@ nm [@option{-A}|@option{-o}|@option{--print-file-name}]
    [@option{-u}|@option{--undefined-only}]
    [@option{-U}|@option{--defined-only}]
    [@option{-V}|@option{--version}]
+   [@option{-W}|@option{--no-weak}]
    [@option{-X 32_64}]
    [@option{--no-demangle}]
    [@option{--no-recurse-limit}|@option{--recurse-limit}]]
@@ -1213,6 +1214,10 @@ them as escape sequences highlighted in red (if supported by the
 output device).  The colouring is intended to draw attention to the
 presence of unicode sequences where they might not be expected.
 
+@item -W
+@itemx --no-weak
+Do not display weak symbols.
+
 @item --with-symbol-versions
 @item --without-symbol-versions
 Enables or disables the display of symbol version information.  The
index 9edaa8d26b0341d71c80a5caf59fc100bec7e1c4..60e4d8508850f08f1912bf77a2a07233f1b40053 100644 (file)
@@ -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}
@@ -364,6 +366,8 @@ usage (FILE *stream, int status)
   fprintf (stream, _("\
       --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, _("\
@@ -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
index 4560df16099dde92c411a8fa0fcca863087f5ae5..1c419df4d9a025adff3361998ca0791f92493242 100644 (file)
@@ -340,7 +340,37 @@ if [is_elf_format] {
        }
     }
 
-    
+    set testname "nm --no-weak"
+    if {![binutils_assemble $srcdir/$subdir/no-weak.s tmpdir/no-weak.o]} then {
+       fail "$testname (assembly)"
+    } else {
+       if [is_remote host] {
+           set tmpfile [remote_download host tmpdir/no-weak.o]
+       } else {
+           set tmpfile tmpdir/no-weak.o
+       }
+
+       set got [binutils_run $NM "$NMFLAGS --no-weak $tmpfile"]
+
+       if [regexp "weak_with_default_value" $got] then {
+           fail "$testname (weak symbol with default value)"
+       } else {
+           pass "$testname (weak symbol with default value)"
+       }
+
+       if [regexp "weak_without_default_value" $got] then {
+           fail "$testname (weak symbol without default value)"
+       } else {
+           pass "$testname (weak symbol without default value)"
+       }
+
+       # FIXME: We should re run this test without the --no-weak option
+       # and verify that the expected symbol names *are* shown...
+
+       if { $verbose < 1 } {
+           remote_file host delete "tmpdir/no0weak.o"
+       }
+    }    
 }
 
 # There are certainly other tests that could be run.
diff --git a/binutils/testsuite/binutils-all/no-weak.s b/binutils/testsuite/binutils-all/no-weak.s
new file mode 100644 (file)
index 0000000..a25454d
--- /dev/null
@@ -0,0 +1,13 @@
+       .file   "no-weak.c"
+       .text
+
+       .globl  weak_with_default_value
+       .weak   weak_with_default_value
+weak_with_default_value:       
+       .nop
+       
+       .data
+       .weak   weak_without_default_value
+       .dc.a   weak_without_default_value
+       
+