read_debug_line_header
[binutils-gdb.git] / binutils / nm.c
index 5d3d647843493a5ad46f00c6b561563243290682..82ccec6801c5c32d51d9e1645ecbe8b83004b0fb 100644 (file)
@@ -1,5 +1,5 @@
 /* nm.c -- Describe symbol table of a rel file.
-   Copyright (C) 1991-2019 Free Software Foundation, Inc.
+   Copyright (C) 1991-2021 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -67,7 +67,6 @@ struct extended_symbol_info
   coff_symbol_type *coffinfo;
   /* FIXME: We should add more fields for Type, Line, Section.  */
 };
-#define SYM_NAME(sym)        (sym->sinfo->name)
 #define SYM_VALUE(sym)       (sym->sinfo->value)
 #define SYM_TYPE(sym)        (sym->sinfo->type)
 #define SYM_STAB_NAME(sym)   (sym->sinfo->stab_name)
@@ -77,44 +76,66 @@ struct extended_symbol_info
   (sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize)
 
 /* The output formatting functions.  */
-static void print_object_filename_bsd (char *);
-static void print_object_filename_sysv (char *);
-static void print_object_filename_posix (char *);
-static void print_archive_filename_bsd (char *);
-static void print_archive_filename_sysv (char *);
-static void print_archive_filename_posix (char *);
-static void print_archive_member_bsd (char *, const char *);
-static void print_archive_member_sysv (char *, const char *);
-static void print_archive_member_posix (char *, const char *);
+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) (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) (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) (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,
@@ -130,18 +151,19 @@ 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];
 static unsigned int print_format = FORMAT_DEFAULT;
+static const char *print_format_string = NULL;
 
 /* Command options.  */
 
@@ -161,7 +183,15 @@ static int show_version = 0;       /* Show the version number.  */
 static int show_synthetic = 0; /* Display synthesized symbols too.  */
 static int line_numbers = 0;   /* Print line numbers for symbols.  */
 static int allow_special_symbols = 0;  /* Allow special symbols.  */
-static int with_symbol_versions = 0; /* Include symbol version information in the output.  */
+static int with_symbol_versions = -1; /* Output symbol version information.  */
+static int quiet = 0;          /* Suppress "no symbols" diagnostic.  */
+
+/* The characters to use for global and local ifunc symbols.  */
+#if DEFAULT_F_FOR_IFUNC_SYMBOLS
+static const char * ifunc_type_chars = "Ff";
+#else
+static const char * ifunc_type_chars = NULL;
+#endif
 
 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
 
@@ -192,7 +222,9 @@ enum long_option_values
   OPTION_PLUGIN,
   OPTION_SIZE_SORT,
   OPTION_RECURSE_LIMIT,
-  OPTION_NO_RECURSE_LIMIT
+  OPTION_NO_RECURSE_LIMIT,
+  OPTION_IFUNC_CHARS,
+  OPTION_QUIET
 };
 
 static struct option long_options[] =
@@ -203,6 +235,8 @@ static struct option long_options[] =
   {"extern-only", no_argument, &external_only, 1},
   {"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},
@@ -215,6 +249,7 @@ static struct option long_options[] =
   {"print-armap", no_argument, &print_armap, 1},
   {"print-file-name", no_argument, 0, 'o'},
   {"print-size", no_argument, 0, 'S'},
+  {"quiet", no_argument, 0, OPTION_QUIET},
   {"radix", required_argument, 0, 't'},
   {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
   {"recursion-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
@@ -227,6 +262,7 @@ static struct option long_options[] =
   {"undefined-only", no_argument, &undefined_only, 1},
   {"version", no_argument, &show_version, 1},
   {"with-symbol-versions", no_argument, &with_symbol_versions, 1},
+  {"without-symbol-versions", no_argument, &with_symbol_versions, 0},
   {0, no_argument, 0, 0}
 };
 \f
@@ -252,8 +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\
@@ -268,6 +306,7 @@ usage (FILE *stream, int status)
   fprintf (stream, _("\
   -S, --print-size       Print size of defined symbols\n\
   -s, --print-armap      Include index for symbols from archive members\n\
+      --quiet            Suppress \"no symbols\" diagnostic\n\
       --size-sort        Sort symbols by size\n\
       --special-syms     Include special symbols in the output\n\
       --synthetic        Display synthetic symbols as well\n\
@@ -323,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);
     }
@@ -393,21 +436,50 @@ get_coff_symbol_type (const struct internal_syment *sym)
    demangling it if requested.  */
 
 static void
-print_symname (const char *form, const char *name, bfd *abfd)
+print_symname (const char *form, struct extended_symbol_info *info,
+              const char *name, bfd *abfd)
 {
+  char *alloc = NULL;
+  char *atver = NULL;
+
+  if (name == NULL)
+    name = info->sinfo->name;
+  if (!with_symbol_versions
+      && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+    {
+      atver = strchr (name, '@');
+      if (atver)
+       *atver = 0;
+    }
   if (do_demangle && *name)
     {
-      char *res = bfd_demangle (abfd, name, demangle_flags);
+      alloc = bfd_demangle (abfd, name, demangle_flags);
+      if (alloc != NULL)
+       name = alloc;
+    }
+
+  if (info != NULL && info->elfinfo && with_symbol_versions)
+    {
+      const char *version_string;
+      bool hidden;
 
-      if (res != NULL)
+      version_string
+       = bfd_get_symbol_version_string (abfd, &info->elfinfo->symbol,
+                                        false, &hidden);
+      if (version_string && version_string[0])
        {
-         printf (form, res);
-         free (res);
-         return;
+         const char *at = "@@";
+         if (hidden || bfd_is_und_section (info->elfinfo->symbol.section))
+           at = "@";
+         alloc = reconcat (alloc, name, at, version_string, NULL);
+         if (alloc != NULL)
+           name = alloc;
        }
     }
-
   printf (form, name);
+  if (atver)
+    *atver = '@';
+  free (alloc);
 }
 
 static void
@@ -415,7 +487,7 @@ print_symdef_entry (bfd *abfd)
 {
   symindex idx = BFD_NO_MORE_SYMBOLS;
   carsym *thesym;
-  bfd_boolean everprinted = FALSE;
+  bool everprinted = false;
 
   for (idx = bfd_get_next_mapent (abfd, idx, &thesym);
        idx != BFD_NO_MORE_SYMBOLS;
@@ -425,14 +497,14 @@ print_symdef_entry (bfd *abfd)
       if (!everprinted)
        {
          printf (_("\nArchive index:\n"));
-         everprinted = TRUE;
+         everprinted = true;
        }
       elt = bfd_get_elt_at_index (abfd, idx);
       if (elt == NULL)
        bfd_fatal ("bfd_get_elt_at_index");
       if (thesym->name != (char *) NULL)
        {
-         print_symname ("%s", thesym->name, abfd);
+         print_symname ("%s", NULL, thesym->name, abfd);
          printf (" in %s\n", bfd_get_filename (elt));
        }
     }
@@ -440,14 +512,14 @@ print_symdef_entry (bfd *abfd)
 \f
 
 /* True when we can report missing plugin error.  */
-bfd_boolean report_plugin_err = TRUE;
+bool report_plugin_err = true;
 
 /* Choose which symbol entries to print;
    compact them downward to get rid of the rest.
    Return the number of symbols to be printed.  */
 
 static long
-filter_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
+filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
                long symcount, unsigned int size)
 {
   bfd_byte *from, *fromend, *to;
@@ -477,7 +549,7 @@ filter_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
          && strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0
          && report_plugin_err)
        {
-         report_plugin_err = FALSE;
+         report_plugin_err = false;
          non_fatal (_("%s: plugin needed to handle lto object"),
                     bfd_get_filename (abfd));
        }
@@ -531,7 +603,7 @@ filter_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
 /* These globals are used to pass information into the sorting
    routines.  */
 static bfd *sort_bfd;
-static bfd_boolean sort_dynamic;
+static bool sort_dynamic;
 static asymbol *sort_x;
 static asymbol *sort_y;
 
@@ -561,7 +633,6 @@ non_numeric_forward (const void *P_x, const void *P_y)
   if (xn == NULL)
     return -1;
 
-#ifdef HAVE_STRCOLL
   /* Solaris 2.5 has a bug in strcoll.
      strcoll returns invalid values when confronted with empty strings.  */
   if (*yn == '\0')
@@ -570,9 +641,6 @@ non_numeric_forward (const void *P_x, const void *P_y)
     return -1;
 
   return strcoll (xn, yn);
-#else
-  return strcmp (xn, yn);
-#endif
 }
 
 static int
@@ -592,8 +660,8 @@ numeric_forward (const void *P_x, const void *P_y)
   if (x == NULL || y == NULL)
     bfd_fatal (bfd_get_filename (sort_bfd));
 
-  xs = bfd_get_section (x);
-  ys = bfd_get_section (y);
+  xs = bfd_asymbol_section (x);
+  ys = bfd_asymbol_section (y);
 
   if (bfd_is_und_section (xs))
     {
@@ -645,8 +713,8 @@ size_forward1 (const void *P_x, const void *P_y)
   if (x == NULL || y == NULL)
     bfd_fatal (bfd_get_filename (sort_bfd));
 
-  xs = bfd_get_section (x);
-  ys = bfd_get_section (y);
+  xs = bfd_asymbol_section (x);
+  ys = bfd_asymbol_section (y);
 
   if (bfd_is_und_section (xs))
     abort ();
@@ -722,7 +790,7 @@ size_forward2 (const void *P_x, const void *P_y)
    size.  */
 
 static long
-sort_symbols_by_size (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
+sort_symbols_by_size (bfd *abfd, bool is_dynamic, void *minisyms,
                      long symcount, unsigned int size,
                      struct size_sym **symsizesp)
 {
@@ -774,7 +842,7 @@ sort_symbols_by_size (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
       else
        next = NULL;
 
-      sec = bfd_get_section (sym);
+      sec = bfd_asymbol_section (sym);
 
       /* Synthetic symbols don't have a full type set of data available, thus
         we can't rely on that information for the symbol size.  Ditto for
@@ -788,11 +856,11 @@ sort_symbols_by_size (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
       else
        {
          if (from + size < fromend
-             && sec == bfd_get_section (next))
+             && sec == bfd_asymbol_section (next))
            sz = valueof (next) - valueof (sym);
          else
-           sz = (bfd_get_section_vma (abfd, sec)
-                 + bfd_section_size (abfd, sec)
+           sz = (bfd_section_vma (sec)
+                 + bfd_section_size (sec)
                  - valueof (sym));
        }
 
@@ -870,6 +938,18 @@ print_symbol (bfd *        abfd,
 
   bfd_get_symbol_info (abfd, sym, &syminfo);
 
+  /* PR 22967 - Distinguish between local and global ifunc symbols.  */
+  if (syminfo.type == 'i'
+      && sym->flags & BSF_GNU_INDIRECT_FUNCTION)
+    {
+      if (ifunc_type_chars == NULL || ifunc_type_chars[0] == 0)
+       ; /* Change nothing.  */
+      else if (sym->flags & BSF_GLOBAL) 
+       syminfo.type = ifunc_type_chars[0];
+      else if (ifunc_type_chars[1] != 0)
+       syminfo.type = ifunc_type_chars[1];
+    }
+
   info.sinfo = &syminfo;
   info.ssize = ssize;
   /* Synthetic symbols do not have a full symbol type set of data available.
@@ -881,27 +961,12 @@ print_symbol (bfd *        abfd,
     }
   else
     {
-      info.elfinfo = elf_symbol_from (abfd, sym);
+      info.elfinfo = elf_symbol_from (sym);
       info.coffinfo = coff_symbol_from (sym);
     }
 
   format->print_symbol_info (&info, abfd);
 
-  if (with_symbol_versions)
-    {
-      const char *  version_string = NULL;
-      bfd_boolean   hidden = FALSE;
-
-      if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0)
-       version_string = bfd_get_symbol_version_string (abfd, sym, &hidden);
-
-      if (bfd_is_und_section (bfd_get_section (sym)))
-       hidden = TRUE;
-
-      if (version_string && *version_string != '\0')
-       printf (hidden ? "@%s" : "@@%s", version_string);
-    }
-
   if (line_numbers)
     {
       static asymbol **syms;
@@ -931,7 +996,7 @@ print_symbol (bfd *        abfd,
          lineno_cache_bfd = abfd;
        }
 
-      if (bfd_is_und_section (bfd_get_section (sym)))
+      if (bfd_is_und_section (bfd_asymbol_section (sym)))
        {
          static asection **secs;
          static arelent ***relocs;
@@ -1001,10 +1066,10 @@ print_symbol (bfd *        abfd,
                }
            }
        }
-      else if (bfd_get_section (sym)->owner == abfd)
+      else if (bfd_asymbol_section (sym)->owner == abfd)
        {
          if ((bfd_find_line (abfd, syms, sym, &filename, &lineno)
-              || bfd_find_nearest_line (abfd, bfd_get_section (sym),
+              || bfd_find_nearest_line (abfd, bfd_asymbol_section (sym),
                                         syms, sym->value, &filename,
                                         &functionname, &lineno))
              && filename != NULL
@@ -1019,11 +1084,11 @@ print_symbol (bfd *        abfd,
 /* Print the symbols when sorting by size.  */
 
 static void
-print_size_symbols (bfd *              abfd,
-                   bfd_boolean        is_dynamic,
-                   struct size_sym *  symsizes,
-                   long               symcount,
-                   bfd *              archive_bfd)
+print_size_symbols (bfd *abfd,
+                   bool is_dynamic,
+                   struct size_sym *symsizes,
+                   long symcount,
+                   bfd *archive_bfd)
 {
   asymbol *store;
   struct size_sym *from;
@@ -1058,12 +1123,12 @@ print_size_symbols (bfd *              abfd,
    SIZE is the size of a symbol in MINISYMS.  */
 
 static void
-print_symbols (bfd *         abfd,
-              bfd_boolean   is_dynamic,
-              void *        minisyms,
-              long          symcount,
-              unsigned int  size,
-              bfd *         archive_bfd)
+print_symbols (bfd *abfd,
+              bool is_dynamic,
+              void *minisyms,
+              long symcount,
+              unsigned int size,
+              bfd *archive_bfd)
 {
   asymbol *store;
   bfd_byte *from;
@@ -1103,7 +1168,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
     {
       if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
        {
-         non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
+         if (!quiet)
+           non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
          return;
        }
     }
@@ -1113,7 +1179,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
     {
       if (dynamic && bfd_get_error () == bfd_error_no_symbols)
        {
-         non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
+         if (!quiet)
+           non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
          return;
        }
 
@@ -1122,7 +1189,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
 
   if (symcount == 0)
     {
-      non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
+      if (!quiet)
+       non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
       return;
     }
 
@@ -1170,13 +1238,15 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
          *symp = 0;
          symcount += synth_count;
        }
+      if (!dynamic && dyn_syms != NULL)
+       free (dyn_syms);
     }
 
   /* lto_slim_object is set to false when a bfd is loaded with a compiler
      LTO plugin.  */
   if (abfd->lto_slim_object)
     {
-      report_plugin_err = FALSE;
+      report_plugin_err = false;
       non_fatal (_("%s: plugin needed to handle lto object"),
                 bfd_get_filename (abfd));
     }
@@ -1216,6 +1286,51 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
   free (symsizes);
 }
 
+/* Construct a formatting string for printing symbol values.  */
+
+static const char *
+get_print_format (void)
+{
+  const char * padding;
+  if (print_format == FORMAT_POSIX || print_format == FORMAT_JUST_SYMBOLS)
+    {
+      /* POSIX compatible output does not have any padding.  */
+      padding = "";
+    }
+  else if (print_width == 32)
+    {
+      padding ="08";
+    }
+  else /* print_width == 64 */
+    {
+      padding = "016";
+    }
+
+  const char * length = "l";
+  if (print_width == 64)
+    {
+#if BFD_HOST_64BIT_LONG
+      ;
+#elif BFD_HOST_64BIT_LONG_LONG
+#ifndef __MSVCRT__
+      length = "ll";
+#else
+      length = "I64";
+#endif
+#endif
+    }
+
+  const char * radix = NULL;
+  switch (print_radix)
+    {
+    case 8:  radix = "o"; break;
+    case 10: radix = "d"; break;
+    case 16: radix = "x"; break;
+    }
+
+  return concat ("%", padding, length, radix, NULL);
+}
+
 static void
 set_print_width (bfd *file)
 {
@@ -1234,6 +1349,8 @@ set_print_width (bfd *file)
       else
        print_width = 32;
     }
+  free ((char *) print_format_string);
+  print_format_string = get_print_format ();
 }
 
 static void
@@ -1297,21 +1414,21 @@ display_archive (bfd *file)
     }
 }
 
-static bfd_boolean
+static bool
 display_file (char *filename)
 {
-  bfd_boolean retval = TRUE;
+  bool retval = true;
   bfd *file;
   char **matching;
 
   if (get_file_size (filename) < 1)
-    return FALSE;
+    return false;
 
   file = bfd_openr (filename, target ? target : plugin_target);
   if (file == NULL)
     {
       bfd_nonfatal (filename);
-      return FALSE;
+      return false;
     }
 
   /* If printing line numbers, decompress the debug sections.  */
@@ -1336,7 +1453,7 @@ display_file (char *filename)
          list_matching_formats (matching);
          free (matching);
        }
-      retval = FALSE;
+      retval = false;
     }
 
   if (!bfd_close (file))
@@ -1357,14 +1474,14 @@ display_file (char *filename)
 /* Print the name of an object file given on the command line.  */
 
 static void
-print_object_filename_bsd (char *filename)
+print_object_filename_bsd (const char *filename)
 {
   if (filename_per_file && !filename_per_symbol)
     printf ("\n%s:\n", filename);
 }
 
 static void
-print_object_filename_sysv (char *filename)
+print_object_filename_sysv (const char *filename)
 {
   if (undefined_only)
     printf (_("\n\nUndefined symbols from %s:\n\n"), filename);
@@ -1379,35 +1496,45 @@ Name                  Value           Class        Type         Size
 }
 
 static void
-print_object_filename_posix (char *filename)
+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.  */
 
 static void
-print_archive_filename_bsd (char *filename)
+print_archive_filename_bsd (const char *filename)
 {
   if (filename_per_file)
     printf ("\n%s:\n", filename);
 }
 
 static void
-print_archive_filename_sysv (char *filename ATTRIBUTE_UNUSED)
+print_archive_filename_sysv (const char *filename ATTRIBUTE_UNUSED)
 {
 }
 
 static void
-print_archive_filename_posix (char *filename ATTRIBUTE_UNUSED)
+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.  */
 
 static void
-print_archive_member_bsd (char *archive ATTRIBUTE_UNUSED,
+print_archive_member_bsd (const char *archive ATTRIBUTE_UNUSED,
                          const char *filename)
 {
   if (!filename_per_symbol)
@@ -1415,7 +1542,7 @@ print_archive_member_bsd (char *archive ATTRIBUTE_UNUSED,
 }
 
 static void
-print_archive_member_sysv (char *archive, const char *filename)
+print_archive_member_sysv (const char *archive, const char *filename)
 {
   if (undefined_only)
     printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename);
@@ -1430,11 +1557,18 @@ Name                  Value           Class        Type         Size
 }
 
 static void
-print_archive_member_posix (char *archive, const char *filename)
+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.  */
@@ -1473,59 +1607,14 @@ print_symbol_filename_posix (bfd *archive_bfd, bfd *abfd)
        printf ("%s: ", bfd_get_filename (abfd));
     }
 }
-\f
-/* Construct a formatting string for printing symbol values.  */
 
-static const char *
-get_print_format (void)
+static void
+do_not_print_symbol_filename (bfd *archive_bfd ATTRIBUTE_UNUSED,
+                             bfd *abfd ATTRIBUTE_UNUSED)
 {
-  static const char * saved_format = NULL;
-
-  /* See if we have already constructed the format.  */
-  if (saved_format)
-    return saved_format;
-
-  const char * padding;
-  if (print_format == FORMAT_POSIX)
-    {
-      /* POSIX compatible output does not have any padding.  */
-      padding = "";
-    }
-  else if (print_width == 32)
-    {
-      padding ="08";
-    }
-  else /* print_width == 64 */
-    {
-      padding = "016";
-    }
-
-  const char * length = "l";
-  if (print_width == 64)
-    {
-#if BFD_HOST_64BIT_LONG
-      ;
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-      length = "ll";
-#else
-      length = "I64";
-#endif
-#endif
-    }
-
-  const char * radix = NULL;
-  switch (print_radix)
-    {
-    case 8:  radix = "o"; break;
-    case 10: radix = "d"; break;
-    case 16: radix = "x"; break;
-    }
-
-  saved_format = concat ("%", padding, length, radix, NULL);
-  return saved_format;
 }
 
+\f
 /* Print a symbol value.  */
 
 static void
@@ -1534,12 +1623,12 @@ print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val)
   switch (print_width)
     {
     case 32:
-      printf (get_print_format (), (unsigned long) val);
+      printf (print_format_string, (unsigned long) val);
       break;
 
     case 64:
 #if BFD_HOST_64BIT_LONG || BFD_HOST_64BIT_LONG_LONG
-      printf (get_print_format (), val);
+      printf (print_format_string, val);
 #else
       /* We have a 64 bit value to print, but the host is only 32 bit.  */
       if (print_radix == 16)
@@ -1608,13 +1697,13 @@ print_symbol_info_bsd (struct extended_symbol_info *info, bfd *abfd)
       printf (desc_format, SYM_STAB_DESC (info));
       printf (" %5s", SYM_STAB_NAME (info));
     }
-  print_symname (" %s", SYM_NAME (info), abfd);
+  print_symname (" %s", info, NULL, abfd);
 }
 
 static void
 print_symbol_info_sysv (struct extended_symbol_info *info, bfd *abfd)
 {
-  print_symname ("%-20s|", SYM_NAME (info), abfd);
+  print_symname ("%-20s|", info, NULL, abfd);
 
   if (bfd_is_undefined_symclass (SYM_TYPE (info)))
     {
@@ -1669,7 +1758,7 @@ print_symbol_info_sysv (struct extended_symbol_info *info, bfd *abfd)
 static void
 print_symbol_info_posix (struct extended_symbol_info *info, bfd *abfd)
 {
-  print_symname ("%s ", SYM_NAME (info), abfd);
+  print_symname ("%s ", info, NULL, abfd);
   printf ("%c ", SYM_TYPE (info));
 
   if (bfd_is_undefined_symclass (SYM_TYPE (info)))
@@ -1682,6 +1771,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)
@@ -1689,13 +1784,11 @@ main (int argc, char **argv)
   int c;
   int retval;
 
-#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
+#ifdef HAVE_LC_MESSAGES
   setlocale (LC_MESSAGES, "");
 #endif
-#if defined (HAVE_SETLOCALE)
   setlocale (LC_CTYPE, "");
   setlocale (LC_COLLATE, "");
-#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
@@ -1714,7 +1807,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)
@@ -1749,6 +1842,9 @@ main (int argc, char **argv)
        case OPTION_NO_RECURSE_LIMIT:
          demangle_flags |= DMGL_NO_RECURSE_LIMIT;
          break;
+       case OPTION_QUIET:
+         quiet = 1;
+         break;
        case 'D':
          dynamic = 1;
          break;
@@ -1786,6 +1882,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;
@@ -1828,6 +1927,10 @@ main (int argc, char **argv)
 #endif
          break;
 
+       case OPTION_IFUNC_CHARS:
+         ifunc_type_chars = optarg;
+         break;
+
        case 0:         /* A long option that just sets a flag.  */
          break;