* bucomm.c: Replace CONST with const.
[deliverable/binutils-gdb.git] / binutils / nm.c
index e6cc368e815d8fa7d8f8823cb54931fa9c3ccc05..589c4e8400b6d6e0f62123e436e4f35d7ed3baa6 100644 (file)
@@ -1,6 +1,6 @@
 /* nm.c -- Describe symbol table of a rel file.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001
+   2001, 2002
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
@@ -28,6 +28,7 @@
 #include "aout/ranlib.h"
 #include "demangle.h"
 #include "libiberty.h"
+#include "elf-bfd.h"
 
 /* When sorting by size, we use this structure to hold the size and a
    pointer to the minisymbol.  */
@@ -132,13 +133,13 @@ print_archive_filename_posix PARAMS ((char *filename));
 
 
 static void
-print_archive_member_bsd PARAMS ((char *archive, CONST char *filename));
+print_archive_member_bsd PARAMS ((char *archive, const char *filename));
 
 static void
-print_archive_member_sysv PARAMS ((char *archive, CONST char *filename));
+print_archive_member_sysv PARAMS ((char *archive, const char *filename));
 
 static void
-print_archive_member_posix PARAMS ((char *archive, CONST char *filename));
+print_archive_member_posix PARAMS ((char *archive, const char *filename));
 
 
 static void
@@ -176,7 +177,7 @@ struct output_fns
     void (*print_archive_filename) PARAMS ((char *filename));
 
     /* Print the name of an archive member file.  */
-    void (*print_archive_member) PARAMS ((char *archive, CONST char *filename));
+    void (*print_archive_member) PARAMS ((char *archive, const char *filename));
 
     /* Print the name of the file (and archive, if there is one)
        containing a symbol.  */
@@ -297,9 +298,9 @@ usage (stream, status)
      FILE *stream;
      int status;
 {
-  fprintf (stream, _("Usage: %s [OPTION]... [FILE]...\n"), program_name);
-  fprintf (stream, _("List symbols from FILEs (a.out by default).\n"));
-  fprintf (stream, _("\n\
+  fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name);
+  fprintf (stream, _(" List symbols in [file(s)] (a.out by default).\n"));
+  fprintf (stream, _(" The options are:\n\
   -a, --debug-syms       Display debugger-only symbols\n\
   -A, --print-file-name  Print name of the input file before every symbol\n\
   -B                     Same as --format=bsd\n\
@@ -313,7 +314,6 @@ usage (stream, status)
   -f, --format=FORMAT    Use the output format FORMAT.  FORMAT can be `bsd',\n\
                            `sysv' or `posix'.  The default is `bsd'\n\
   -g, --extern-only      Display only external symbols\n\
-  -h, --help             Display this information\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\
@@ -326,8 +326,9 @@ usage (stream, status)
   -t, --radix=RADIX      Use RADIX for printing symbol values\n\
       --target=BFDNAME   Specify the target object format as BFDNAME\n\
   -u, --undefined-only   Display only undefined symbols\n\
-  -V, --version          Display this program's version number\n\
   -X 32_64               (ignored)\n\
+  -h, --help             Display this information\n\
+  -V, --version          Display this program's version number\n\
 \n"));
   list_supported_targets (program_name, stream);
   if (status == 0)
@@ -394,6 +395,8 @@ set_output_format (f)
   format = &formats[i];
 }
 \f
+int main PARAMS ((int, char **));
+
 int
 main (argc, argv)
      int argc;
@@ -419,7 +422,7 @@ main (argc, argv)
   bfd_init ();
   set_default_bfd_target ();
 
-  while ((c = getopt_long (argc, argv, "aABCDef:glnopPrst:uvVX:",
+  while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrst:uvVvX:",
                           long_options, (int *) 0)) != EOF)
     {
       switch (c)
@@ -439,14 +442,14 @@ main (argc, argv)
          if (optarg != NULL)
            {
              enum demangling_styles style;
-             
+
              style = cplus_demangle_name_to_style (optarg);
-             if (style == unknown_demangling) 
+             if (style == unknown_demangling)
                fatal (_("unknown demangling style `%s'"),
                       optarg);
-             
+
              cplus_demangle_set_style (style);
-           }
+           }
          break;
        case 'D':
          dynamic = 1;
@@ -460,6 +463,7 @@ main (argc, argv)
        case 'g':
          external_only = 1;
          break;
+       case 'H':
        case 'h':
          usage (stdout, 0);
        case 'l':
@@ -836,10 +840,10 @@ size_forward2 (P_x, P_y)
     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.  */
+/* Sort the symbols by size.  ELF provides a size but for other formats
+   we have to make a guess by assuming that the difference between the
+   address of a symbol and the address of the next higher symbol is the
+   size.  */
 
 static long
 sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
@@ -901,7 +905,9 @@ sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
 
       sec = bfd_get_section (sym);
 
-      if (bfd_is_com_section (sec))
+      if (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))
        sz = sym->value;
       else
        {
@@ -1032,7 +1038,7 @@ filter_symbols (abfd, dynamic, minisyms, symcount, size)
       asymbol *sym;
 
       PROGRESS (1);
-      
+
       sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from, store);
       if (sym == NULL)
        bfd_fatal (bfd_get_filename (abfd));
@@ -1141,7 +1147,7 @@ print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd)
 
 /* Print the symbols when sorting by size.  */
 
-static void 
+static void
 print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd)
      bfd *abfd;
      boolean dynamic;
@@ -1288,7 +1294,8 @@ print_symbol (abfd, sym, archive_bfd)
                                 bfd_asymbol_name (*r->sym_ptr_ptr)) == 0
                      && bfd_find_nearest_line (abfd, secs[i], syms,
                                                r->address, &filename,
-                                               &functionname, &lineno))
+                                               &functionname, &lineno)
+                     && filename != NULL)
                    {
                      /* We only print the first one we find.  */
                      printf ("\t%s:%u", filename, lineno);
@@ -1377,7 +1384,7 @@ print_archive_filename_posix (filename)
 static void
 print_archive_member_bsd (archive, filename)
      char *archive ATTRIBUTE_UNUSED;
-     CONST char *filename;
+     const char *filename;
 {
   if (!filename_per_symbol)
     printf ("\n%s:\n", filename);
@@ -1386,7 +1393,7 @@ print_archive_member_bsd (archive, filename)
 static void
 print_archive_member_sysv (archive, filename)
      char *archive;
-     CONST char *filename;
+     const char *filename;
 {
   if (undefined_only)
     printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename);
@@ -1399,7 +1406,7 @@ Name                  Value   Class        Type         Size   Line  Section\n\n
 static void
 print_archive_member_posix (archive, filename)
      char *archive;
-     CONST char *filename;
+     const char *filename;
 {
   if (!filename_per_symbol)
     printf ("%s[%s]:\n", archive, filename);
@@ -1450,7 +1457,7 @@ print_symbol_filename_posix (archive_bfd, abfd)
 
 static void
 print_value (abfd, val)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      bfd_vma val;
 {
 #if ! defined (BFD64) || BFD_HOST_64BIT_LONG
This page took 0.027716 seconds and 4 git commands to generate.