1 /* nm.c -- Describe symbol table of a rel file.
2 Copyright 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "aout/stab_gnu.h"
25 #include "aout/ranlib.h"
27 #include "libiberty.h"
29 /* When sorting by size, we use this structure to hold the size and a
30 pointer to the minisymbol. */
38 /* When fetching relocs, we use this structure to pass information to
41 struct get_relocs_info
50 usage PARAMS ((FILE *, int));
53 set_print_radix PARAMS ((char *));
56 set_output_format PARAMS ((char *));
59 display_archive PARAMS ((bfd *));
62 display_file PARAMS ((char *filename));
65 display_rel_file PARAMS ((bfd * file, bfd * archive));
68 filter_symbols PARAMS ((bfd *, boolean, PTR, long, unsigned int));
71 sort_symbols_by_size PARAMS ((bfd *, boolean, PTR, long, unsigned int,
75 print_symbols PARAMS ((bfd *, boolean, PTR, long, unsigned int, bfd *));
78 print_size_symbols PARAMS ((bfd *, boolean, struct size_sym *, long, bfd *));
81 print_symname PARAMS ((const char *, const char *, bfd *));
84 print_symbol PARAMS ((bfd *, asymbol *, bfd *));
87 print_symdef_entry PARAMS ((bfd * abfd));
89 /* The sorting functions. */
92 numeric_forward PARAMS ((const PTR, const PTR));
95 numeric_reverse PARAMS ((const PTR, const PTR));
98 non_numeric_forward PARAMS ((const PTR, const PTR));
101 non_numeric_reverse PARAMS ((const PTR, const PTR));
104 size_forward1 PARAMS ((const PTR, const PTR));
107 size_forward2 PARAMS ((const PTR, const PTR));
109 /* The output formatting functions. */
112 print_object_filename_bsd PARAMS ((char *filename));
115 print_object_filename_sysv PARAMS ((char *filename));
118 print_object_filename_posix PARAMS ((char *filename));
122 print_archive_filename_bsd PARAMS ((char *filename));
125 print_archive_filename_sysv PARAMS ((char *filename));
128 print_archive_filename_posix PARAMS ((char *filename));
132 print_archive_member_bsd PARAMS ((char *archive, CONST char *filename));
135 print_archive_member_sysv PARAMS ((char *archive, CONST char *filename));
138 print_archive_member_posix PARAMS ((char *archive, CONST char *filename));
142 print_symbol_filename_bsd PARAMS ((bfd * archive_bfd, bfd * abfd));
145 print_symbol_filename_sysv PARAMS ((bfd * archive_bfd, bfd * abfd));
148 print_symbol_filename_posix PARAMS ((bfd * archive_bfd, bfd * abfd));
152 print_value PARAMS ((bfd_vma));
155 print_symbol_info_bsd PARAMS ((symbol_info * info, bfd * abfd));
158 print_symbol_info_sysv PARAMS ((symbol_info * info, bfd * abfd));
161 print_symbol_info_posix PARAMS ((symbol_info * info, bfd * abfd));
164 get_relocs PARAMS ((bfd *, asection *, PTR));
166 /* Support for different output formats. */
169 /* Print the name of an object file given on the command line. */
170 void (*print_object_filename) PARAMS ((char *filename));
172 /* Print the name of an archive file given on the command line. */
173 void (*print_archive_filename) PARAMS ((char *filename));
175 /* Print the name of an archive member file. */
176 void (*print_archive_member) PARAMS ((char *archive, CONST char *filename));
178 /* Print the name of the file (and archive, if there is one)
179 containing a symbol. */
180 void (*print_symbol_filename) PARAMS ((bfd * archive_bfd, bfd * abfd));
182 /* Print a line of information about a symbol. */
183 void (*print_symbol_info) PARAMS ((symbol_info * info, bfd * abfd));
185 static struct output_fns formats[] =
187 {print_object_filename_bsd,
188 print_archive_filename_bsd,
189 print_archive_member_bsd,
190 print_symbol_filename_bsd,
191 print_symbol_info_bsd},
192 {print_object_filename_sysv,
193 print_archive_filename_sysv,
194 print_archive_member_sysv,
195 print_symbol_filename_sysv,
196 print_symbol_info_sysv},
197 {print_object_filename_posix,
198 print_archive_filename_posix,
199 print_archive_member_posix,
200 print_symbol_filename_posix,
201 print_symbol_info_posix}
204 /* Indices in `formats'. */
206 #define FORMAT_SYSV 1
207 #define FORMAT_POSIX 2
208 #define FORMAT_DEFAULT FORMAT_BSD
210 /* The output format to use. */
211 static struct output_fns *format = &formats[FORMAT_DEFAULT];
214 /* Command options. */
216 static int do_demangle = 0; /* Pretty print C++ symbol names. */
217 static int external_only = 0; /* print external symbols only */
218 static int defined_only = 0; /* Print defined symbols only */
219 static int no_sort = 0; /* don't sort; print syms in order found */
220 static int print_debug_syms = 0; /* print debugger-only symbols too */
221 static int print_armap = 0; /* describe __.SYMDEF data in archive files. */
222 static int reverse_sort = 0; /* sort in downward(alpha or numeric) order */
223 static int sort_numerically = 0; /* sort in numeric rather than alpha order */
224 static int sort_by_size = 0; /* sort by size of symbol */
225 static int undefined_only = 0; /* print undefined symbols only */
226 static int dynamic = 0; /* print dynamic symbols. */
227 static int show_version = 0; /* show the version number */
228 static int show_stats = 0; /* show statistics */
229 static int line_numbers = 0; /* print line numbers for symbols */
231 /* When to print the names of files. Not mutually exclusive in SYSV format. */
232 static int filename_per_file = 0; /* Once per file, on its own line. */
233 static int filename_per_symbol = 0; /* Once per symbol, at start of line. */
235 /* Print formats for printing a symbol value. */
237 static char value_format[] = "%08lx";
239 #if BFD_HOST_64BIT_LONG
240 static char value_format[] = "%016lx";
242 /* We don't use value_format for this case. */
245 static int print_radix = 16;
246 /* Print formats for printing stab info. */
247 static char other_format[] = "%02x";
248 static char desc_format[] = "%04x";
250 static char *target = NULL;
252 /* Used to cache the line numbers for a BFD. */
253 static bfd *lineno_cache_bfd;
254 static bfd *lineno_cache_rel_bfd;
256 static struct option long_options[] =
258 {"debug-syms", no_argument, &print_debug_syms, 1},
259 {"demangle", no_argument, &do_demangle, 1},
260 {"dynamic", no_argument, &dynamic, 1},
261 {"extern-only", no_argument, &external_only, 1},
262 {"format", required_argument, 0, 'f'},
263 {"help", no_argument, 0, 'h'},
264 {"line-numbers", no_argument, 0, 'l'},
265 {"no-cplus", no_argument, &do_demangle, 0}, /* Linux compatibility. */
266 {"no-demangle", no_argument, &do_demangle, 0},
267 {"no-sort", no_argument, &no_sort, 1},
268 {"numeric-sort", no_argument, &sort_numerically, 1},
269 {"portability", no_argument, 0, 'P'},
270 {"print-armap", no_argument, &print_armap, 1},
271 {"print-file-name", no_argument, 0, 'o'},
272 {"radix", required_argument, 0, 't'},
273 {"reverse-sort", no_argument, &reverse_sort, 1},
274 {"size-sort", no_argument, &sort_by_size, 1},
275 {"stats", no_argument, &show_stats, 1},
276 {"target", required_argument, 0, 200},
277 {"defined-only", no_argument, &defined_only, 1},
278 {"undefined-only", no_argument, &undefined_only, 1},
279 {"version", no_argument, &show_version, 1},
280 {0, no_argument, 0, 0}
283 /* Some error-reporting functions */
286 usage (stream, status)
290 fprintf (stream, _("\
291 Usage: %s [-aABCDglnopPrsuvV] [-t radix] [--radix=radix] [--target=bfdname]\n\
292 [--debug-syms] [--extern-only] [--print-armap] [--print-file-name]\n\
293 [--numeric-sort] [--no-sort] [--reverse-sort] [--size-sort]\n\
294 [--undefined-only] [--portability] [-f {bsd,sysv,posix}]\n\
295 [--format={bsd,sysv,posix}] [--demangle] [--no-demangle] [--dynamic]\n\
296 [--defined-only] [--line-numbers]\n\
297 [--version] [--help]\n\
300 list_supported_targets (program_name, stream);
302 fprintf (stream, _("Report bugs to bug-gnu-utils@gnu.org\n"));
306 /* Set the radix for the symbol value and size according to RADIX. */
309 set_print_radix (radix)
323 value_format[4] = *radix;
325 #if BFD_HOST_64BIT_LONG
326 value_format[5] = *radix;
328 /* This case requires special handling for octal and decimal
332 other_format[3] = desc_format[3] = *radix;
335 fprintf (stderr, _("%s: %s: invalid radix\n"), program_name, radix);
341 set_output_format (f)
361 fprintf (stderr, _("%s: %s: invalid output format\n"), program_name, f);
364 format = &formats[i];
375 program_name = *argv;
376 xmalloc_set_program_name (program_name);
378 START_PROGRESS (program_name, 0);
381 set_default_bfd_target ();
383 while ((c = getopt_long (argc, argv, "aABCDef:glnopPrst:uvV", long_options, (int *) 0)) != EOF)
388 print_debug_syms = 1;
392 filename_per_symbol = 1;
394 case 'B': /* For MIPS compatibility. */
395 set_output_format ("bsd");
404 /* Ignored for HP/UX compatibility. */
407 set_output_format (optarg);
419 sort_numerically = 1;
425 set_output_format ("posix");
434 set_print_radix (optarg);
443 case 200: /* --target */
447 case 0: /* A long option that just sets a flag. */
456 print_version ("nm");
458 /* OK, all options now parsed. If no filename specified, do a.out. */
460 return !display_file ("a.out");
464 if (argc - optind > 1)
465 filename_per_file = 1;
467 /* We were given several filenames to do. */
468 while (optind < argc)
471 if (!display_file (argv[optind++]))
475 END_PROGRESS (program_name);
480 extern char **environ;
481 char *lim = (char *) sbrk (0);
483 fprintf (stderr, _("%s: data size %ld\n"), program_name,
484 (long) (lim - (char *) &environ));
493 display_archive (file)
497 bfd *last_arfile = NULL;
500 (*format->print_archive_filename) (bfd_get_filename (file));
503 print_symdef_entry (file);
509 arfile = bfd_openr_next_archived_file (file, arfile);
513 if (bfd_get_error () != bfd_error_no_more_archived_files)
514 bfd_fatal (bfd_get_filename (file));
518 if (bfd_check_format_matches (arfile, bfd_object, &matching))
520 (*format->print_archive_member) (bfd_get_filename (file),
521 bfd_get_filename (arfile));
522 display_rel_file (arfile, file);
526 bfd_nonfatal (bfd_get_filename (arfile));
527 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
529 list_matching_formats (matching);
534 if (last_arfile != NULL)
536 bfd_close (last_arfile);
537 lineno_cache_bfd = NULL;
538 lineno_cache_rel_bfd = NULL;
540 last_arfile = arfile;
543 if (last_arfile != NULL)
545 bfd_close (last_arfile);
546 lineno_cache_bfd = NULL;
547 lineno_cache_rel_bfd = NULL;
552 display_file (filename)
555 boolean retval = true;
559 file = bfd_openr (filename, target);
562 bfd_nonfatal (filename);
566 if (bfd_check_format (file, bfd_archive))
568 display_archive (file);
570 else if (bfd_check_format_matches (file, bfd_object, &matching))
572 (*format->print_object_filename) (filename);
573 display_rel_file (file, NULL);
577 bfd_nonfatal (filename);
578 if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
580 list_matching_formats (matching);
586 if (bfd_close (file) == false)
587 bfd_fatal (filename);
589 lineno_cache_bfd = NULL;
590 lineno_cache_rel_bfd = NULL;
595 /* These globals are used to pass information into the sorting
597 static bfd *sort_bfd;
598 static boolean sort_dynamic;
599 static asymbol *sort_x;
600 static asymbol *sort_y;
602 /* Symbol-sorting predicates */
603 #define valueof(x) ((x)->section->vma + (x)->value)
605 /* Numeric sorts. Undefined symbols are always considered "less than"
606 defined symbols with zero values. Common symbols are not treated
607 specially -- i.e., their sizes are used as their "values". */
610 numeric_forward (P_x, P_y)
617 x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
618 y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
619 if (x == NULL || y == NULL)
620 bfd_fatal (bfd_get_filename (sort_bfd));
622 xs = bfd_get_section (x);
623 ys = bfd_get_section (y);
625 if (bfd_is_und_section (xs))
627 if (! bfd_is_und_section (ys))
630 else if (bfd_is_und_section (ys))
632 else if (valueof (x) != valueof (y))
633 return valueof (x) < valueof (y) ? -1 : 1;
635 return non_numeric_forward (P_x, P_y);
639 numeric_reverse (x, y)
643 return - numeric_forward (x, y);
647 non_numeric_forward (P_x, P_y)
654 x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
655 y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
656 if (x == NULL || y == NULL)
657 bfd_fatal (bfd_get_filename (sort_bfd));
659 xn = bfd_asymbol_name (x);
660 yn = bfd_asymbol_name (y);
662 return ((xn == NULL) ? ((yn == NULL) ? 0 : -1) :
663 ((yn == NULL) ? 1 : strcmp (xn, yn)));
667 non_numeric_reverse (x, y)
671 return - non_numeric_forward (x, y);
674 static int (*(sorters[2][2])) PARAMS ((const PTR, const PTR)) =
676 { non_numeric_forward, non_numeric_reverse },
677 { numeric_forward, numeric_reverse }
680 /* This sort routine is used by sort_symbols_by_size. It is similar
681 to numeric_forward, but when symbols have the same value it sorts
682 by section VMA. This simplifies the sort_symbols_by_size code
683 which handles symbols at the end of sections. Also, this routine
684 tries to sort file names before other symbols with the same value.
685 That will make the file name have a zero size, which will make
686 sort_symbols_by_size choose the non file name symbol, leading to
687 more meaningful output. For similar reasons, this code sorts
688 gnu_compiled_* and gcc2_compiled before other symbols with the same
692 size_forward1 (P_x, P_y)
702 x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
703 y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
704 if (x == NULL || y == NULL)
705 bfd_fatal (bfd_get_filename (sort_bfd));
707 xs = bfd_get_section (x);
708 ys = bfd_get_section (y);
710 if (bfd_is_und_section (xs))
712 if (bfd_is_und_section (ys))
715 if (valueof (x) != valueof (y))
716 return valueof (x) < valueof (y) ? -1 : 1;
718 if (xs->vma != ys->vma)
719 return xs->vma < ys->vma ? -1 : 1;
721 xn = bfd_asymbol_name (x);
722 yn = bfd_asymbol_name (y);
726 /* The symbols gnu_compiled and gcc2_compiled convey even less
727 information than the file name, so sort them out first. */
729 xf = (strstr (xn, "gnu_compiled") != NULL
730 || strstr (xn, "gcc2_compiled") != NULL);
731 yf = (strstr (yn, "gnu_compiled") != NULL
732 || strstr (yn, "gcc2_compiled") != NULL);
739 /* We use a heuristic for the file name. It may not work on non
740 Unix systems, but it doesn't really matter; the only difference
741 is precisely which symbol names get printed. */
743 #define file_symbol(s, sn, snl) \
744 (((s)->flags & BSF_FILE) != 0 \
745 || ((sn)[(snl) - 2] == '.' \
746 && ((sn)[(snl) - 1] == 'o' \
747 || (sn)[(snl) - 1] == 'a')))
749 xf = file_symbol (x, xn, xnl);
750 yf = file_symbol (y, yn, ynl);
757 return non_numeric_forward (P_x, P_y);
760 /* This sort routine is used by sort_symbols_by_size. It is sorting
761 an array of size_sym structures into size order. */
764 size_forward2 (P_x, P_y)
768 const struct size_sym *x = (const struct size_sym *) P_x;
769 const struct size_sym *y = (const struct size_sym *) P_y;
771 if (x->size < y->size)
772 return reverse_sort ? 1 : -1;
773 else if (x->size > y->size)
774 return reverse_sort ? -1 : 1;
776 return sorters[0][reverse_sort] (x->minisym, y->minisym);
779 /* Sort the symbols by size. We guess the size by assuming that the
780 difference between the address of a symbol and the address of the
781 next higher symbol is the size. FIXME: ELF actually stores a size
782 with each symbol. We should use it. */
785 sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
791 struct size_sym **symsizesp;
793 struct size_sym *symsizes;
794 bfd_byte *from, *fromend;
796 asymbol *store_sym, *store_next;
798 qsort (minisyms, symcount, size, size_forward1);
800 /* We are going to return a special set of symbols and sizes to
802 symsizes = (struct size_sym *) xmalloc (symcount * sizeof (struct size_sym));
803 *symsizesp = symsizes;
805 /* Note that filter_symbols has already removed all absolute and
806 undefined symbols. Here we remove all symbols whose size winds
809 from = (bfd_byte *) minisyms;
810 fromend = from + symcount * size;
817 sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from,
820 bfd_fatal (bfd_get_filename (abfd));
823 for (; from < fromend; from += size)
830 if (from + size < fromend)
832 next = bfd_minisymbol_to_symbol (abfd,
834 (const PTR) (from + size),
837 bfd_fatal (bfd_get_filename (abfd));
842 sec = bfd_get_section (sym);
844 if (bfd_is_com_section (sec))
848 if (from + size < fromend
849 && sec == bfd_get_section (next))
850 sz = valueof (next) - valueof (sym);
852 sz = (bfd_get_section_vma (abfd, sec)
853 + bfd_section_size (abfd, sec)
859 symsizes->minisym = (const PTR) from;
867 store_sym = store_next;
871 symcount = symsizes - *symsizesp;
873 /* We must now sort again by size. */
874 qsort ((PTR) *symsizesp, symcount, sizeof (struct size_sym), size_forward2);
879 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */
882 display_rel_file (abfd, archive_bfd)
889 struct size_sym *symsizes;
893 if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
895 printf (_("No symbols in \"%s\".\n"), bfd_get_filename (abfd));
900 symcount = bfd_read_minisymbols (abfd, dynamic, &minisyms, &size);
902 bfd_fatal (bfd_get_filename (abfd));
906 fprintf (stderr, _("%s: no symbols\n"), bfd_get_filename (abfd));
910 /* Discard the symbols we don't want to print.
911 It's OK to do this in place; we'll free the storage anyway
914 symcount = filter_symbols (abfd, dynamic, minisyms, symcount, size);
920 sort_dynamic = dynamic;
921 sort_x = bfd_make_empty_symbol (abfd);
922 sort_y = bfd_make_empty_symbol (abfd);
923 if (sort_x == NULL || sort_y == NULL)
924 bfd_fatal (bfd_get_filename (abfd));
927 qsort (minisyms, symcount, size,
928 sorters[sort_numerically][reverse_sort]);
930 symcount = sort_symbols_by_size (abfd, dynamic, minisyms, symcount,
935 print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd);
937 print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd);
942 /* Choose which symbol entries to print;
943 compact them downward to get rid of the rest.
944 Return the number of symbols to be printed. */
947 filter_symbols (abfd, dynamic, minisyms, symcount, size)
954 bfd_byte *from, *fromend, *to;
957 store = bfd_make_empty_symbol (abfd);
959 bfd_fatal (bfd_get_filename (abfd));
961 from = (bfd_byte *) minisyms;
962 fromend = from + symcount * size;
963 to = (bfd_byte *) minisyms;
965 for (; from < fromend; from += size)
972 sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from, store);
974 bfd_fatal (bfd_get_filename (abfd));
977 keep = bfd_is_und_section (sym->section);
978 else if (external_only)
979 keep = ((sym->flags & BSF_GLOBAL) != 0
980 || (sym->flags & BSF_WEAK) != 0
981 || bfd_is_und_section (sym->section)
982 || bfd_is_com_section (sym->section));
987 && ! print_debug_syms
988 && (sym->flags & BSF_DEBUGGING) != 0)
993 && (bfd_is_abs_section (sym->section)
994 || bfd_is_und_section (sym->section)))
1000 if (bfd_is_und_section (sym->section))
1006 memcpy (to, from, size);
1011 return (to - (bfd_byte *) minisyms) / size;
1014 /* Print symbol name NAME, read from ABFD, with printf format FORMAT,
1015 demangling it if requested. */
1018 print_symname (format, name, abfd)
1023 if (do_demangle && *name)
1027 /* In this mode, give a user-level view of the symbol name
1028 even if it's not mangled; strip off any leading
1030 if (bfd_get_symbol_leading_char (abfd) == name[0])
1033 res = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS);
1036 printf (format, res);
1042 printf (format, name);
1045 /* Print the symbols. If ARCHIVE_BFD is non-NULL, it is the archive
1049 print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd)
1058 bfd_byte *from, *fromend;
1060 store = bfd_make_empty_symbol (abfd);
1062 bfd_fatal (bfd_get_filename (abfd));
1064 from = (bfd_byte *) minisyms;
1065 fromend = from + symcount * size;
1066 for (; from < fromend; from += size)
1070 sym = bfd_minisymbol_to_symbol (abfd, dynamic, from, store);
1072 bfd_fatal (bfd_get_filename (abfd));
1074 print_symbol (abfd, sym, archive_bfd);
1078 /* Print the symbols when sorting by size. */
1081 print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd)
1084 struct size_sym *symsizes;
1089 struct size_sym *from, *fromend;
1091 store = bfd_make_empty_symbol (abfd);
1093 bfd_fatal (bfd_get_filename (abfd));
1096 fromend = from + symcount;
1097 for (; from < fromend; from++)
1101 sym = bfd_minisymbol_to_symbol (abfd, dynamic, from->minisym, store);
1103 bfd_fatal (bfd_get_filename (abfd));
1105 /* Set the symbol value so that we actually display the symbol
1107 sym->value = from->size - bfd_section_vma (abfd, bfd_get_section (sym));
1109 print_symbol (abfd, sym, archive_bfd);
1113 /* Print a single symbol. */
1116 print_symbol (abfd, sym, archive_bfd)
1123 (*format->print_symbol_filename) (archive_bfd, abfd);
1127 if (bfd_is_und_section (bfd_get_section (sym)))
1128 print_symname ("%s", bfd_asymbol_name (sym), abfd);
1132 symbol_info syminfo;
1134 bfd_get_symbol_info (abfd, sym, &syminfo);
1135 (*format->print_symbol_info) (&syminfo, abfd);
1140 static asymbol **syms;
1141 static long symcount;
1142 const char *filename, *functionname;
1143 unsigned int lineno;
1145 /* We need to get the canonical symbols in order to call
1146 bfd_find_nearest_line. This is inefficient, but, then, you
1147 don't have to use --line-numbers. */
1148 if (abfd != lineno_cache_bfd && syms != NULL)
1157 symsize = bfd_get_symtab_upper_bound (abfd);
1159 bfd_fatal (bfd_get_filename (abfd));
1160 syms = (asymbol **) xmalloc (symsize);
1161 symcount = bfd_canonicalize_symtab (abfd, syms);
1163 bfd_fatal (bfd_get_filename (abfd));
1164 lineno_cache_bfd = abfd;
1167 if (bfd_is_und_section (bfd_get_section (sym)))
1169 static asection **secs;
1170 static arelent ***relocs;
1171 static long *relcount;
1172 static unsigned int seccount;
1174 const char *symname;
1176 /* For an undefined symbol, we try to find a reloc for the
1177 symbol, and print the line number of the reloc. */
1179 if (abfd != lineno_cache_rel_bfd && relocs != NULL)
1181 for (i = 0; i < seccount; i++)
1182 if (relocs[i] != NULL)
1194 struct get_relocs_info info;
1196 seccount = bfd_count_sections (abfd);
1198 secs = (asection **) xmalloc (seccount * sizeof *secs);
1199 relocs = (arelent ***) xmalloc (seccount * sizeof *relocs);
1200 relcount = (long *) xmalloc (seccount * sizeof *relcount);
1203 info.relocs = relocs;
1204 info.relcount = relcount;
1206 bfd_map_over_sections (abfd, get_relocs, (PTR) &info);
1207 lineno_cache_rel_bfd = abfd;
1210 symname = bfd_asymbol_name (sym);
1211 for (i = 0; i < seccount; i++)
1215 for (j = 0; j < relcount[i]; j++)
1220 if (r->sym_ptr_ptr != NULL
1221 && (*r->sym_ptr_ptr)->section == sym->section
1222 && (*r->sym_ptr_ptr)->value == sym->value
1224 bfd_asymbol_name (*r->sym_ptr_ptr)) == 0
1225 && bfd_find_nearest_line (abfd, secs[i], syms,
1226 r->address, &filename,
1227 &functionname, &lineno))
1229 /* We only print the first one we find. */
1230 printf ("\t%s:%u", filename, lineno);
1237 else if (bfd_get_section (sym)->owner == abfd)
1239 if (bfd_find_nearest_line (abfd, bfd_get_section (sym), syms,
1240 sym->value, &filename, &functionname,
1245 printf ("\t%s:%u", filename, lineno);
1253 /* The following 3 groups of functions are called unconditionally,
1254 once at the start of processing each file of the appropriate type.
1255 They should check `filename_per_file' and `filename_per_symbol',
1256 as appropriate for their output format, to determine whether to
1259 /* Print the name of an object file given on the command line. */
1262 print_object_filename_bsd (filename)
1265 if (filename_per_file && !filename_per_symbol)
1266 printf ("\n%s:\n", filename);
1270 print_object_filename_sysv (filename)
1274 printf (_("\n\nUndefined symbols from %s:\n\n"), filename);
1276 printf (_("\n\nSymbols from %s:\n\n"), filename);
1278 Name Value Class Type Size Line Section\n\n"));
1282 print_object_filename_posix (filename)
1285 if (filename_per_file && !filename_per_symbol)
1286 printf ("%s:\n", filename);
1289 /* Print the name of an archive file given on the command line. */
1292 print_archive_filename_bsd (filename)
1295 if (filename_per_file)
1296 printf ("\n%s:\n", filename);
1300 print_archive_filename_sysv (filename)
1306 print_archive_filename_posix (filename)
1311 /* Print the name of an archive member file. */
1314 print_archive_member_bsd (archive, filename)
1316 CONST char *filename;
1318 if (!filename_per_symbol)
1319 printf ("\n%s:\n", filename);
1323 print_archive_member_sysv (archive, filename)
1325 CONST char *filename;
1328 printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename);
1330 printf (_("\n\nSymbols from %s[%s]:\n\n"), archive, filename);
1332 Name Value Class Type Size Line Section\n\n"));
1336 print_archive_member_posix (archive, filename)
1338 CONST char *filename;
1340 if (!filename_per_symbol)
1341 printf ("%s[%s]:\n", archive, filename);
1344 /* Print the name of the file (and archive, if there is one)
1345 containing a symbol. */
1348 print_symbol_filename_bsd (archive_bfd, abfd)
1349 bfd *archive_bfd, *abfd;
1351 if (filename_per_symbol)
1354 printf ("%s:", bfd_get_filename (archive_bfd));
1355 printf ("%s:", bfd_get_filename (abfd));
1360 print_symbol_filename_sysv (archive_bfd, abfd)
1361 bfd *archive_bfd, *abfd;
1363 if (filename_per_symbol)
1366 printf ("%s:", bfd_get_filename (archive_bfd));
1367 printf ("%s:", bfd_get_filename (abfd));
1372 print_symbol_filename_posix (archive_bfd, abfd)
1373 bfd *archive_bfd, *abfd;
1375 if (filename_per_symbol)
1378 printf ("%s[%s]: ", bfd_get_filename (archive_bfd),
1379 bfd_get_filename (abfd));
1381 printf ("%s: ", bfd_get_filename (abfd));
1385 /* Print a symbol value. */
1391 #if ! defined (BFD64) || BFD_HOST_64BIT_LONG
1392 printf (value_format, val);
1394 /* We have a 64 bit value to print, but the host is only 32 bit. */
1395 if (print_radix == 16)
1396 fprintf_vma (stdout, val);
1402 s = buf + sizeof buf;
1406 *--s = (val % print_radix) + '0';
1409 while ((buf + sizeof buf - 1) - s < 16)
1416 /* Print a line of information about a symbol. */
1419 print_symbol_info_bsd (info, abfd)
1423 if (info->type == 'U')
1434 print_value (info->value);
1435 printf (" %c", info->type);
1436 if (info->type == '-')
1440 printf (other_format, info->stab_other);
1442 printf (desc_format, info->stab_desc);
1443 printf (" %5s", info->stab_name);
1445 print_symname (" %s", info->name, abfd);
1449 print_symbol_info_sysv (info, abfd)
1453 print_symname ("%-20s|", info->name, abfd); /* Name */
1454 if (info->type == 'U')
1455 printf (" "); /* Value */
1457 print_value (info->value);
1458 printf ("| %c |", info->type); /* Class */
1459 if (info->type == '-')
1462 printf ("%18s| ", info->stab_name); /* (C) Type */
1463 printf (desc_format, info->stab_desc); /* Size */
1464 printf ("| |"); /* Line, Section */
1467 printf (" | | |"); /* Type, Size, Line, Section */
1471 print_symbol_info_posix (info, abfd)
1475 print_symname ("%s ", info->name, abfd);
1476 printf ("%c ", info->type);
1477 if (info->type == 'U')
1480 print_value (info->value);
1481 /* POSIX.2 wants the symbol size printed here, when applicable;
1482 BFD currently doesn't provide it, so we take the easy way out by
1483 considering it to never be applicable. */
1487 print_symdef_entry (abfd)
1490 symindex idx = BFD_NO_MORE_SYMBOLS;
1492 boolean everprinted = false;
1494 for (idx = bfd_get_next_mapent (abfd, idx, &thesym);
1495 idx != BFD_NO_MORE_SYMBOLS;
1496 idx = bfd_get_next_mapent (abfd, idx, &thesym))
1501 printf (_("\nArchive index:\n"));
1504 elt = bfd_get_elt_at_index (abfd, idx);
1506 bfd_fatal ("bfd_get_elt_at_index");
1507 if (thesym->name != (char *) NULL)
1509 print_symname ("%s", thesym->name, abfd);
1510 printf (" in %s\n", bfd_get_filename (elt));
1515 /* This function is used to get the relocs for a particular section.
1516 It is called via bfd_map_over_sections. */
1519 get_relocs (abfd, sec, dataarg)
1524 struct get_relocs_info *data = (struct get_relocs_info *) dataarg;
1528 if ((sec->flags & SEC_RELOC) == 0)
1530 *data->relocs = NULL;
1531 *data->relcount = 0;
1537 relsize = bfd_get_reloc_upper_bound (abfd, sec);
1539 bfd_fatal (bfd_get_filename (abfd));
1541 *data->relocs = (arelent **) xmalloc (relsize);
1542 *data->relcount = bfd_canonicalize_reloc (abfd, sec, *data->relocs,
1544 if (*data->relcount < 0)
1545 bfd_fatal (bfd_get_filename (abfd));