* nlmconv.c (main), objcopy.c (copy_file): Print matching formats
[external/binutils.git] / binutils / nm.c
1 /* nm.c -- Describe symbol table of a rel file.
2    Copyright 1991, 92, 93, 94 Free Software Foundation, Inc.
3
4    This file is part of GNU Binutils.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include "bfd.h"
21 #include "sysdep.h"
22 #include "bucomm.h"
23 #include "getopt.h"
24 #include "aout/stab_gnu.h"
25 #include "aout/ranlib.h"
26 #include "demangle.h"
27
28 static boolean
29 display_file PARAMS ((char *filename));
30
31 static void
32 display_rel_file PARAMS ((bfd * file, bfd * archive));
33
34 static unsigned int
35 filter_symbols PARAMS ((bfd * file, asymbol ** syms, unsigned long symcount));
36
37 static void
38 print_symbols PARAMS ((bfd * file, asymbol ** syms, unsigned long symcount,
39                        bfd * archive));
40
41 static void
42 print_symdef_entry PARAMS ((bfd * abfd));
43
44
45 /* The output formatting functions.  */
46
47 static void
48 print_object_filename_bsd PARAMS ((char *filename));
49
50 static void
51 print_object_filename_sysv PARAMS ((char *filename));
52
53 static void
54 print_object_filename_posix PARAMS ((char *filename));
55
56
57 static void
58 print_archive_filename_bsd PARAMS ((char *filename));
59
60 static void
61 print_archive_filename_sysv PARAMS ((char *filename));
62
63 static void
64 print_archive_filename_posix PARAMS ((char *filename));
65
66
67 static void
68 print_archive_member_bsd PARAMS ((char *archive, CONST char *filename));
69
70 static void
71 print_archive_member_sysv PARAMS ((char *archive, CONST char *filename));
72
73 static void
74 print_archive_member_posix PARAMS ((char *archive, CONST char *filename));
75
76
77 static void
78 print_symbol_filename_bsd PARAMS ((bfd * archive_bfd, bfd * abfd));
79
80 static void
81 print_symbol_filename_sysv PARAMS ((bfd * archive_bfd, bfd * abfd));
82
83 static void
84 print_symbol_filename_posix PARAMS ((bfd * archive_bfd, bfd * abfd));
85
86
87 static void
88 print_symbol_info_bsd PARAMS ((symbol_info * info, bfd * abfd));
89
90 static void
91 print_symbol_info_sysv PARAMS ((symbol_info * info, bfd * abfd));
92
93 static void
94 print_symbol_info_posix PARAMS ((symbol_info * info, bfd * abfd));
95
96
97 /* Support for different output formats.  */
98 struct output_fns
99   {
100     /* Print the name of an object file given on the command line.  */
101     void (*print_object_filename) PARAMS ((char *filename));
102
103     /* Print the name of an archive file given on the command line.  */
104     void (*print_archive_filename) PARAMS ((char *filename));
105
106     /* Print the name of an archive member file.  */
107     void (*print_archive_member) PARAMS ((char *archive, CONST char *filename));
108
109     /* Print the name of the file (and archive, if there is one)
110        containing a symbol.  */
111     void (*print_symbol_filename) PARAMS ((bfd * archive_bfd, bfd * abfd));
112
113     /* Print a line of information about a symbol.  */
114     void (*print_symbol_info) PARAMS ((symbol_info * info, bfd * abfd));
115   };
116 static struct output_fns formats[] =
117 {
118   {print_object_filename_bsd,
119    print_archive_filename_bsd,
120    print_archive_member_bsd,
121    print_symbol_filename_bsd,
122    print_symbol_info_bsd},
123   {print_object_filename_sysv,
124    print_archive_filename_sysv,
125    print_archive_member_sysv,
126    print_symbol_filename_sysv,
127    print_symbol_info_sysv},
128   {print_object_filename_posix,
129    print_archive_filename_posix,
130    print_archive_member_posix,
131    print_symbol_filename_posix,
132    print_symbol_info_posix}
133 };
134
135 /* Indices in `formats'.  */
136 #define FORMAT_BSD 0
137 #define FORMAT_SYSV 1
138 #define FORMAT_POSIX 2
139 #define FORMAT_DEFAULT FORMAT_BSD
140
141 /* The output format to use.  */
142 static struct output_fns *format = &formats[FORMAT_DEFAULT];
143
144
145 /* Command options.  */
146
147 static int do_demangle = 0;     /* Pretty print C++ symbol names.  */
148 static int external_only = 0;   /* print external symbols only */
149 static int no_sort = 0;         /* don't sort; print syms in order found */
150 static int print_debug_syms = 0;        /* print debugger-only symbols too */
151 static int print_armap = 0;     /* describe __.SYMDEF data in archive files.  */
152 static int reverse_sort = 0;    /* sort in downward(alpha or numeric) order */
153 static int sort_numerically = 0;        /* sort in numeric rather than alpha order */
154 static int undefined_only = 0;  /* print undefined symbols only */
155 static int show_version = 0;    /* show the version number */
156
157 /* When to print the names of files.  Not mutually exclusive in SYSV format.  */
158 static int filename_per_file = 0;       /* Once per file, on its own line.  */
159 static int filename_per_symbol = 0;     /* Once per symbol, at start of line.  */
160
161 /* Print formats for printing a symbol value.  */
162 #ifdef  HOST_64_BIT
163 static char value_format[] = "%08x%08x";
164 #else
165 static char value_format[] = "%08lx";
166 #endif
167 /* Print formats for printing stab info.  */
168 static char other_format[] = "%02x";
169 static char desc_format[] = "%04x";
170
171 /* IMPORT */
172 extern char *program_name;
173 extern char *program_version;
174 extern char *target;
175 extern int print_version;
176
177 static struct option long_options[] =
178 {
179   {"debug-syms", no_argument, &print_debug_syms, 1},
180   {"demangle", no_argument, &do_demangle, 1},
181   {"extern-only", no_argument, &external_only, 1},
182   {"format", required_argument, 0, 'f'},
183   {"help", no_argument, 0, 'h'},
184   {"no-sort", no_argument, &no_sort, 1},
185   {"numeric-sort", no_argument, &sort_numerically, 1},
186   {"portability", no_argument, 0, 'P'},
187   {"print-armap", no_argument, &print_armap, 1},
188   {"print-file-name", no_argument, 0, 'o'},
189   {"radix", required_argument, 0, 't'},
190   {"reverse-sort", no_argument, &reverse_sort, 1},
191   {"target", required_argument, 0, 200},
192   {"undefined-only", no_argument, &undefined_only, 1},
193   {"version", no_argument, &show_version, 1},
194   {0, no_argument, 0, 0}
195 };
196 \f
197 /* Some error-reporting functions */
198
199 void
200 usage (stream, status)
201      FILE *stream;
202      int status;
203 {
204   fprintf (stream, "\
205 Usage: %s [-aABCgnopPrsuvV] [-t radix] [--radix=radix] [--target=bfdname]\n\
206        [--debug-syms] [--extern-only] [--print-armap] [--print-file-name]\n\
207        [--numeric-sort] [--no-sort] [--reverse-sort] [--undefined-only]\n\
208        [--portability] [-f {bsd,sysv,posix}] [--format={bsd,sysv,posix}]\n\
209        [--demangle] [--version] [--help] [file...]\n",
210            program_name);
211   exit (status);
212 }
213
214 /* Set the radix for the symbol value and size according to RADIX.  */
215
216 void
217 set_print_radix (radix)
218      char *radix;
219 {
220   switch (*radix)
221     {
222     case 'd':
223     case 'o':
224     case 'x':
225 #ifdef  HOST_64_BIT
226       value_format[3] = value_format[7] = *radix;
227 #else
228       value_format[4] = *radix;
229 #endif
230       other_format[3] = desc_format[3] = *radix;
231       break;
232     default:
233       fprintf (stderr, "%s: %s: invalid radix\n", program_name, radix);
234       exit (1);
235     }
236 }
237
238 void
239 set_output_format (f)
240      char *f;
241 {
242   int i;
243
244   switch (*f)
245     {
246     case 'b':
247     case 'B':
248       i = FORMAT_BSD;
249       break;
250     case 'p':
251     case 'P':
252       i = FORMAT_POSIX;
253       break;
254     case 's':
255     case 'S':
256       i = FORMAT_SYSV;
257       break;
258     default:
259       fprintf (stderr, "%s: %s: invalid output format\n", program_name, f);
260       exit (1);
261     }
262   format = &formats[i];
263 }
264 \f
265 int
266 main (argc, argv)
267      int argc;
268      char **argv;
269 {
270   int c;
271   int retval;
272
273   program_name = *argv;
274
275   bfd_init ();
276
277   while ((c = getopt_long (argc, argv, "aABCf:gnopPrst:uvV", long_options, (int *) 0)) != EOF)
278     {
279       switch (c)
280         {
281         case 'a':
282           print_debug_syms = 1;
283           break;
284         case 'A':
285         case 'o':
286           filename_per_symbol = 1;
287           break;
288         case 'B':               /* For MIPS compatibility.  */
289           set_output_format ("bsd");
290           break;
291         case 'C':
292           do_demangle = 1;
293           break;
294         case 'f':
295           set_output_format (optarg);
296           break;
297         case 'g':
298           external_only = 1;
299           break;
300         case 'h':
301           usage (stdout, 0);
302         case 'n':
303         case 'v':
304           sort_numerically = 1;
305           break;
306         case 'p':
307           no_sort = 1;
308           break;
309         case 'P':
310           set_output_format ("posix");
311           break;
312         case 'r':
313           reverse_sort = 1;
314           break;
315         case 's':
316           print_armap = 1;
317           break;
318         case 't':
319           set_print_radix (optarg);
320           break;
321         case 'u':
322           undefined_only = 1;
323           break;
324         case 'V':
325           show_version = 1;
326           break;
327
328         case 200:               /* --target */
329           target = optarg;
330           break;
331
332         case 0:         /* A long option that just sets a flag.  */
333           break;
334
335         default:
336           usage (stderr, 1);
337         }
338     }
339
340   if (show_version)
341     {
342       printf ("GNU %s version %s\n", program_name, program_version);
343       exit (0);
344     }
345
346   /* OK, all options now parsed.  If no filename specified, do a.out.  */
347   if (optind == argc)
348     return !display_file ("a.out");
349
350   retval = 0;
351
352   if (argc - optind > 1)
353     filename_per_file = 1;
354
355   /* We were given several filenames to do.  */
356   while (optind < argc)
357     {
358       if (!display_file (argv[optind++]))
359         retval++;
360     }
361
362   exit (retval);
363   return retval;
364 }
365 \f
366 static void
367 display_archive (file)
368      bfd *file;
369 {
370   bfd *arfile = NULL;
371
372   (*format->print_archive_filename) (bfd_get_filename (file));
373
374   if (print_armap)
375     print_symdef_entry (file);
376
377   for (;;)
378     {
379       arfile = bfd_openr_next_archived_file (file, arfile);
380
381       if (arfile == NULL)
382         {
383           if (bfd_error != no_more_archived_files)
384             bfd_fatal (bfd_get_filename (file));
385           break;
386         }
387
388       if (bfd_check_format (arfile, bfd_object))
389         {
390           (*format->print_archive_member) (bfd_get_filename (file),
391                                            bfd_get_filename (arfile));
392           display_rel_file (arfile, file);
393         }
394       else
395         printf ("%s: not an object file\n", arfile->filename);
396     }
397 }
398
399 static boolean
400 display_file (filename)
401      char *filename;
402 {
403   boolean retval = true;
404   bfd *file;
405   char **matching;
406
407   file = bfd_openr (filename, target);
408   if (file == NULL)
409     {
410       bfd_nonfatal (filename);
411       return false;
412     }
413
414   if (bfd_check_format (file, bfd_archive))
415     {
416       display_archive (file);
417     }
418   else if (bfd_check_format_matches (file, bfd_object, &matching))
419     {
420       (*format->print_object_filename) (filename);
421       display_rel_file (file, NULL);
422     }
423   else
424     {
425       bfd_nonfatal (filename);
426       if (bfd_error == file_ambiguously_recognized)
427         {
428           list_matching_formats (matching);
429           free (matching);
430         }
431       retval = false;
432     }
433
434   if (bfd_close (file) == false)
435     bfd_fatal (filename);
436
437   return retval;
438 }
439 \f
440 /* Symbol-sorting predicates */
441 #define valueof(x) ((x)->section->vma + (x)->value)
442 int
443 numeric_forward (x, y)
444      CONST void *x;
445      CONST void *y;
446 {
447   return (valueof (*(asymbol **) x) - valueof (*(asymbol **) y));
448 }
449
450 int
451 numeric_reverse (x, y)
452      CONST void *x;
453      CONST void *y;
454 {
455   return (valueof (*(asymbol **) y) - valueof (*(asymbol **) x));
456 }
457
458 int
459 non_numeric_forward (x, y)
460      CONST void *x;
461      CONST void *y;
462 {
463   CONST char *xn = (*(asymbol **) x)->name;
464   CONST char *yn = (*(asymbol **) y)->name;
465
466   return ((xn == NULL) ? ((yn == NULL) ? 0 : -1) :
467           ((yn == NULL) ? 1 : strcmp (xn, yn)));
468 }
469
470 int
471 non_numeric_reverse (x, y)
472      CONST void *x;
473      CONST void *y;
474 {
475   return -(non_numeric_forward (x, y));
476 }
477
478 static int (*(sorters[2][2])) PARAMS ((CONST void *, CONST void *)) =
479 {
480   { non_numeric_forward, non_numeric_reverse },
481   { numeric_forward, numeric_reverse }
482 };
483 \f
484 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD.  */
485
486 static void
487 display_rel_file (abfd, archive_bfd)
488      bfd *abfd;
489      bfd *archive_bfd;
490 {
491   unsigned int storage;
492   asymbol **syms;
493   unsigned int symcount = 0;
494
495   if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
496     {
497       printf ("No symbols in \"%s\".\n", bfd_get_filename (abfd));
498       return;
499     }
500
501   storage = get_symtab_upper_bound (abfd);
502   if (storage == 0)
503     {
504     nosymz:
505       fprintf (stderr, "%s: Symflags set but there are none?\n",
506                bfd_get_filename (abfd));
507       return;
508     }
509
510   syms = (asymbol **) xmalloc (storage);
511
512   symcount = bfd_canonicalize_symtab (abfd, syms);
513   if (symcount == 0)
514     {
515       free (syms);
516       goto nosymz;
517     }
518
519   /* Discard the symbols we don't want to print.
520      It's OK to do this in place; we'll free the storage anyway
521      (after printing).  */
522
523   symcount = filter_symbols (abfd, syms, symcount);
524
525   if (!no_sort)
526     qsort ((char *) syms, symcount, sizeof (asymbol *),
527            sorters[sort_numerically][reverse_sort]);
528
529   print_symbols (abfd, syms, symcount, archive_bfd);
530   free (syms);
531 }
532 \f
533 /* Choose which symbol entries to print;
534    compact them downward to get rid of the rest.
535    Return the number of symbols to be printed.  */
536
537 static unsigned int
538 filter_symbols (abfd, syms, symcount)
539      bfd *abfd;                 /* Unused.  */
540      asymbol **syms;
541      unsigned long symcount;
542 {
543   asymbol **from, **to;
544   unsigned int src_count;
545   unsigned int dst_count = 0;
546   asymbol *sym;
547
548   for (from = to = syms, src_count = 0; src_count < symcount; src_count++)
549     {
550       int keep = 0;
551       flagword flags = (from[src_count])->flags;
552
553       sym = from[src_count];
554       if (undefined_only)
555         keep = sym->section == &bfd_und_section;
556       else if (external_only)
557         keep = ((flags & BSF_GLOBAL)
558                 || (sym->section == &bfd_und_section)
559                 || (bfd_is_com_section (sym->section)));
560       else
561         keep = 1;
562
563       if (!print_debug_syms && ((flags & BSF_DEBUGGING) != 0))
564         keep = 0;
565
566       if (keep)
567         to[dst_count++] = from[src_count];
568     }
569
570   return dst_count;
571 }
572 \f
573 /* Print symbol name NAME, read from ABFD, with printf format FORMAT,
574    demangling it if requested.  */
575
576 static void
577 print_symname (format, name, abfd)
578      char *format, *name;
579      bfd *abfd;
580 {
581   if (do_demangle)
582     {
583       char *res;
584
585       /* In this mode, give a user-level view of the symbol name
586          even if it's not mangled; strip off any leading
587          underscore.  */
588       if (bfd_get_symbol_leading_char (abfd) == name[0])
589         name++;
590
591       res = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
592       if (res)
593         {
594           printf (format, res);
595           free (res);
596           return;
597         }
598     }
599
600   printf (format, name);
601 }
602
603 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD.  */
604
605 static void
606 print_symbols (abfd, syms, symcount, archive_bfd)
607      bfd *abfd;
608      asymbol **syms;
609      unsigned long symcount;
610      bfd *archive_bfd;
611 {
612   asymbol **sym = syms, **end = syms + symcount;
613   symbol_info syminfo;
614
615   for (; sym < end; ++sym)
616     {
617       (*format->print_symbol_filename) (archive_bfd, abfd);
618
619       if (undefined_only)
620         {
621           if ((*sym)->section == &bfd_und_section)
622             {
623               print_symname ("%s\n", (*sym)->name, abfd);
624             }
625         }
626       else
627         {
628           asymbol *p = *sym;
629           if (p)
630             {
631               bfd_get_symbol_info (abfd, p, &syminfo);
632               (*format->print_symbol_info) (&syminfo, abfd);
633               putchar ('\n');
634             }
635         }
636     }
637 }
638 \f
639 /* The following 3 groups of functions are called unconditionally,
640    once at the start of processing each file of the appropriate type.
641    They should check `filename_per_file' and `filename_per_symbol',
642    as appropriate for their output format, to determine whether to
643    print anything.  */
644 \f
645 /* Print the name of an object file given on the command line.  */
646
647 static void
648 print_object_filename_bsd (filename)
649      char *filename;
650 {
651   if (filename_per_file && !filename_per_symbol)
652     printf ("\n%s:\n", filename);
653 }
654
655 static void
656 print_object_filename_sysv (filename)
657      char *filename;
658 {
659   if (undefined_only)
660     printf ("\n\nUndefined symbols from %s:\n\n", filename);
661   else
662     printf ("\n\nSymbols from %s:\n\n", filename);
663   printf ("\
664 Name                  Value   Class        Type         Size   Line  Section\n\n");
665 }
666
667 static void
668 print_object_filename_posix (filename)
669      char *filename;
670 {
671   if (filename_per_file && !filename_per_symbol)
672     printf ("%s:\n", filename);
673 }
674 \f
675 /* Print the name of an archive file given on the command line.  */
676
677 static void
678 print_archive_filename_bsd (filename)
679      char *filename;
680 {
681   if (filename_per_file)
682     printf ("\n%s:\n", filename);
683 }
684
685 static void
686 print_archive_filename_sysv (filename)
687      char *filename;
688 {
689 }
690
691 static void
692 print_archive_filename_posix (filename)
693      char *filename;
694 {
695 }
696 \f
697 /* Print the name of an archive member file.  */
698
699 static void
700 print_archive_member_bsd (archive, filename)
701      char *archive;
702      CONST char *filename;
703 {
704   if (!filename_per_symbol)
705     printf ("\n%s:\n", filename);
706 }
707
708 static void
709 print_archive_member_sysv (archive, filename)
710      char *archive;
711      CONST char *filename;
712 {
713   if (undefined_only)
714     printf ("\n\nUndefined symbols from %s[%s]:\n\n", archive, filename);
715   else
716     printf ("\n\nSymbols from %s[%s]:\n\n", archive, filename);
717   printf ("\
718 Name                  Value   Class        Type         Size   Line  Section\n\n");
719 }
720
721 static void
722 print_archive_member_posix (archive, filename)
723      char *archive;
724      CONST char *filename;
725 {
726   if (!filename_per_symbol)
727     printf ("%s[%s]:\n", archive, filename);
728 }
729 \f
730 /* Print the name of the file (and archive, if there is one)
731    containing a symbol.  */
732
733 static void
734 print_symbol_filename_bsd (archive_bfd, abfd)
735      bfd *archive_bfd, *abfd;
736 {
737   if (filename_per_symbol)
738     {
739       if (archive_bfd)
740         printf ("%s:", bfd_get_filename (archive_bfd));
741       printf ("%s:", bfd_get_filename (abfd));
742     }
743 }
744
745 static void
746 print_symbol_filename_sysv (archive_bfd, abfd)
747      bfd *archive_bfd, *abfd;
748 {
749   if (filename_per_symbol)
750     {
751       if (archive_bfd)
752         printf ("%s:", bfd_get_filename (archive_bfd));
753       printf ("%s:", bfd_get_filename (abfd));
754     }
755 }
756
757 static void
758 print_symbol_filename_posix (archive_bfd, abfd)
759      bfd *archive_bfd, *abfd;
760 {
761   if (filename_per_symbol)
762     {
763       if (archive_bfd)
764         printf ("%s[%s]: ", bfd_get_filename (archive_bfd),
765                 bfd_get_filename (abfd));
766       else
767         printf ("%s: ", bfd_get_filename (abfd));
768     }
769 }
770 \f
771 /* Print a line of information about a symbol.  */
772
773 static void
774 print_symbol_info_bsd (info, abfd)
775      symbol_info *info;
776      bfd *abfd;
777 {
778   if (info->type == 'U')
779     printf ("        ");
780   else
781     {
782 #ifdef HOST_64_BIT
783       printf (value_format, uint64_typeHIGH (info->value),
784               uint64_typeLOW (info->value));
785 #else
786       printf (value_format, info->value);
787 #endif
788     }
789   printf (" %c", info->type);
790   if (info->type == '-')
791     {
792       /* A stab.  */
793       printf (" ");
794       printf (other_format, info->stab_other);
795       printf (" ");
796       printf (desc_format, info->stab_desc);
797       printf (" %5s", info->stab_name);
798     }
799   print_symname (" %s", info->name, abfd);
800 }
801
802 static void
803 print_symbol_info_sysv (info, abfd)
804      symbol_info *info;
805      bfd *abfd;
806 {
807   print_symname ("%-20s|", info->name, abfd);   /* Name */
808   if (info->type == 'U')
809     printf ("        ");        /* Value */
810   else
811     {
812 #ifdef HOST_64_BIT
813       printf (value_format, uint64_typeHIGH (info->value),
814               uint64_typeLOW (info->value));
815 #else
816       printf (value_format, info->value);
817 #endif
818     }
819   printf ("|   %c  |", info->type);     /* Class */
820   if (info->type == '-')
821     {
822       /* A stab.  */
823       printf ("%18s|  ", info->stab_name);      /* (C) Type */
824       printf (desc_format, info->stab_desc);    /* Size */
825       printf ("|     |");       /* Line, Section */
826     }
827   else
828     printf ("                  |      |     |");        /* Type, Size, Line, Section */
829 }
830
831 static void
832 print_symbol_info_posix (info, abfd)
833      symbol_info *info;
834      bfd *abfd;
835 {
836   print_symname ("%s ", info->name, abfd);
837   printf ("%c ", info->type);
838   if (info->type == 'U')
839     printf ("        ");
840   else
841     {
842 #ifdef HOST_64_BIT
843       printf (value_format, uint64_typeHIGH (info->value),
844               uint64_typeLOW (info->value));
845 #else
846       printf (value_format, info->value);
847 #endif
848     }
849   /* POSIX.2 wants the symbol size printed here, when applicable;
850      BFD currently doesn't provide it, so we take the easy way out by
851      considering it to never be applicable.  */
852 }
853 \f
854 static void
855 print_symdef_entry (abfd)
856      bfd *abfd;
857 {
858   symindex idx = BFD_NO_MORE_SYMBOLS;
859   carsym *thesym;
860   boolean everprinted = false;
861
862   for (idx = bfd_get_next_mapent (abfd, idx, &thesym);
863        idx != BFD_NO_MORE_SYMBOLS;
864        idx = bfd_get_next_mapent (abfd, idx, &thesym))
865     {
866       bfd *elt;
867       if (!everprinted)
868         {
869           printf ("\nArchive index:\n");
870           everprinted = true;
871         }
872       elt = bfd_get_elt_at_index (abfd, idx);
873       if (thesym->name != (char *) NULL)
874         {
875           printf ("%s in %s\n", thesym->name, bfd_get_filename (elt));
876         }
877     }
878 }