]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add a symbols-only mode to nm.
authorNick Clifton <nickc@redhat.com>
Mon, 15 Mar 2021 10:55:49 +0000 (10:55 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 15 Mar 2021 10:55:49 +0000 (10:55 +0000)
PR 27487
* nm.c (FORMAT_JUST_SYMBOLS): Define.
(struct optput_fns): Add entry for FORMAT_JUST_SYMBOLS.
(long_options): Add just-symbols.
(set_output_format): Add support for just-symbols.
(get_print_format): Likewise.
(do_not_print_object_filename): New function.
(do_not_print_archive_filename): New function.
(do_not_print_archive_member): New function.
(do_not_print_symbol_filename): New function.
(just_print_symbol_name): New function.
(main): Handle --just-symbols.
* NEWS: Mention the new feature.
* doc/binutils.texi: Document the new feature.

binutils/ChangeLog
binutils/NEWS
binutils/doc/binutils.texi
binutils/nm.c

index 37460e7bcde0948c23c8df52d4ff46aafe6153be..62f98b4cda027eb9316eaec0297981d02b0757b1 100644 (file)
@@ -1,3 +1,20 @@
+2021-03-15  Nick Clifton  <nickc@redhat.com>
+
+       PR 27487
+       * nm.c (FORMAT_JUST_SYMBOLS): Define.
+       (struct optput_fns): Add entry for FORMAT_JUST_SYMBOLS.
+       (long_options): Add just-symbols.
+       (set_output_format): Add support for just-symbols.
+       (get_print_format): Likewise.
+       (do_not_print_object_filename): New function.
+       (do_not_print_archive_filename): New function.
+       (do_not_print_archive_member): New function.
+       (do_not_print_symbol_filename): New function.
+       (just_print_symbol_name): New function.
+       (main): Handle --just-symbols.
+       * NEWS: Mention the new feature.
+       * doc/binutils.texi: Document the new feature.
+
 2021-03-12  ClĂ©ment Chigot  <clement.chigot@atos.net>
 
        * od-xcoff.c: Replace RTB by TRL entry.
index a4d7a61ef2df4d9ccb652411a605b6e7b3b70558..c035f522e3f152a58cf1e15e0a8cb61646018bb5 100644 (file)
@@ -1,5 +1,9 @@
 -*- text -*-
 
+* A new format has been added to the nm program.  Specifying
+  --format=just-symbols (or just using -j) will tell the program to only
+  display symbol names and nothing else.
+
 * A new command line --keep-section-symbols has been added to objcopy and
   strip.  This stops the removal of unused section symbols when the file is
   copied.  Removing these symbols saves space, but sometimes they are needed by
index a9d1dd3e73b98f5235fd7f3b5aed7c8679d3dd1e..292f71110c9b101c52fac39ee25371ae5bb4db52 100644 (file)
@@ -793,23 +793,37 @@ The @sc{gnu} linker @command{ld} is now described in a separate manual.
 
 @smallexample
 @c man begin SYNOPSIS nm
-nm [@option{-A}|@option{-o}|@option{--print-file-name}] [@option{-a}|@option{--debug-syms}]
-   [@option{-B}|@option{--format=bsd}] [@option{-C}|@option{--demangle}[=@var{style}]]
-   [@option{-D}|@option{--dynamic}] [@option{-f}@var{format}|@option{--format=}@var{format}]
-   [@option{-g}|@option{--extern-only}] [@option{-h}|@option{--help}]
+nm [@option{-A}|@option{-o}|@option{--print-file-name}]
+   [@option{-a}|@option{--debug-syms}]
+   [@option{-B}|@option{--format=bsd}]
+   [@option{-C}|@option{--demangle}[=@var{style}]]
+   [@option{-D}|@option{--dynamic}]
+   [@option{-f}@var{format}|@option{--format=}@var{format}]
+   [@option{-g}|@option{--extern-only}]
+   [@option{-h}|@option{--help}]
    [@option{--ifunc-chars=@var{CHARS}}]
+   [@option{-j}|@option{--format=just-symbols}]
    [@option{-l}|@option{--line-numbers}] [@option{--inlines}]
    [@option{-n}|@option{-v}|@option{--numeric-sort}]
-   [@option{-P}|@option{--portability}] [@option{-p}|@option{--no-sort}]
-   [@option{-r}|@option{--reverse-sort}] [@option{-S}|@option{--print-size}]
-   [@option{-s}|@option{--print-armap}] [@option{-t} @var{radix}|@option{--radix=}@var{radix}]
-   [@option{-u}|@option{--undefined-only}] [@option{-V}|@option{--version}]
-   [@option{-X 32_64}] [@option{--defined-only}] [@option{--no-demangle}]
-   [@option{--plugin} @var{name}]
+   [@option{-P}|@option{--portability}]
+   [@option{-p}|@option{--no-sort}]
+   [@option{-r}|@option{--reverse-sort}]
+   [@option{-S}|@option{--print-size}]
+   [@option{-s}|@option{--print-armap}]
+   [@option{-t} @var{radix}|@option{--radix=}@var{radix}]
+   [@option{-u}|@option{--undefined-only}]
+   [@option{-V}|@option{--version}]
+   [@option{-X 32_64}]
+   [@option{--defined-only}]
+   [@option{--no-demangle}]
    [@option{--no-recurse-limit}|@option{--recurse-limit}]]
-   [@option{--size-sort}] [@option{--special-syms}]
-   [@option{--synthetic}] [@option{--with-symbol-versions}]
-   [@option{--without-symbol-versions}] [@option{--target=}@var{bfdname}]
+   [@option{--plugin} @var{name}]
+   [@option{--size-sort}]
+   [@option{--special-syms}]
+   [@option{--synthetic}]
+   [@option{--target=}@var{bfdname}]
+   [@option{--with-symbol-versions}]
+   [@option{--without-symbol-versions}]
    [@var{objfile}@dots{}]
 @c man end
 @end smallexample
@@ -1027,7 +1041,7 @@ libraries.
 @cindex @command{nm} format
 @cindex @command{nm} compatibility
 Use the output format @var{format}, which can be @code{bsd},
-@code{sysv}, or @code{posix}.  The default is @code{bsd}.
+@code{sysv}, @code{posix} or @code{just-symbols}.  The default is @code{bsd}.
 Only the first character of @var{format} is significant; it can be
 either upper or lower case.
 
@@ -1049,6 +1063,9 @@ first character will be used for global indirect function symbols and
 the second character, if present, will be used for local indirect
 function symbols.
 
+@item j
+The same as @option{--format=just-symbols}.
+
 @item -l
 @itemx --line-numbers
 @cindex symbol line numbers
index 2637756c6475694808c30d3f404832ebf69dcb47..119c486af6274602d173d2905b9df97b39ff25a6 100644 (file)
@@ -79,41 +79,63 @@ struct extended_symbol_info
 static void print_object_filename_bsd (const char *);
 static void print_object_filename_sysv (const char *);
 static void print_object_filename_posix (const char *);
+static void do_not_print_object_filename (const char *);
+
 static void print_archive_filename_bsd (const char *);
 static void print_archive_filename_sysv (const char *);
 static void print_archive_filename_posix (const char *);
+static void do_not_print_archive_filename (const char *);
+
 static void print_archive_member_bsd (const char *, const char *);
 static void print_archive_member_sysv (const char *, const char *);
 static void print_archive_member_posix (const char *, const char *);
+static void do_not_print_archive_member (const char *, const char *);
+
 static void print_symbol_filename_bsd (bfd *, bfd *);
 static void print_symbol_filename_sysv (bfd *, bfd *);
 static void print_symbol_filename_posix (bfd *, bfd *);
-static void print_value (bfd *, bfd_vma);
+static void do_not_print_symbol_filename (bfd *, bfd *);
+
 static void print_symbol_info_bsd (struct extended_symbol_info *, bfd *);
 static void print_symbol_info_sysv (struct extended_symbol_info *, bfd *);
 static void print_symbol_info_posix (struct extended_symbol_info *, bfd *);
+static void just_print_symbol_name (struct extended_symbol_info *, bfd *);
+
+static void print_value (bfd *, bfd_vma);
 
 /* Support for different output formats.  */
 struct output_fns
-  {
-    /* Print the name of an object file given on the command line.  */
-    void (*print_object_filename) (const char *);
+{
+  /* Print the name of an object file given on the command line.  */
+  void (*print_object_filename) (const char *);
 
-    /* Print the name of an archive file given on the command line.  */
-    void (*print_archive_filename) (const char *);
+  /* Print the name of an archive file given on the command line.  */
+  void (*print_archive_filename) (const char *);
 
-    /* Print the name of an archive member file.  */
-    void (*print_archive_member) (const char *, const char *);
+  /* Print the name of an archive member file.  */
+  void (*print_archive_member) (const char *, const char *);
 
-    /* Print the name of the file (and archive, if there is one)
-       containing a symbol.  */
-    void (*print_symbol_filename) (bfd *, bfd *);
+  /* Print the name of the file (and archive, if there is one)
+     containing a symbol.  */
+  void (*print_symbol_filename) (bfd *, bfd *);
 
-    /* Print a line of information about a symbol.  */
-    void (*print_symbol_info) (struct extended_symbol_info *, bfd *);
-  };
+  /* Print a line of information about a symbol.  */
+  void (*print_symbol_info) (struct extended_symbol_info *, bfd *);
+};
 
-static struct output_fns formats[] =
+/* Indices in `formats'.  */
+enum formats
+{
+  FORMAT_BSD = 0,
+  FORMAT_SYSV,
+  FORMAT_POSIX,
+  FORMAT_JUST_SYMBOLS,
+  FORMAT_MAX
+};
+
+#define FORMAT_DEFAULT FORMAT_BSD
+
+static struct output_fns formats[FORMAT_MAX] =
 {
   {print_object_filename_bsd,
    print_archive_filename_bsd,
@@ -129,14 +151,14 @@ static struct output_fns formats[] =
    print_archive_filename_posix,
    print_archive_member_posix,
    print_symbol_filename_posix,
-   print_symbol_info_posix}
+   print_symbol_info_posix},
+  {do_not_print_object_filename,
+   do_not_print_archive_filename,
+   do_not_print_archive_member,
+   do_not_print_symbol_filename,
+   just_print_symbol_name}
 };
 
-/* Indices in `formats'.  */
-#define FORMAT_BSD 0
-#define FORMAT_SYSV 1
-#define FORMAT_POSIX 2
-#define FORMAT_DEFAULT FORMAT_BSD
 
 /* The output format to use.  */
 static struct output_fns *format = &formats[FORMAT_DEFAULT];
@@ -214,6 +236,7 @@ static struct option long_options[] =
   {"format", required_argument, 0, 'f'},
   {"help", no_argument, 0, 'h'},
   {"ifunc-chars", required_argument, 0, OPTION_IFUNC_CHARS},
+  {"just-symbols", no_argument, 0, 'j'},
   {"line-numbers", no_argument, 0, 'l'},
   {"no-cplus", no_argument, &do_demangle, 0},  /* Linux compatibility.  */
   {"no-demangle", no_argument, &do_demangle, 0},
@@ -265,9 +288,10 @@ usage (FILE *stream, int status)
       --defined-only     Display only defined symbols\n\
   -e                     (ignored)\n\
   -f, --format=FORMAT    Use the output format FORMAT.  FORMAT can be `bsd',\n\
-                           `sysv' or `posix'.  The default is `bsd'\n\
+                           `sysv', `posix' or 'just-symbols'.  The default is `bsd'\n\
   -g, --extern-only      Display only external symbols\n\
     --ifunc-chars=CHARS  Characters to use when displaying ifunc symbols\n\
+  -j, --just-symbols     Same as --format=just-symbols\n\
   -l, --line-numbers     Use debugging information to find a filename and\n\
                            line number for each symbol\n\
   -n, --numeric-sort     Sort symbols numerically by address\n\
@@ -338,6 +362,10 @@ set_output_format (char *f)
     case 'S':
       i = FORMAT_SYSV;
       break;
+    case 'j':
+    case 'J':
+      i = FORMAT_JUST_SYMBOLS;
+      break;
     default:
       fatal (_("%s: invalid output format"), f);
     }
@@ -1268,7 +1296,7 @@ static const char *
 get_print_format (void)
 {
   const char * padding;
-  if (print_format == FORMAT_POSIX)
+  if (print_format == FORMAT_POSIX || print_format == FORMAT_JUST_SYMBOLS)
     {
       /* POSIX compatible output does not have any padding.  */
       padding = "";
@@ -1477,6 +1505,11 @@ print_object_filename_posix (const char *filename)
   if (filename_per_file && !filename_per_symbol)
     printf ("%s:\n", filename);
 }
+
+static void
+do_not_print_object_filename (const char *filename ATTRIBUTE_UNUSED)
+{
+}
 \f
 /* Print the name of an archive file given on the command line.  */
 
@@ -1496,6 +1529,11 @@ static void
 print_archive_filename_posix (const char *filename ATTRIBUTE_UNUSED)
 {
 }
+
+static void
+do_not_print_archive_filename (const char *filename ATTRIBUTE_UNUSED)
+{
+}
 \f
 /* Print the name of an archive member file.  */
 
@@ -1528,6 +1566,13 @@ print_archive_member_posix (const char *archive, const char *filename)
   if (!filename_per_symbol)
     printf ("%s[%s]:\n", archive, filename);
 }
+
+static void
+do_not_print_archive_member (const char *archive ATTRIBUTE_UNUSED,
+                            const char *filename ATTRIBUTE_UNUSED)
+{
+}
+
 \f
 /* Print the name of the file (and archive, if there is one)
    containing a symbol.  */
@@ -1566,6 +1611,13 @@ print_symbol_filename_posix (bfd *archive_bfd, bfd *abfd)
        printf ("%s: ", bfd_get_filename (abfd));
     }
 }
+
+static void
+do_not_print_symbol_filename (bfd *archive_bfd ATTRIBUTE_UNUSED,
+                             bfd *abfd ATTRIBUTE_UNUSED)
+{
+}
+
 \f
 /* Print a symbol value.  */
 
@@ -1723,6 +1775,12 @@ print_symbol_info_posix (struct extended_symbol_info *info, bfd *abfd)
        print_value (abfd, SYM_SIZE (info));
     }
 }
+
+static void
+just_print_symbol_name (struct extended_symbol_info *info, bfd *abfd)
+{
+  print_symname ("%s", info, NULL, abfd);
+}
 \f
 int
 main (int argc, char **argv)
@@ -1755,7 +1813,7 @@ main (int argc, char **argv)
     fatal (_("fatal error: libbfd ABI mismatch"));
   set_default_bfd_target ();
 
-  while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrSst:uvVvX:",
+  while ((c = getopt_long (argc, argv, "aABCDef:gHhjJlnopPrSst:uvVvX:",
                           long_options, (int *) 0)) != EOF)
     {
       switch (c)
@@ -1830,6 +1888,9 @@ main (int argc, char **argv)
        case 'P':
          set_output_format ("posix");
          break;
+       case 'j':
+         set_output_format ("just-symbols");
+         break;
        case 'r':
          reverse_sort = 1;
          break;