* mpw-config.in: New file, MPW configure fragment for binutils.
[deliverable/binutils-gdb.git] / binutils / nm.c
index 6580e7b6992dec2f512e0c2f7fa183b6388c3111..1be15cdb14ef0073d9f79a455311d38a2129c547 100644 (file)
@@ -152,6 +152,7 @@ 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 undefined_only = 0; /* print undefined symbols only */
+static int dynamic = 0;                /* print dynamic symbols.  */
 static int show_version = 0;   /* show the version number */
 
 /* When to print the names of files.  Not mutually exclusive in SYSV format.  */
@@ -159,7 +160,7 @@ 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
+#ifdef BFD_HOST_64_BIT
 static char value_format[] = "%08x%08x";
 #else
 static char value_format[] = "%08lx";
@@ -178,9 +179,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'},
@@ -202,11 +206,12 @@ 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",
+       [--demangle] [--no-demangle] [--dynamic] [--version] [--help]\n\
+       [file...]\n",
           program_name);
   exit (status);
 }
@@ -222,7 +227,7 @@ set_print_radix (radix)
     case 'd':
     case 'o':
     case 'x':
-#ifdef HOST_64_BIT
+#ifdef BFD_HOST_64_BIT
       value_format[3] = value_format[7] = *radix;
 #else
       value_format[4] = *radix;
@@ -271,10 +276,11 @@ main (argc, argv)
   int retval;
 
   program_name = *argv;
+  xmalloc_set_program_name (program_name);
 
   bfd_init ();
 
-  while ((c = getopt_long (argc, argv, "aABCf:gnopPrst:uvV", long_options, (int *) 0)) != EOF)
+  while ((c = getopt_long (argc, argv, "aABCDf:gnopPrst:uvV", long_options, (int *) 0)) != EOF)
     {
       switch (c)
        {
@@ -291,6 +297,9 @@ main (argc, argv)
        case 'C':
          do_demangle = 1;
          break;
+       case 'D':
+         dynamic = 1;
+         break;
        case 'f':
          set_output_format (optarg);
          break;
@@ -368,6 +377,7 @@ display_archive (file)
      bfd *file;
 {
   bfd *arfile = NULL;
+  bfd *last_arfile = NULL;
   char **matching;
 
   (*format->print_archive_filename) (bfd_get_filename (file));
@@ -381,7 +391,7 @@ display_archive (file)
 
       if (arfile == NULL)
        {
-         if (bfd_error != no_more_archived_files)
+         if (bfd_get_error () != bfd_error_no_more_archived_files)
            bfd_fatal (bfd_get_filename (file));
          break;
        }
@@ -395,13 +405,20 @@ display_archive (file)
       else
        {
          bfd_nonfatal (bfd_get_filename (arfile));
-         if (bfd_error == file_ambiguously_recognized)
+         if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
            {
              list_matching_formats (matching);
              free (matching);
            }
        }
+
+      if (last_arfile != NULL)
+       bfd_close (last_arfile);
+      last_arfile = arfile;
     }
+
+  if (last_arfile != NULL)
+    bfd_close (last_arfile);
 }
 
 static boolean
@@ -431,7 +448,7 @@ display_file (filename)
   else
     {
       bfd_nonfatal (filename);
-      if (bfd_error == file_ambiguously_recognized)
+      if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
        {
          list_matching_formats (matching);
          free (matching);
@@ -496,28 +513,53 @@ display_rel_file (abfd, archive_bfd)
      bfd *abfd;
      bfd *archive_bfd;
 {
-  unsigned int storage;
+  long storage;
   asymbol **syms;
-  unsigned int symcount = 0;
+  long symcount = 0;
 
-  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
+  if (dynamic)
     {
-      printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
-      return;
+      if (!(bfd_get_file_flags (abfd) & DYNAMIC))
+       {
+         printf ("\"%s\" is not a dynamic object.\n",
+                 bfd_get_filename (abfd));
+         return;
+       }
+    }
+  else
+    {
+      if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
+       {
+         printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
+         return;
+       }
     }
 
-  storage = get_symtab_upper_bound (abfd);
+  if (dynamic)
+    storage = bfd_get_dynamic_symtab_upper_bound (abfd);
+  else
+    storage = bfd_get_symtab_upper_bound (abfd);
+  if (storage < 0)
+    bfd_fatal (bfd_get_filename (abfd));
   if (storage == 0)
     {
     nosymz:
-      fprintf (stderr, "%s: Symflags set but there are none?\n",
-              bfd_get_filename (abfd));
+      if (dynamic)
+       fprintf (stderr, "%s: no symbols\n", bfd_get_filename (abfd));
+      else
+       fprintf (stderr, "%s: Symflags set but there are none?\n",
+                bfd_get_filename (abfd));
       return;
     }
 
   syms = (asymbol **) xmalloc (storage);
 
-  symcount = bfd_canonicalize_symtab (abfd, syms);
+  if (dynamic)
+    symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);
+  else
+    symcount = bfd_canonicalize_symtab (abfd, syms);
+  if (symcount < 0)
+    bfd_fatal (bfd_get_filename (abfd));
   if (symcount == 0)
     {
       free (syms);
@@ -787,7 +829,7 @@ print_symbol_info_bsd (info, abfd)
     printf ("        ");
   else
     {
-#ifdef HOST_64_BIT
+#ifdef BFD_HOST_64_BIT
       printf (value_format, uint64_typeHIGH (info->value),
              uint64_typeLOW (info->value));
 #else
@@ -817,7 +859,7 @@ print_symbol_info_sysv (info, abfd)
     printf ("        ");       /* Value */
   else
     {
-#ifdef HOST_64_BIT
+#ifdef BFD_HOST_64_BIT
       printf (value_format, uint64_typeHIGH (info->value),
              uint64_typeLOW (info->value));
 #else
@@ -847,7 +889,7 @@ print_symbol_info_posix (info, abfd)
     printf ("        ");
   else
     {
-#ifdef HOST_64_BIT
+#ifdef BFD_HOST_64_BIT
       printf (value_format, uint64_typeHIGH (info->value),
              uint64_typeLOW (info->value));
 #else
This page took 0.025016 seconds and 4 git commands to generate.