1 /* nm.c -- Describe symbol table of a rel file.
2 Copyright 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "aout/stab_gnu.h"
27 #include "aout/ranlib.h"
29 #include "libiberty.h"
31 /* When sorting by size, we use this structure to hold the size and a
32 pointer to the minisymbol. */
40 /* When fetching relocs, we use this structure to pass information to
43 struct get_relocs_info
52 usage
PARAMS ((FILE *, int));
55 set_print_radix
PARAMS ((char *));
58 set_output_format
PARAMS ((char *));
61 display_archive
PARAMS ((bfd
*));
64 display_file
PARAMS ((char *filename
));
67 display_rel_file
PARAMS ((bfd
* file
, bfd
* archive
));
70 filter_symbols
PARAMS ((bfd
*, boolean
, PTR
, long, unsigned int));
73 sort_symbols_by_size
PARAMS ((bfd
*, boolean
, PTR
, long, unsigned int,
77 print_symbols
PARAMS ((bfd
*, boolean
, PTR
, long, unsigned int, bfd
*));
80 print_size_symbols
PARAMS ((bfd
*, boolean
, struct size_sym
*, long, bfd
*));
83 print_symname
PARAMS ((const char *, const char *, bfd
*));
86 print_symbol
PARAMS ((bfd
*, asymbol
*, bfd
*));
89 print_symdef_entry
PARAMS ((bfd
* abfd
));
91 /* The sorting functions. */
94 numeric_forward
PARAMS ((const PTR
, const PTR
));
97 numeric_reverse
PARAMS ((const PTR
, const PTR
));
100 non_numeric_forward
PARAMS ((const PTR
, const PTR
));
103 non_numeric_reverse
PARAMS ((const PTR
, const PTR
));
106 size_forward1
PARAMS ((const PTR
, const PTR
));
109 size_forward2
PARAMS ((const PTR
, const PTR
));
111 /* The output formatting functions. */
114 print_object_filename_bsd
PARAMS ((char *filename
));
117 print_object_filename_sysv
PARAMS ((char *filename
));
120 print_object_filename_posix
PARAMS ((char *filename
));
124 print_archive_filename_bsd
PARAMS ((char *filename
));
127 print_archive_filename_sysv
PARAMS ((char *filename
));
130 print_archive_filename_posix
PARAMS ((char *filename
));
134 print_archive_member_bsd
PARAMS ((char *archive
, CONST
char *filename
));
137 print_archive_member_sysv
PARAMS ((char *archive
, CONST
char *filename
));
140 print_archive_member_posix
PARAMS ((char *archive
, CONST
char *filename
));
144 print_symbol_filename_bsd
PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
147 print_symbol_filename_sysv
PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
150 print_symbol_filename_posix
PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
154 print_value
PARAMS ((bfd_vma
));
157 print_symbol_info_bsd
PARAMS ((symbol_info
* info
, bfd
* abfd
));
160 print_symbol_info_sysv
PARAMS ((symbol_info
* info
, bfd
* abfd
));
163 print_symbol_info_posix
PARAMS ((symbol_info
* info
, bfd
* abfd
));
166 get_relocs
PARAMS ((bfd
*, asection
*, PTR
));
168 /* Support for different output formats. */
171 /* Print the name of an object file given on the command line. */
172 void (*print_object_filename
) PARAMS ((char *filename
));
174 /* Print the name of an archive file given on the command line. */
175 void (*print_archive_filename
) PARAMS ((char *filename
));
177 /* Print the name of an archive member file. */
178 void (*print_archive_member
) PARAMS ((char *archive
, CONST
char *filename
));
180 /* Print the name of the file (and archive, if there is one)
181 containing a symbol. */
182 void (*print_symbol_filename
) PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
184 /* Print a line of information about a symbol. */
185 void (*print_symbol_info
) PARAMS ((symbol_info
* info
, bfd
* abfd
));
187 static struct output_fns formats
[] =
189 {print_object_filename_bsd
,
190 print_archive_filename_bsd
,
191 print_archive_member_bsd
,
192 print_symbol_filename_bsd
,
193 print_symbol_info_bsd
},
194 {print_object_filename_sysv
,
195 print_archive_filename_sysv
,
196 print_archive_member_sysv
,
197 print_symbol_filename_sysv
,
198 print_symbol_info_sysv
},
199 {print_object_filename_posix
,
200 print_archive_filename_posix
,
201 print_archive_member_posix
,
202 print_symbol_filename_posix
,
203 print_symbol_info_posix
}
206 /* Indices in `formats'. */
208 #define FORMAT_SYSV 1
209 #define FORMAT_POSIX 2
210 #define FORMAT_DEFAULT FORMAT_BSD
212 /* The output format to use. */
213 static struct output_fns
*format
= &formats
[FORMAT_DEFAULT
];
216 /* Command options. */
218 static int do_demangle
= 0; /* Pretty print C++ symbol names. */
219 static int external_only
= 0; /* print external symbols only */
220 static int defined_only
= 0; /* Print defined symbols only */
221 static int no_sort
= 0; /* don't sort; print syms in order found */
222 static int print_debug_syms
= 0; /* print debugger-only symbols too */
223 static int print_armap
= 0; /* describe __.SYMDEF data in archive files. */
224 static int reverse_sort
= 0; /* sort in downward(alpha or numeric) order */
225 static int sort_numerically
= 0; /* sort in numeric rather than alpha order */
226 static int sort_by_size
= 0; /* sort by size of symbol */
227 static int undefined_only
= 0; /* print undefined symbols only */
228 static int dynamic
= 0; /* print dynamic symbols. */
229 static int show_version
= 0; /* show the version number */
230 static int show_stats
= 0; /* show statistics */
231 static int line_numbers
= 0; /* print line numbers for symbols */
233 /* When to print the names of files. Not mutually exclusive in SYSV format. */
234 static int filename_per_file
= 0; /* Once per file, on its own line. */
235 static int filename_per_symbol
= 0; /* Once per symbol, at start of line. */
237 /* Print formats for printing a symbol value. */
239 static char value_format
[] = "%08lx";
241 #if BFD_HOST_64BIT_LONG
242 static char value_format
[] = "%016lx";
244 /* We don't use value_format for this case. */
247 static int print_radix
= 16;
248 /* Print formats for printing stab info. */
249 static char other_format
[] = "%02x";
250 static char desc_format
[] = "%04x";
252 static char *target
= NULL
;
254 /* Used to cache the line numbers for a BFD. */
255 static bfd
*lineno_cache_bfd
;
256 static bfd
*lineno_cache_rel_bfd
;
258 #define OPTION_TARGET 200
260 static struct option long_options
[] =
262 {"debug-syms", no_argument
, &print_debug_syms
, 1},
263 {"demangle", no_argument
, &do_demangle
, 1},
264 {"dynamic", no_argument
, &dynamic
, 1},
265 {"extern-only", no_argument
, &external_only
, 1},
266 {"format", required_argument
, 0, 'f'},
267 {"help", no_argument
, 0, 'h'},
268 {"line-numbers", no_argument
, 0, 'l'},
269 {"no-cplus", no_argument
, &do_demangle
, 0}, /* Linux compatibility. */
270 {"no-demangle", no_argument
, &do_demangle
, 0},
271 {"no-sort", no_argument
, &no_sort
, 1},
272 {"numeric-sort", no_argument
, &sort_numerically
, 1},
273 {"portability", no_argument
, 0, 'P'},
274 {"print-armap", no_argument
, &print_armap
, 1},
275 {"print-file-name", no_argument
, 0, 'o'},
276 {"radix", required_argument
, 0, 't'},
277 {"reverse-sort", no_argument
, &reverse_sort
, 1},
278 {"size-sort", no_argument
, &sort_by_size
, 1},
279 {"stats", no_argument
, &show_stats
, 1},
280 {"target", required_argument
, 0, OPTION_TARGET
},
281 {"defined-only", no_argument
, &defined_only
, 1},
282 {"undefined-only", no_argument
, &undefined_only
, 1},
283 {"version", no_argument
, &show_version
, 1},
284 {0, no_argument
, 0, 0}
287 /* Some error-reporting functions */
290 usage (stream
, status
)
294 fprintf (stream
, _("\
295 Usage: %s [-aABCDglnopPrsuvV] [-t radix] [--radix=radix] [--target=bfdname]\n\
296 [--debug-syms] [--extern-only] [--print-armap] [--print-file-name]\n\
297 [--numeric-sort] [--no-sort] [--reverse-sort] [--size-sort]\n\
298 [--undefined-only] [--portability] [-f {bsd,sysv,posix}]\n\
299 [--format={bsd,sysv,posix}] [--demangle] [--no-demangle] [--dynamic]\n\
300 [--defined-only] [--line-numbers]\n\
301 [--version] [--help]\n\
304 list_supported_targets (program_name
, stream
);
306 fprintf (stream
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
310 /* Set the radix for the symbol value and size according to RADIX. */
313 set_print_radix (radix
)
327 value_format
[4] = *radix
;
329 #if BFD_HOST_64BIT_LONG
330 value_format
[5] = *radix
;
332 /* This case requires special handling for octal and decimal
336 other_format
[3] = desc_format
[3] = *radix
;
339 fatal (_("%s: invalid radix"), radix
);
344 set_output_format (f
)
364 fatal (_("%s: invalid output format"), f
);
366 format
= &formats
[i
];
377 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
378 setlocale (LC_MESSAGES
, "");
380 bindtextdomain (PACKAGE
, LOCALEDIR
);
381 textdomain (PACKAGE
);
383 program_name
= *argv
;
384 xmalloc_set_program_name (program_name
);
386 START_PROGRESS (program_name
, 0);
389 set_default_bfd_target ();
391 while ((c
= getopt_long (argc
, argv
, "aABCDef:glnopPrst:uvV", long_options
, (int *) 0)) != EOF
)
396 print_debug_syms
= 1;
400 filename_per_symbol
= 1;
402 case 'B': /* For MIPS compatibility. */
403 set_output_format ("bsd");
412 /* Ignored for HP/UX compatibility. */
415 set_output_format (optarg
);
427 sort_numerically
= 1;
433 set_output_format ("posix");
442 set_print_radix (optarg
);
451 case OPTION_TARGET
: /* --target */
455 case 0: /* A long option that just sets a flag. */
464 print_version ("nm");
466 /* OK, all options now parsed. If no filename specified, do a.out. */
468 return !display_file ("a.out");
472 if (argc
- optind
> 1)
473 filename_per_file
= 1;
475 /* We were given several filenames to do. */
476 while (optind
< argc
)
479 if (!display_file (argv
[optind
++]))
483 END_PROGRESS (program_name
);
488 char *lim
= (char *) sbrk (0);
490 non_fatal (_("data size %ld"), (long) (lim
- (char *) &environ
));
499 display_archive (file
)
503 bfd
*last_arfile
= NULL
;
506 (*format
->print_archive_filename
) (bfd_get_filename (file
));
509 print_symdef_entry (file
);
515 arfile
= bfd_openr_next_archived_file (file
, arfile
);
519 if (bfd_get_error () != bfd_error_no_more_archived_files
)
520 bfd_fatal (bfd_get_filename (file
));
524 if (bfd_check_format_matches (arfile
, bfd_object
, &matching
))
526 (*format
->print_archive_member
) (bfd_get_filename (file
),
527 bfd_get_filename (arfile
));
528 display_rel_file (arfile
, file
);
532 bfd_nonfatal (bfd_get_filename (arfile
));
533 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
535 list_matching_formats (matching
);
540 if (last_arfile
!= NULL
)
542 bfd_close (last_arfile
);
543 lineno_cache_bfd
= NULL
;
544 lineno_cache_rel_bfd
= NULL
;
546 last_arfile
= arfile
;
549 if (last_arfile
!= NULL
)
551 bfd_close (last_arfile
);
552 lineno_cache_bfd
= NULL
;
553 lineno_cache_rel_bfd
= NULL
;
558 display_file (filename
)
561 boolean retval
= true;
565 file
= bfd_openr (filename
, target
);
568 bfd_nonfatal (filename
);
572 if (bfd_check_format (file
, bfd_archive
))
574 display_archive (file
);
576 else if (bfd_check_format_matches (file
, bfd_object
, &matching
))
578 (*format
->print_object_filename
) (filename
);
579 display_rel_file (file
, NULL
);
583 bfd_nonfatal (filename
);
584 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
586 list_matching_formats (matching
);
592 if (bfd_close (file
) == false)
593 bfd_fatal (filename
);
595 lineno_cache_bfd
= NULL
;
596 lineno_cache_rel_bfd
= NULL
;
601 /* These globals are used to pass information into the sorting
603 static bfd
*sort_bfd
;
604 static boolean sort_dynamic
;
605 static asymbol
*sort_x
;
606 static asymbol
*sort_y
;
608 /* Symbol-sorting predicates */
609 #define valueof(x) ((x)->section->vma + (x)->value)
611 /* Numeric sorts. Undefined symbols are always considered "less than"
612 defined symbols with zero values. Common symbols are not treated
613 specially -- i.e., their sizes are used as their "values". */
616 numeric_forward (P_x
, P_y
)
623 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
624 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
625 if (x
== NULL
|| y
== NULL
)
626 bfd_fatal (bfd_get_filename (sort_bfd
));
628 xs
= bfd_get_section (x
);
629 ys
= bfd_get_section (y
);
631 if (bfd_is_und_section (xs
))
633 if (! bfd_is_und_section (ys
))
636 else if (bfd_is_und_section (ys
))
638 else if (valueof (x
) != valueof (y
))
639 return valueof (x
) < valueof (y
) ? -1 : 1;
641 return non_numeric_forward (P_x
, P_y
);
645 numeric_reverse (x
, y
)
649 return - numeric_forward (x
, y
);
653 non_numeric_forward (P_x
, P_y
)
660 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
661 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
662 if (x
== NULL
|| y
== NULL
)
663 bfd_fatal (bfd_get_filename (sort_bfd
));
665 xn
= bfd_asymbol_name (x
);
666 yn
= bfd_asymbol_name (y
);
668 return ((xn
== NULL
) ? ((yn
== NULL
) ? 0 : -1) :
669 ((yn
== NULL
) ? 1 : strcmp (xn
, yn
)));
673 non_numeric_reverse (x
, y
)
677 return - non_numeric_forward (x
, y
);
680 static int (*(sorters
[2][2])) PARAMS ((const PTR
, const PTR
)) =
682 { non_numeric_forward
, non_numeric_reverse
},
683 { numeric_forward
, numeric_reverse
}
686 /* This sort routine is used by sort_symbols_by_size. It is similar
687 to numeric_forward, but when symbols have the same value it sorts
688 by section VMA. This simplifies the sort_symbols_by_size code
689 which handles symbols at the end of sections. Also, this routine
690 tries to sort file names before other symbols with the same value.
691 That will make the file name have a zero size, which will make
692 sort_symbols_by_size choose the non file name symbol, leading to
693 more meaningful output. For similar reasons, this code sorts
694 gnu_compiled_* and gcc2_compiled before other symbols with the same
698 size_forward1 (P_x
, P_y
)
708 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
709 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
710 if (x
== NULL
|| y
== NULL
)
711 bfd_fatal (bfd_get_filename (sort_bfd
));
713 xs
= bfd_get_section (x
);
714 ys
= bfd_get_section (y
);
716 if (bfd_is_und_section (xs
))
718 if (bfd_is_und_section (ys
))
721 if (valueof (x
) != valueof (y
))
722 return valueof (x
) < valueof (y
) ? -1 : 1;
724 if (xs
->vma
!= ys
->vma
)
725 return xs
->vma
< ys
->vma
? -1 : 1;
727 xn
= bfd_asymbol_name (x
);
728 yn
= bfd_asymbol_name (y
);
732 /* The symbols gnu_compiled and gcc2_compiled convey even less
733 information than the file name, so sort them out first. */
735 xf
= (strstr (xn
, "gnu_compiled") != NULL
736 || strstr (xn
, "gcc2_compiled") != NULL
);
737 yf
= (strstr (yn
, "gnu_compiled") != NULL
738 || strstr (yn
, "gcc2_compiled") != NULL
);
745 /* We use a heuristic for the file name. It may not work on non
746 Unix systems, but it doesn't really matter; the only difference
747 is precisely which symbol names get printed. */
749 #define file_symbol(s, sn, snl) \
750 (((s)->flags & BSF_FILE) != 0 \
751 || ((sn)[(snl) - 2] == '.' \
752 && ((sn)[(snl) - 1] == 'o' \
753 || (sn)[(snl) - 1] == 'a')))
755 xf
= file_symbol (x
, xn
, xnl
);
756 yf
= file_symbol (y
, yn
, ynl
);
763 return non_numeric_forward (P_x
, P_y
);
766 /* This sort routine is used by sort_symbols_by_size. It is sorting
767 an array of size_sym structures into size order. */
770 size_forward2 (P_x
, P_y
)
774 const struct size_sym
*x
= (const struct size_sym
*) P_x
;
775 const struct size_sym
*y
= (const struct size_sym
*) P_y
;
777 if (x
->size
< y
->size
)
778 return reverse_sort
? 1 : -1;
779 else if (x
->size
> y
->size
)
780 return reverse_sort
? -1 : 1;
782 return sorters
[0][reverse_sort
] (x
->minisym
, y
->minisym
);
785 /* Sort the symbols by size. We guess the size by assuming that the
786 difference between the address of a symbol and the address of the
787 next higher symbol is the size. FIXME: ELF actually stores a size
788 with each symbol. We should use it. */
791 sort_symbols_by_size (abfd
, dynamic
, minisyms
, symcount
, size
, symsizesp
)
797 struct size_sym
**symsizesp
;
799 struct size_sym
*symsizes
;
800 bfd_byte
*from
, *fromend
;
802 asymbol
*store_sym
, *store_next
;
804 qsort (minisyms
, symcount
, size
, size_forward1
);
806 /* We are going to return a special set of symbols and sizes to
808 symsizes
= (struct size_sym
*) xmalloc (symcount
* sizeof (struct size_sym
));
809 *symsizesp
= symsizes
;
811 /* Note that filter_symbols has already removed all absolute and
812 undefined symbols. Here we remove all symbols whose size winds
815 from
= (bfd_byte
*) minisyms
;
816 fromend
= from
+ symcount
* size
;
823 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, (const PTR
) from
,
826 bfd_fatal (bfd_get_filename (abfd
));
829 for (; from
< fromend
; from
+= size
)
836 if (from
+ size
< fromend
)
838 next
= bfd_minisymbol_to_symbol (abfd
,
840 (const PTR
) (from
+ size
),
843 bfd_fatal (bfd_get_filename (abfd
));
848 sec
= bfd_get_section (sym
);
850 if (bfd_is_com_section (sec
))
854 if (from
+ size
< fromend
855 && sec
== bfd_get_section (next
))
856 sz
= valueof (next
) - valueof (sym
);
858 sz
= (bfd_get_section_vma (abfd
, sec
)
859 + bfd_section_size (abfd
, sec
)
865 symsizes
->minisym
= (const PTR
) from
;
873 store_sym
= store_next
;
877 symcount
= symsizes
- *symsizesp
;
879 /* We must now sort again by size. */
880 qsort ((PTR
) *symsizesp
, symcount
, sizeof (struct size_sym
), size_forward2
);
885 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */
888 display_rel_file (abfd
, archive_bfd
)
895 struct size_sym
*symsizes
;
899 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
901 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
906 symcount
= bfd_read_minisymbols (abfd
, dynamic
, &minisyms
, &size
);
908 bfd_fatal (bfd_get_filename (abfd
));
912 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
916 /* Discard the symbols we don't want to print.
917 It's OK to do this in place; we'll free the storage anyway
920 symcount
= filter_symbols (abfd
, dynamic
, minisyms
, symcount
, size
);
926 sort_dynamic
= dynamic
;
927 sort_x
= bfd_make_empty_symbol (abfd
);
928 sort_y
= bfd_make_empty_symbol (abfd
);
929 if (sort_x
== NULL
|| sort_y
== NULL
)
930 bfd_fatal (bfd_get_filename (abfd
));
933 qsort (minisyms
, symcount
, size
,
934 sorters
[sort_numerically
][reverse_sort
]);
936 symcount
= sort_symbols_by_size (abfd
, dynamic
, minisyms
, symcount
,
941 print_symbols (abfd
, dynamic
, minisyms
, symcount
, size
, archive_bfd
);
943 print_size_symbols (abfd
, dynamic
, symsizes
, symcount
, archive_bfd
);
948 /* Choose which symbol entries to print;
949 compact them downward to get rid of the rest.
950 Return the number of symbols to be printed. */
953 filter_symbols (abfd
, dynamic
, minisyms
, symcount
, size
)
960 bfd_byte
*from
, *fromend
, *to
;
963 store
= bfd_make_empty_symbol (abfd
);
965 bfd_fatal (bfd_get_filename (abfd
));
967 from
= (bfd_byte
*) minisyms
;
968 fromend
= from
+ symcount
* size
;
969 to
= (bfd_byte
*) minisyms
;
971 for (; from
< fromend
; from
+= size
)
978 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, (const PTR
) from
, store
);
980 bfd_fatal (bfd_get_filename (abfd
));
983 keep
= bfd_is_und_section (sym
->section
);
984 else if (external_only
)
985 keep
= ((sym
->flags
& BSF_GLOBAL
) != 0
986 || (sym
->flags
& BSF_WEAK
) != 0
987 || bfd_is_und_section (sym
->section
)
988 || bfd_is_com_section (sym
->section
));
993 && ! print_debug_syms
994 && (sym
->flags
& BSF_DEBUGGING
) != 0)
999 && (bfd_is_abs_section (sym
->section
)
1000 || bfd_is_und_section (sym
->section
)))
1006 if (bfd_is_und_section (sym
->section
))
1012 memcpy (to
, from
, size
);
1017 return (to
- (bfd_byte
*) minisyms
) / size
;
1020 /* Print symbol name NAME, read from ABFD, with printf format FORMAT,
1021 demangling it if requested. */
1024 print_symname (format
, name
, abfd
)
1029 if (do_demangle
&& *name
)
1033 /* In this mode, give a user-level view of the symbol name
1034 even if it's not mangled; strip off any leading
1036 if (bfd_get_symbol_leading_char (abfd
) == name
[0])
1039 res
= cplus_demangle (name
, DMGL_ANSI
| DMGL_PARAMS
);
1042 printf (format
, res
);
1048 printf (format
, name
);
1051 /* Print the symbols. If ARCHIVE_BFD is non-NULL, it is the archive
1055 print_symbols (abfd
, dynamic
, minisyms
, symcount
, size
, archive_bfd
)
1064 bfd_byte
*from
, *fromend
;
1066 store
= bfd_make_empty_symbol (abfd
);
1068 bfd_fatal (bfd_get_filename (abfd
));
1070 from
= (bfd_byte
*) minisyms
;
1071 fromend
= from
+ symcount
* size
;
1072 for (; from
< fromend
; from
+= size
)
1076 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, from
, store
);
1078 bfd_fatal (bfd_get_filename (abfd
));
1080 print_symbol (abfd
, sym
, archive_bfd
);
1084 /* Print the symbols when sorting by size. */
1087 print_size_symbols (abfd
, dynamic
, symsizes
, symcount
, archive_bfd
)
1090 struct size_sym
*symsizes
;
1095 struct size_sym
*from
, *fromend
;
1097 store
= bfd_make_empty_symbol (abfd
);
1099 bfd_fatal (bfd_get_filename (abfd
));
1102 fromend
= from
+ symcount
;
1103 for (; from
< fromend
; from
++)
1107 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, from
->minisym
, store
);
1109 bfd_fatal (bfd_get_filename (abfd
));
1111 /* Set the symbol value so that we actually display the symbol
1113 sym
->value
= from
->size
- bfd_section_vma (abfd
, bfd_get_section (sym
));
1115 print_symbol (abfd
, sym
, archive_bfd
);
1119 /* Print a single symbol. */
1122 print_symbol (abfd
, sym
, archive_bfd
)
1129 (*format
->print_symbol_filename
) (archive_bfd
, abfd
);
1133 if (bfd_is_und_section (bfd_get_section (sym
)))
1134 print_symname ("%s", bfd_asymbol_name (sym
), abfd
);
1138 symbol_info syminfo
;
1140 bfd_get_symbol_info (abfd
, sym
, &syminfo
);
1141 (*format
->print_symbol_info
) (&syminfo
, abfd
);
1146 static asymbol
**syms
;
1147 static long symcount
;
1148 const char *filename
, *functionname
;
1149 unsigned int lineno
;
1151 /* We need to get the canonical symbols in order to call
1152 bfd_find_nearest_line. This is inefficient, but, then, you
1153 don't have to use --line-numbers. */
1154 if (abfd
!= lineno_cache_bfd
&& syms
!= NULL
)
1163 symsize
= bfd_get_symtab_upper_bound (abfd
);
1165 bfd_fatal (bfd_get_filename (abfd
));
1166 syms
= (asymbol
**) xmalloc (symsize
);
1167 symcount
= bfd_canonicalize_symtab (abfd
, syms
);
1169 bfd_fatal (bfd_get_filename (abfd
));
1170 lineno_cache_bfd
= abfd
;
1173 if (bfd_is_und_section (bfd_get_section (sym
)))
1175 static asection
**secs
;
1176 static arelent
***relocs
;
1177 static long *relcount
;
1178 static unsigned int seccount
;
1180 const char *symname
;
1182 /* For an undefined symbol, we try to find a reloc for the
1183 symbol, and print the line number of the reloc. */
1185 if (abfd
!= lineno_cache_rel_bfd
&& relocs
!= NULL
)
1187 for (i
= 0; i
< seccount
; i
++)
1188 if (relocs
[i
] != NULL
)
1200 struct get_relocs_info info
;
1202 seccount
= bfd_count_sections (abfd
);
1204 secs
= (asection
**) xmalloc (seccount
* sizeof *secs
);
1205 relocs
= (arelent
***) xmalloc (seccount
* sizeof *relocs
);
1206 relcount
= (long *) xmalloc (seccount
* sizeof *relcount
);
1209 info
.relocs
= relocs
;
1210 info
.relcount
= relcount
;
1212 bfd_map_over_sections (abfd
, get_relocs
, (PTR
) &info
);
1213 lineno_cache_rel_bfd
= abfd
;
1216 symname
= bfd_asymbol_name (sym
);
1217 for (i
= 0; i
< seccount
; i
++)
1221 for (j
= 0; j
< relcount
[i
]; j
++)
1226 if (r
->sym_ptr_ptr
!= NULL
1227 && (*r
->sym_ptr_ptr
)->section
== sym
->section
1228 && (*r
->sym_ptr_ptr
)->value
== sym
->value
1230 bfd_asymbol_name (*r
->sym_ptr_ptr
)) == 0
1231 && bfd_find_nearest_line (abfd
, secs
[i
], syms
,
1232 r
->address
, &filename
,
1233 &functionname
, &lineno
))
1235 /* We only print the first one we find. */
1236 printf ("\t%s:%u", filename
, lineno
);
1243 else if (bfd_get_section (sym
)->owner
== abfd
)
1245 if (bfd_find_nearest_line (abfd
, bfd_get_section (sym
), syms
,
1246 sym
->value
, &filename
, &functionname
,
1251 printf ("\t%s:%u", filename
, lineno
);
1259 /* The following 3 groups of functions are called unconditionally,
1260 once at the start of processing each file of the appropriate type.
1261 They should check `filename_per_file' and `filename_per_symbol',
1262 as appropriate for their output format, to determine whether to
1265 /* Print the name of an object file given on the command line. */
1268 print_object_filename_bsd (filename
)
1271 if (filename_per_file
&& !filename_per_symbol
)
1272 printf ("\n%s:\n", filename
);
1276 print_object_filename_sysv (filename
)
1280 printf (_("\n\nUndefined symbols from %s:\n\n"), filename
);
1282 printf (_("\n\nSymbols from %s:\n\n"), filename
);
1284 Name Value Class Type Size Line Section\n\n"));
1288 print_object_filename_posix (filename
)
1291 if (filename_per_file
&& !filename_per_symbol
)
1292 printf ("%s:\n", filename
);
1295 /* Print the name of an archive file given on the command line. */
1298 print_archive_filename_bsd (filename
)
1301 if (filename_per_file
)
1302 printf ("\n%s:\n", filename
);
1306 print_archive_filename_sysv (filename
)
1307 char *filename ATTRIBUTE_UNUSED
;
1312 print_archive_filename_posix (filename
)
1313 char *filename ATTRIBUTE_UNUSED
;
1317 /* Print the name of an archive member file. */
1320 print_archive_member_bsd (archive
, filename
)
1321 char *archive ATTRIBUTE_UNUSED
;
1322 CONST
char *filename
;
1324 if (!filename_per_symbol
)
1325 printf ("\n%s:\n", filename
);
1329 print_archive_member_sysv (archive
, filename
)
1331 CONST
char *filename
;
1334 printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive
, filename
);
1336 printf (_("\n\nSymbols from %s[%s]:\n\n"), archive
, filename
);
1338 Name Value Class Type Size Line Section\n\n"));
1342 print_archive_member_posix (archive
, filename
)
1344 CONST
char *filename
;
1346 if (!filename_per_symbol
)
1347 printf ("%s[%s]:\n", archive
, filename
);
1350 /* Print the name of the file (and archive, if there is one)
1351 containing a symbol. */
1354 print_symbol_filename_bsd (archive_bfd
, abfd
)
1355 bfd
*archive_bfd
, *abfd
;
1357 if (filename_per_symbol
)
1360 printf ("%s:", bfd_get_filename (archive_bfd
));
1361 printf ("%s:", bfd_get_filename (abfd
));
1366 print_symbol_filename_sysv (archive_bfd
, abfd
)
1367 bfd
*archive_bfd
, *abfd
;
1369 if (filename_per_symbol
)
1372 printf ("%s:", bfd_get_filename (archive_bfd
));
1373 printf ("%s:", bfd_get_filename (abfd
));
1378 print_symbol_filename_posix (archive_bfd
, abfd
)
1379 bfd
*archive_bfd
, *abfd
;
1381 if (filename_per_symbol
)
1384 printf ("%s[%s]: ", bfd_get_filename (archive_bfd
),
1385 bfd_get_filename (abfd
));
1387 printf ("%s: ", bfd_get_filename (abfd
));
1391 /* Print a symbol value. */
1397 #if ! defined (BFD64) || BFD_HOST_64BIT_LONG
1398 printf (value_format
, val
);
1400 /* We have a 64 bit value to print, but the host is only 32 bit. */
1401 if (print_radix
== 16)
1402 fprintf_vma (stdout
, val
);
1408 s
= buf
+ sizeof buf
;
1412 *--s
= (val
% print_radix
) + '0';
1415 while ((buf
+ sizeof buf
- 1) - s
< 16)
1422 /* Print a line of information about a symbol. */
1425 print_symbol_info_bsd (info
, abfd
)
1429 if (bfd_is_undefined_symclass (info
->type
))
1440 print_value (info
->value
);
1441 printf (" %c", info
->type
);
1442 if (info
->type
== '-')
1446 printf (other_format
, info
->stab_other
);
1448 printf (desc_format
, info
->stab_desc
);
1449 printf (" %5s", info
->stab_name
);
1451 print_symname (" %s", info
->name
, abfd
);
1455 print_symbol_info_sysv (info
, abfd
)
1459 print_symname ("%-20s|", info
->name
, abfd
); /* Name */
1460 if (bfd_is_undefined_symclass (info
->type
))
1461 printf (" "); /* Value */
1463 print_value (info
->value
);
1464 printf ("| %c |", info
->type
); /* Class */
1465 if (info
->type
== '-')
1468 printf ("%18s| ", info
->stab_name
); /* (C) Type */
1469 printf (desc_format
, info
->stab_desc
); /* Size */
1470 printf ("| |"); /* Line, Section */
1473 printf (" | | |"); /* Type, Size, Line, Section */
1477 print_symbol_info_posix (info
, abfd
)
1481 print_symname ("%s ", info
->name
, abfd
);
1482 printf ("%c ", info
->type
);
1483 if (bfd_is_undefined_symclass (info
->type
))
1486 print_value (info
->value
);
1487 /* POSIX.2 wants the symbol size printed here, when applicable;
1488 BFD currently doesn't provide it, so we take the easy way out by
1489 considering it to never be applicable. */
1493 print_symdef_entry (abfd
)
1496 symindex idx
= BFD_NO_MORE_SYMBOLS
;
1498 boolean everprinted
= false;
1500 for (idx
= bfd_get_next_mapent (abfd
, idx
, &thesym
);
1501 idx
!= BFD_NO_MORE_SYMBOLS
;
1502 idx
= bfd_get_next_mapent (abfd
, idx
, &thesym
))
1507 printf (_("\nArchive index:\n"));
1510 elt
= bfd_get_elt_at_index (abfd
, idx
);
1512 bfd_fatal ("bfd_get_elt_at_index");
1513 if (thesym
->name
!= (char *) NULL
)
1515 print_symname ("%s", thesym
->name
, abfd
);
1516 printf (" in %s\n", bfd_get_filename (elt
));
1521 /* This function is used to get the relocs for a particular section.
1522 It is called via bfd_map_over_sections. */
1525 get_relocs (abfd
, sec
, dataarg
)
1530 struct get_relocs_info
*data
= (struct get_relocs_info
*) dataarg
;
1534 if ((sec
->flags
& SEC_RELOC
) == 0)
1536 *data
->relocs
= NULL
;
1537 *data
->relcount
= 0;
1543 relsize
= bfd_get_reloc_upper_bound (abfd
, sec
);
1545 bfd_fatal (bfd_get_filename (abfd
));
1547 *data
->relocs
= (arelent
**) xmalloc (relsize
);
1548 *data
->relcount
= bfd_canonicalize_reloc (abfd
, sec
, *data
->relocs
,
1550 if (*data
->relcount
< 0)
1551 bfd_fatal (bfd_get_filename (abfd
));