* linker.c (link_action): Change COMMON_ROW/indr to from CREF to
[deliverable/binutils-gdb.git] / binutils / nm.c
index 201c3c90104b1cc3cc8ef8245eee844a72a30672..835036818e0b42d1cc16be5c64b5a9d1d15a0d8b 100644 (file)
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
-#include "sysdep.h"
+#include "progress.h"
 #include "bucomm.h"
 #include "getopt.h"
 #include "aout/stab_gnu.h"
 #include "aout/ranlib.h"
 #include "demangle.h"
+#include "libiberty.h"
+
+/* When sorting by size, we use this structure to hold the size and a
+   pointer to the minisymbol.  */
+
+struct size_sym
+{
+  const PTR minisym;
+  bfd_vma size;
+};
 
 static boolean
 display_file PARAMS ((char *filename));
@@ -31,16 +41,44 @@ display_file PARAMS ((char *filename));
 static void
 display_rel_file PARAMS ((bfd * file, bfd * archive));
 
-static unsigned int
-filter_symbols PARAMS ((bfd * file, asymbol ** syms, unsigned long symcount));
+static long
+filter_symbols PARAMS ((bfd *, boolean, PTR, long, unsigned int));
+
+static long
+sort_symbols_by_size PARAMS ((bfd *, boolean, PTR, long, unsigned int,
+                             struct size_sym **));
+
+static void
+print_symbols PARAMS ((bfd *, boolean, PTR, long, unsigned int, bfd *));
+
+static void
+print_size_symbols PARAMS ((bfd *, boolean, struct size_sym *, long, bfd *));
 
 static void
-print_symbols PARAMS ((bfd * file, asymbol ** syms, unsigned long symcount,
-                      bfd * archive));
+print_symbol PARAMS ((bfd *, asymbol *, bfd *));
 
 static void
 print_symdef_entry PARAMS ((bfd * abfd));
 
+/* The sorting functions.  */
+
+static int
+numeric_forward PARAMS ((const PTR, const PTR));
+
+static int
+numeric_reverse PARAMS ((const PTR, const PTR));
+
+static int
+non_numeric_forward PARAMS ((const PTR, const PTR));
+
+static int
+non_numeric_reverse PARAMS ((const PTR, const PTR));
+
+static int
+size_forward1 PARAMS ((const PTR, const PTR));
+
+static int
+size_forward2 PARAMS ((const PTR, const PTR));
 
 /* The output formatting functions.  */
 
@@ -84,6 +122,9 @@ static void
 print_symbol_filename_posix PARAMS ((bfd * archive_bfd, bfd * abfd));
 
 
+static void
+print_value PARAMS ((bfd_vma));
+
 static void
 print_symbol_info_bsd PARAMS ((symbol_info * info, bfd * abfd));
 
@@ -151,19 +192,27 @@ static int print_debug_syms = 0;  /* print debugger-only symbols too */
 static int print_armap = 0;    /* describe __.SYMDEF data in archive files.  */
 static int reverse_sort = 0;   /* sort in downward(alpha or numeric) order */
 static int sort_numerically = 0;       /* sort in numeric rather than alpha order */
+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 */
 
 /* When to print the names of files.  Not mutually exclusive in SYSV format.  */
 static int filename_per_file = 0;      /* Once per file, on its own line.  */
 static int filename_per_symbol = 0;    /* Once per symbol, at start of line.  */
 
 /* Print formats for printing a symbol value.  */
-#ifdef HOST_64_BIT
-static char value_format[] = "%08x%08x";
-#else
+#ifndef BFD64
 static char value_format[] = "%08lx";
+#else
+#if BFD_HOST_64BIT_LONG
+static char value_format[] = "%016lx";
+#else
+/* We don't use value_format for this case.  */
+#endif
 #endif
+static int print_radix = 16;
 /* Print formats for printing stab info.  */
 static char other_format[] = "%02x";
 static char desc_format[] = "%04x";
@@ -178,9 +227,12 @@ static struct option long_options[] =
 {
   {"debug-syms", no_argument, &print_debug_syms, 1},
   {"demangle", no_argument, &do_demangle, 1},
+  {"dynamic", no_argument, &dynamic, 1},
   {"extern-only", no_argument, &external_only, 1},
   {"format", required_argument, 0, 'f'},
   {"help", no_argument, 0, 'h'},
+  {"no-cplus", no_argument, &do_demangle, 0},  /* Linux compatibility.  */
+  {"no-demangle", no_argument, &do_demangle, 0},
   {"no-sort", no_argument, &no_sort, 1},
   {"numeric-sort", no_argument, &sort_numerically, 1},
   {"portability", no_argument, 0, 'P'},
@@ -188,6 +240,8 @@ static struct option long_options[] =
   {"print-file-name", no_argument, 0, 'o'},
   {"radix", required_argument, 0, 't'},
   {"reverse-sort", no_argument, &reverse_sort, 1},
+  {"size-sort", no_argument, &sort_by_size, 1},
+  {"stats", no_argument, &show_stats, 1},
   {"target", required_argument, 0, 200},
   {"undefined-only", no_argument, &undefined_only, 1},
   {"version", no_argument, &show_version, 1},
@@ -202,12 +256,15 @@ usage (stream, status)
      int status;
 {
   fprintf (stream, "\
-Usage: %s [-aABCgnopPrsuvV] [-t radix] [--radix=radix] [--target=bfdname]\n\
+Usage: %s [-aABCDgnopPrsuvV] [-t radix] [--radix=radix] [--target=bfdname]\n\
        [--debug-syms] [--extern-only] [--print-armap] [--print-file-name]\n\
-       [--numeric-sort] [--no-sort] [--reverse-sort] [--undefined-only]\n\
-       [--portability] [-f {bsd,sysv,posix}] [--format={bsd,sysv,posix}]\n\
-       [--demangle] [--version] [--help] [file...]\n",
+       [--numeric-sort] [--no-sort] [--reverse-sort] [--size-sort]\n\
+       [--undefined-only] [--portability] [-f {bsd,sysv,posix}]\n\
+       [--format={bsd,sysv,posix}] [--demangle] [--no-demangle] [--dynamic]\n\
+       [--version] [--help]\n\
+       [file...]\n",
           program_name);
+  list_supported_targets (program_name, stream);
   exit (status);
 }
 
@@ -219,13 +276,23 @@ set_print_radix (radix)
 {
   switch (*radix)
     {
+    case 'x':
+      break;
     case 'd':
     case 'o':
-    case 'x':
-#ifdef HOST_64_BIT
-      value_format[3] = value_format[7] = *radix;
-#else
+      if (*radix == 'd')
+       print_radix = 10;
+      else
+       print_radix = 8;
+#ifndef BFD64
       value_format[4] = *radix;
+#else
+#if BFD_HOST_64BIT_LONG
+      value_format[5] = *radix;
+#else
+      /* This case requires special handling for octal and decimal
+         printing.  */
+#endif
 #endif
       other_format[3] = desc_format[3] = *radix;
       break;
@@ -273,9 +340,11 @@ main (argc, argv)
   program_name = *argv;
   xmalloc_set_program_name (program_name);
 
+  START_PROGRESS (program_name, 0);
+
   bfd_init ();
 
-  while ((c = getopt_long (argc, argv, "aABCf:gnopPrst:uvV", long_options, (int *) 0)) != EOF)
+  while ((c = getopt_long (argc, argv, "aABCDef:gnopPrst:uvV", long_options, (int *) 0)) != EOF)
     {
       switch (c)
        {
@@ -292,6 +361,12 @@ main (argc, argv)
        case 'C':
          do_demangle = 1;
          break;
+       case 'D':
+         dynamic = 1;
+         break;
+       case 'e':
+         /* Ignored for HP/UX compatibility.  */
+         break;
        case 'f':
          set_output_format (optarg);
          break;
@@ -356,10 +431,24 @@ main (argc, argv)
   /* We were given several filenames to do.  */
   while (optind < argc)
     {
+      PROGRESS (1);
       if (!display_file (argv[optind++]))
        retval++;
     }
 
+  END_PROGRESS (program_name);
+
+#ifdef HAVE_SBRK
+  if (show_stats)
+    {
+      extern char **environ;
+      char *lim = (char *) sbrk (0);
+
+      fprintf (stderr, "%s: data size %ld\n", program_name,
+              (long) (lim - (char *) &environ));
+    }
+#endif
+
   exit (retval);
   return retval;
 }
@@ -379,6 +468,8 @@ display_archive (file)
 
   for (;;)
     {
+      PROGRESS (1);
+
       arfile = bfd_openr_next_archived_file (file, arfile);
 
       if (arfile == NULL)
@@ -454,49 +545,287 @@ display_file (filename)
   return retval;
 }
 \f
+/* These globals are used to pass information into the sorting
+   routines.  */
+static bfd *sort_bfd;
+static boolean sort_dynamic;
+static asymbol *sort_x;
+static asymbol *sort_y;
+
 /* Symbol-sorting predicates */
 #define valueof(x) ((x)->section->vma + (x)->value)
-int
-numeric_forward (x, y)
-     CONST void *x;
-     CONST void *y;
+
+/* Numeric sorts.  Undefined symbols are always considered "less than"
+   defined symbols with zero values.  Common symbols are not treated
+   specially -- i.e., their sizes are used as their "values".  */
+
+static int
+numeric_forward (P_x, P_y)
+     const PTR P_x;
+     const PTR P_y;
 {
-  return (valueof (*(asymbol **) x) - valueof (*(asymbol **) y));
+  asymbol *x, *y;
+  asection *xs, *ys;
+
+  x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
+  y =  bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
+  if (x == NULL || y == NULL)
+    bfd_fatal (bfd_get_filename (sort_bfd));
+
+  xs = bfd_get_section (x);
+  ys = bfd_get_section (y);
+
+  if (bfd_is_und_section (xs))
+    {
+      if (! bfd_is_und_section (ys))
+       return -1;
+    }
+  else if (bfd_is_und_section (ys))
+    return 1;
+  else if (valueof (x) != valueof (y))
+    return valueof (x) < valueof (y) ? -1 : 1;
+
+  return non_numeric_forward (P_x, P_y);
 }
 
-int
+static int
 numeric_reverse (x, y)
-     CONST void *x;
-     CONST void *y;
+     const PTR x;
+     const PTR y;
 {
-  return (valueof (*(asymbol **) y) - valueof (*(asymbol **) x));
+  return - numeric_forward (x, y);
 }
 
-int
-non_numeric_forward (x, y)
-     CONST void *x;
-     CONST void *y;
+static int
+non_numeric_forward (P_x, P_y)
+     const PTR P_x;
+     const PTR P_y;
 {
-  CONST char *xn = (*(asymbol **) x)->name;
-  CONST char *yn = (*(asymbol **) y)->name;
+  asymbol *x, *y;
+  const char *xn, *yn;
+
+  x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
+  y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
+  if (x == NULL || y == NULL)
+    bfd_fatal (bfd_get_filename (sort_bfd));
+
+  xn = bfd_asymbol_name (x);
+  yn = bfd_asymbol_name (y);
 
   return ((xn == NULL) ? ((yn == NULL) ? 0 : -1) :
          ((yn == NULL) ? 1 : strcmp (xn, yn)));
 }
 
-int
+static int
 non_numeric_reverse (x, y)
-     CONST void *x;
-     CONST void *y;
+     const PTR x;
+     const PTR y;
 {
-  return -(non_numeric_forward (x, y));
+  return - non_numeric_forward (x, y);
 }
 
-static int (*(sorters[2][2])) PARAMS ((CONST void *, CONST void *)) =
+static int (*(sorters[2][2])) PARAMS ((const PTR, const PTR)) =
 {
   { non_numeric_forward, non_numeric_reverse },
   { numeric_forward, numeric_reverse }
 };
+
+/* This sort routine is used by sort_symbols_by_size.  It is similar
+   to numeric_forward, but when symbols have the same value it sorts
+   by section VMA.  This simplifies the sort_symbols_by_size code
+   which handles symbols at the end of sections.  Also, this routine
+   tries to sort file names before other symbols with the same value.
+   That will make the file name have a zero size, which will make
+   sort_symbols_by_size choose the non file name symbol, leading to
+   more meaningful output.  For similar reasons, this code sorts
+   gnu_compiled_* and gcc2_compiled before other symbols with the same
+   value.  */
+
+static int
+size_forward1 (P_x, P_y)
+     const PTR P_x;
+     const PTR P_y;
+{
+  asymbol *x, *y;
+  asection *xs, *ys;
+  const char *xn, *yn;
+  size_t xnl, ynl;
+  int xf, yf;
+
+  x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
+  y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
+  if (x == NULL || y == NULL)
+    bfd_fatal (bfd_get_filename (sort_bfd));
+
+  xs = bfd_get_section (x);
+  ys = bfd_get_section (y);
+
+  if (bfd_is_und_section (xs))
+    abort ();
+  if (bfd_is_und_section (ys))
+    abort ();
+
+  if (valueof (x) != valueof (y))
+    return valueof (x) < valueof (y) ? -1 : 1;
+
+  if (xs->vma != ys->vma)
+    return xs->vma < ys->vma ? -1 : 1;
+
+  xn = bfd_asymbol_name (x);
+  yn = bfd_asymbol_name (y);
+  xnl = strlen (xn);
+  ynl = strlen (yn);
+
+  /* The symbols gnu_compiled and gcc2_compiled convey even less
+     information than the file name, so sort them out first.  */
+
+  xf = (strstr (xn, "gnu_compiled") != NULL
+       || strstr (xn, "gcc2_compiled") != NULL);
+  yf = (strstr (yn, "gnu_compiled") != NULL
+       || strstr (yn, "gcc2_compiled") != NULL);
+
+  if (xf && ! yf)
+    return -1;
+  if (! xf && yf)
+    return 1;
+
+  /* We use a heuristic for the file name.  It may not work on non
+     Unix systems, but it doesn't really matter; the only difference
+     is precisely which symbol names get printed.  */
+
+#define file_symbol(s, sn, snl)                        \
+  (((s)->flags & BSF_FILE) != 0                        \
+   || ((sn)[(snl) - 2] == '.'                  \
+       && ((sn)[(snl) - 1] == 'o'              \
+          || (sn)[(snl) - 1] == 'a')))
+
+  xf = file_symbol (x, xn, xnl);
+  yf = file_symbol (y, yn, ynl);
+
+  if (xf && ! yf)
+    return -1;
+  if (! xf && yf)
+    return 1;
+
+  return non_numeric_forward (P_x, P_y);
+}
+
+/* This sort routine is used by sort_symbols_by_size.  It is sorting
+   an array of size_sym structures into size order.  */
+
+static int
+size_forward2 (P_x, P_y)
+     const PTR P_x;
+     const PTR P_y;
+{
+  const struct size_sym *x = (const struct size_sym *) P_x;
+  const struct size_sym *y = (const struct size_sym *) P_y;
+
+  if (x->size < y->size)
+    return reverse_sort ? 1 : -1;
+  else if (x->size > y->size)
+    return reverse_sort ? -1 : 1;
+  else
+    return sorters[0][reverse_sort] (x->minisym, y->minisym);
+}
+
+/* Sort the symbols by size.  We guess the size by assuming that the
+   difference between the address of a symbol and the address of the
+   next higher symbol is the size.  FIXME: ELF actually stores a size
+   with each symbol.  We should use it.  */
+
+static long
+sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
+     bfd *abfd;
+     boolean dynamic;
+     PTR minisyms;
+     long symcount;
+     unsigned int size;
+     struct size_sym **symsizesp;
+{
+  struct size_sym *symsizes;
+  bfd_byte *from, *fromend;
+  asymbol *sym;
+  asymbol *store_sym, *store_next;
+
+  qsort (minisyms, symcount, size, size_forward1);
+
+  /* We are going to return a special set of symbols and sizes to
+     print.  */
+  symsizes = (struct size_sym *) xmalloc (symcount * sizeof (struct size_sym));
+  *symsizesp = symsizes;
+
+  /* Note that filter_symbols has already removed all absolute and
+     undefined symbols.  Here we remove all symbols whose size winds
+     up as zero.  */
+
+  from = (bfd_byte *) minisyms;
+  fromend = from + symcount * size;
+
+  store_sym = sort_x;
+  store_next = sort_y;
+
+  if (from < fromend)
+    {
+      sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from,
+                                     store_sym);
+      if (sym == NULL)
+       bfd_fatal (bfd_get_filename (abfd));
+    }
+
+  for (; from < fromend; from += size)
+    {
+      asymbol *next;
+      asection *sec;
+      bfd_vma sz;
+      asymbol *temp;
+
+      if (from + size < fromend)
+       {
+         next = bfd_minisymbol_to_symbol (abfd,
+                                          dynamic,
+                                          (const PTR) (from + size),
+                                          store_next);
+         if (next == NULL)
+           bfd_fatal (bfd_get_filename (abfd));
+       }
+
+      sec = bfd_get_section (sym);
+
+      if (bfd_is_com_section (sec))
+       sz = sym->value;
+      else
+       {
+         if (from + size < fromend
+             && sec == bfd_get_section (next))
+           sz = valueof (next) - valueof (sym);
+         else
+           sz = (bfd_get_section_vma (abfd, sec)
+                 + bfd_section_size (abfd, sec)
+                 - valueof (sym));
+       }
+
+      if (sz != 0)
+       {
+         symsizes->minisym = (const PTR) from;
+         symsizes->size = sz;
+         ++symsizes;
+       }
+
+      sym = next;
+
+      temp = store_sym;
+      store_sym = store_next;
+      store_next = temp;
+    }
+
+  symcount = symsizes - *symsizesp;
+
+  /* We must now sort again by size.  */
+  qsort ((PTR) *symsizesp, symcount, sizeof (struct size_sym), size_forward2);
+
+  return symcount;
+}
 \f
 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD.  */
 
@@ -505,86 +834,124 @@ display_rel_file (abfd, archive_bfd)
      bfd *abfd;
      bfd *archive_bfd;
 {
-  unsigned int storage;
-  asymbol **syms;
-  unsigned int symcount = 0;
-
-  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
-    {
-      printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
-      return;
-    }
+  long symcount;
+  PTR minisyms;
+  unsigned int size;
+  struct size_sym *symsizes;
 
-  storage = get_symtab_upper_bound (abfd);
-  if (storage == 0)
+  if (! dynamic)
     {
-    nosymz:
-      fprintf (stderr, "%s: Symflags set but there are none?\n",
-              bfd_get_filename (abfd));
-      return;
+      if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
+       {
+         printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
+         return;
+       }
     }
 
-  syms = (asymbol **) xmalloc (storage);
+  symcount = bfd_read_minisymbols (abfd, dynamic, &minisyms, &size);
+  if (symcount < 0)
+    bfd_fatal (bfd_get_filename (abfd));
 
-  symcount = bfd_canonicalize_symtab (abfd, syms);
   if (symcount == 0)
     {
-      free (syms);
-      goto nosymz;
+      fprintf (stderr, "%s: no symbols\n", bfd_get_filename (abfd));
+      return;
     }
 
   /* Discard the symbols we don't want to print.
      It's OK to do this in place; we'll free the storage anyway
      (after printing).  */
 
-  symcount = filter_symbols (abfd, syms, symcount);
+  symcount = filter_symbols (abfd, dynamic, minisyms, symcount, size);
 
-  if (!no_sort)
-    qsort ((char *) syms, symcount, sizeof (asymbol *),
-          sorters[sort_numerically][reverse_sort]);
+  symsizes = NULL;
+  if (! no_sort)
+    {
+      sort_bfd = abfd;
+      sort_dynamic = dynamic;
+      sort_x = bfd_make_empty_symbol (abfd);
+      sort_y = bfd_make_empty_symbol (abfd);
+      if (sort_x == NULL || sort_y == NULL)
+       bfd_fatal (bfd_get_filename (abfd));
+
+      if (! sort_by_size)
+       qsort (minisyms, symcount, size,
+              sorters[sort_numerically][reverse_sort]);
+      else
+       symcount = sort_symbols_by_size (abfd, dynamic, minisyms, symcount,
+                                        size, &symsizes);
+    }
 
-  print_symbols (abfd, syms, symcount, archive_bfd);
-  free (syms);
+  if (! sort_by_size)
+    print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd);
+  else
+    print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd);
+
+  free (minisyms);
 }
 \f
 /* Choose which symbol entries to print;
    compact them downward to get rid of the rest.
    Return the number of symbols to be printed.  */
 
-static unsigned int
-filter_symbols (abfd, syms, symcount)
-     bfd *abfd;                        /* Unused.  */
-     asymbol **syms;
-     unsigned long symcount;
+static long
+filter_symbols (abfd, dynamic, minisyms, symcount, size)
+     bfd *abfd;
+     boolean dynamic;
+     PTR minisyms;
+     long symcount;
+     unsigned int size;
 {
-  asymbol **from, **to;
-  unsigned int src_count;
-  unsigned int dst_count = 0;
-  asymbol *sym;
+  bfd_byte *from, *fromend, *to;
+  asymbol *store;
+
+  store = bfd_make_empty_symbol (abfd);
+  if (store == NULL)
+    bfd_fatal (bfd_get_filename (abfd));
+
+  from = (bfd_byte *) minisyms;
+  fromend = from + symcount * size;
+  to = (bfd_byte *) minisyms;
 
-  for (from = to = syms, src_count = 0; src_count < symcount; src_count++)
+  for (; from < fromend; from += size)
     {
       int keep = 0;
-      flagword flags = (from[src_count])->flags;
+      asymbol *sym;
+
+      PROGRESS (1);
+      
+      sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from, store);
+      if (sym == NULL)
+       bfd_fatal (bfd_get_filename (abfd));
 
-      sym = from[src_count];
       if (undefined_only)
-       keep = sym->section == &bfd_und_section;
+       keep = bfd_is_und_section (sym->section);
       else if (external_only)
-       keep = ((flags & BSF_GLOBAL)
-               || (sym->section == &bfd_und_section)
-               || (bfd_is_com_section (sym->section)));
+       keep = ((sym->flags & BSF_GLOBAL) != 0
+               || bfd_is_und_section (sym->section)
+               || bfd_is_com_section (sym->section));
       else
        keep = 1;
 
-      if (!print_debug_syms && ((flags & BSF_DEBUGGING) != 0))
+      if (keep
+         && ! print_debug_syms
+         && (sym->flags & BSF_DEBUGGING) != 0)
+       keep = 0;
+
+      if (keep
+         && sort_by_size
+         && (bfd_is_abs_section (sym->section)
+             || bfd_is_und_section (sym->section)))
        keep = 0;
 
       if (keep)
-       to[dst_count++] = from[src_count];
+       {
+         memcpy (to, from, size);
+         to += size;
+       }
     }
 
-  return dst_count;
+  return (to - (bfd_byte *) minisyms) / size;
 }
 \f
 /* Print symbol name NAME, read from ABFD, with printf format FORMAT,
@@ -595,7 +962,7 @@ print_symname (format, name, abfd)
      char *format, *name;
      bfd *abfd;
 {
-  if (do_demangle)
+  if (do_demangle && *name)
     {
       char *res;
 
@@ -617,39 +984,98 @@ print_symname (format, name, abfd)
   printf (format, name);
 }
 
-/* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD.  */
+/* Print the symbols.  If ARCHIVE_BFD is non-NULL, it is the archive
+   containing ABFD.  */
 
 static void
-print_symbols (abfd, syms, symcount, archive_bfd)
+print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd)
      bfd *abfd;
-     asymbol **syms;
-     unsigned long symcount;
+     boolean dynamic;
+     PTR minisyms;
+     long symcount;
+     unsigned int size;
      bfd *archive_bfd;
 {
-  asymbol **sym = syms, **end = syms + symcount;
-  symbol_info syminfo;
+  asymbol *store;
+  bfd_byte *from, *fromend;
+
+  store = bfd_make_empty_symbol (abfd);
+  if (store == NULL)
+    bfd_fatal (bfd_get_filename (abfd));
 
-  for (; sym < end; ++sym)
+  from = (bfd_byte *) minisyms;
+  fromend = from + symcount * size;
+  for (; from < fromend; from += size)
     {
-      (*format->print_symbol_filename) (archive_bfd, abfd);
+      asymbol *sym;
 
-      if (undefined_only)
-       {
-         if ((*sym)->section == &bfd_und_section)
-           {
-             print_symname ("%s\n", (*sym)->name, abfd);
-           }
-       }
-      else
-       {
-         asymbol *p = *sym;
-         if (p)
-           {
-             bfd_get_symbol_info (abfd, p, &syminfo);
-             (*format->print_symbol_info) (&syminfo, abfd);
-             putchar ('\n');
-           }
-       }
+      sym = bfd_minisymbol_to_symbol (abfd, dynamic, from, store);
+      if (sym == NULL)
+       bfd_fatal (bfd_get_filename (abfd));
+
+      print_symbol (abfd, sym, archive_bfd);
+    }
+}
+
+/* Print the symbols when sorting by size.  */
+
+static void 
+print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd)
+     bfd *abfd;
+     boolean dynamic;
+     struct size_sym *symsizes;
+     long symcount;
+     bfd *archive_bfd;
+{
+  asymbol *store;
+  struct size_sym *from, *fromend;
+
+  store = bfd_make_empty_symbol (abfd);
+  if (store == NULL)
+    bfd_fatal (bfd_get_filename (abfd));
+
+  from = symsizes;
+  fromend = from + symcount;
+  for (; from < fromend; from++)
+    {
+      asymbol *sym;
+
+      sym = bfd_minisymbol_to_symbol (abfd, dynamic, from->minisym, store);
+      if (sym == NULL)
+       bfd_fatal (bfd_get_filename (abfd));
+
+      /* Set the symbol value so that we actually display the symbol
+         size.  */
+      sym->value = from->size - bfd_section_vma (abfd, bfd_get_section (sym));
+
+      print_symbol (abfd, sym, archive_bfd);
+    }
+}
+
+/* Print a single symbol.  */
+
+static void
+print_symbol (abfd, sym, archive_bfd)
+     bfd *abfd;
+     asymbol *sym;
+     bfd *archive_bfd;
+{
+  PROGRESS (1);
+
+  (*format->print_symbol_filename) (archive_bfd, abfd);
+
+  if (undefined_only)
+    {
+      if (bfd_is_und_section (bfd_get_section (sym)))
+       print_symname ("%s\n", bfd_asymbol_name (sym), abfd);
+    }
+  else
+    {
+      symbol_info syminfo;
+
+      bfd_get_symbol_info (abfd, sym, &syminfo);
+      (*format->print_symbol_info) (&syminfo, abfd);
+      putchar ('\n');
     }
 }
 \f
@@ -785,6 +1211,37 @@ print_symbol_filename_posix (archive_bfd, abfd)
     }
 }
 \f
+/* Print a symbol value.  */
+
+static void
+print_value (val)
+     bfd_vma val;
+{
+#if ! defined (BFD64) || BFD_HOST_64BIT_LONG
+  printf (value_format, val);
+#else
+  /* We have a 64 bit value to print, but the host is only 32 bit.  */
+  if (print_radix == 16)
+    fprintf_vma (stdout, val);
+  else
+    {
+      char buf[30];
+      char *s;
+
+      s = buf + sizeof buf;
+      *--s = '\0';
+      while (val > 0)
+       {
+         *--s = (val % print_radix) + '0';
+         val /= print_radix;
+       }
+      while ((buf + sizeof buf - 1) - s < 16)
+       *--s = '0';
+      printf ("%s", s);
+    }
+#endif
+}
+
 /* Print a line of information about a symbol.  */
 
 static void
@@ -793,16 +1250,17 @@ print_symbol_info_bsd (info, abfd)
      bfd *abfd;
 {
   if (info->type == 'U')
-    printf ("        ");
-  else
     {
-#ifdef HOST_64_BIT
-      printf (value_format, uint64_typeHIGH (info->value),
-             uint64_typeLOW (info->value));
+      printf ("%*s",
+#ifdef BFD64
+             16,
 #else
-      printf (value_format, info->value);
+             8,
 #endif
+             "");
     }
+  else
+    print_value (info->value);
   printf (" %c", info->type);
   if (info->type == '-')
     {
@@ -825,14 +1283,7 @@ print_symbol_info_sysv (info, abfd)
   if (info->type == 'U')
     printf ("        ");       /* Value */
   else
-    {
-#ifdef HOST_64_BIT
-      printf (value_format, uint64_typeHIGH (info->value),
-             uint64_typeLOW (info->value));
-#else
-      printf (value_format, info->value);
-#endif
-    }
+    print_value (info->value);
   printf ("|   %c  |", info->type);    /* Class */
   if (info->type == '-')
     {
@@ -855,14 +1306,7 @@ print_symbol_info_posix (info, abfd)
   if (info->type == 'U')
     printf ("        ");
   else
-    {
-#ifdef HOST_64_BIT
-      printf (value_format, uint64_typeHIGH (info->value),
-             uint64_typeLOW (info->value));
-#else
-      printf (value_format, info->value);
-#endif
-    }
+    print_value (info->value);
   /* POSIX.2 wants the symbol size printed here, when applicable;
      BFD currently doesn't provide it, so we take the easy way out by
      considering it to never be applicable.  */
@@ -887,9 +1331,12 @@ print_symdef_entry (abfd)
          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)
        {
-         printf ("%s in %s\n", thesym->name, bfd_get_filename (elt));
+         print_symname ("%s", thesym->name, abfd);
+         printf (" in %s\n", bfd_get_filename (elt));
        }
     }
 }
This page took 0.032315 seconds and 4 git commands to generate.