Update documentation of readelf's --unwind option.
[deliverable/binutils-gdb.git] / binutils / nm.c
index d537441d69547d8607c12659ec66d59c03512043..bc4fccb5fcb80db9d4f571c9367a0876f0b429e7 100644 (file)
@@ -1,5 +1,5 @@
 /* nm.c -- Describe symbol table of a rel file.
-   Copyright (C) 1991-2016 Free Software Foundation, Inc.
+   Copyright (C) 1991-2018 Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -157,7 +157,6 @@ static int sort_by_size = 0;        /* Sort by size of symbol.  */
 static int undefined_only = 0; /* Print undefined symbols only.  */
 static int dynamic = 0;                /* Print dynamic symbols.  */
 static int show_version = 0;   /* Show the version number.  */
-static int show_stats = 0;     /* Show statistics.  */
 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.  */
@@ -221,7 +220,6 @@ static struct option long_options[] =
   {"reverse-sort", no_argument, &reverse_sort, 1},
   {"size-sort", no_argument, 0, OPTION_SIZE_SORT},
   {"special-syms", no_argument, &allow_special_symbols, 1},
-  {"stats", no_argument, &show_stats, 1},
   {"synthetic", no_argument, &show_synthetic, 1},
   {"target", required_argument, 0, OPTION_TARGET},
   {"defined-only", no_argument, &defined_only, 1},
@@ -480,7 +478,9 @@ filter_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
       if (sym == NULL)
        bfd_fatal (bfd_get_filename (abfd));
 
-      if (strcmp (sym->name, "__gnu_lto_slim") == 0)
+      if (sym->name[0] == '_'
+         && sym->name[1] == '_'
+         && strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0)
        non_fatal (_("%s: plugin needed to handle lto object"),
                   bfd_get_filename (abfd));
 
@@ -685,7 +685,8 @@ size_forward1 (const void *P_x, const void *P_y)
 
 #define file_symbol(s, sn, snl)                        \
   (((s)->flags & BSF_FILE) != 0                        \
-   || ((sn)[(snl) - 2] == '.'                  \
+   || ((snl) > 2                               \
+       && (sn)[(snl) - 2] == '.'               \
        && ((sn)[(snl) - 1] == 'o'              \
           || (sn)[(snl) - 1] == 'a')))
 
@@ -777,9 +778,14 @@ sort_symbols_by_size (bfd *abfd, bfd_boolean is_dynamic, void *minisyms,
 
       sec = bfd_get_section (sym);
 
-      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+      /* 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
+        bfd/section.c:global_syms like *ABS*.  */
+      if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
+         && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
        sz = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
-      else if (bfd_is_com_section (sec))
+      else if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
+              && bfd_is_com_section (sec))
        sz = sym->value;
       else
        {
@@ -868,8 +874,9 @@ print_symbol (bfd *        abfd,
 
   info.sinfo = &syminfo;
   info.ssize = ssize;
-  /* Synthetic symbols do not have a full symbol type set of data available.  */
-  if ((sym->flags & BSF_SYNTHETIC) != 0)
+  /* Synthetic symbols do not have a full symbol type set of data available.
+     Nor do bfd/section.c:global_syms like *ABS*.  */
+  if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) != 0)
     {
       info.elfinfo = NULL;
       info.coffinfo = NULL;
@@ -887,7 +894,7 @@ print_symbol (bfd *        abfd,
       const char *  version_string = NULL;
       bfd_boolean   hidden = FALSE;
 
-      if ((sym->flags & BSF_SYNTHETIC) == 0)
+      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)))
@@ -1092,6 +1099,7 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
   void *minisyms;
   unsigned int size;
   struct size_sym *symsizes;
+  asymbol *synthsyms = NULL;
 
   if (! dynamic)
     {
@@ -1122,7 +1130,6 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
 
   if (show_synthetic && size == sizeof (asymbol *))
     {
-      asymbol *synthsyms;
       asymbol **static_syms = NULL;
       asymbol **dyn_syms = NULL;
       long static_count = 0;
@@ -1199,6 +1206,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
   else
     print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd);
 
+  if (synthsyms)
+    free (synthsyms);
   free (minisyms);
   free (symsizes);
 }
@@ -1645,7 +1654,8 @@ main (int argc, char **argv)
 
   expandargv (&argc, &argv);
 
-  bfd_init ();
+  if (bfd_init () != BFD_INIT_MAGIC)
+    fatal (_("fatal error: libbfd ABI mismatch"));
   set_default_bfd_target ();
 
   while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrSst:uvVvX:",
@@ -1793,15 +1803,6 @@ main (int argc, char **argv)
 
   END_PROGRESS (program_name);
 
-#ifdef HAVE_SBRK
-  if (show_stats)
-    {
-      char *lim = (char *) sbrk (0);
-
-      non_fatal (_("data size %ld"), (long) (lim - (char *) &environ));
-    }
-#endif
-
   exit (retval);
   return retval;
 }
This page took 0.051033 seconds and 4 git commands to generate.