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