1 /* nm.c -- Describe symbol table of a rel file.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "aout/stab_gnu.h"
28 #include "aout/ranlib.h"
30 #include "libiberty.h"
33 /* When sorting by size, we use this structure to hold the size and a
34 pointer to the minisymbol. */
42 /* When fetching relocs, we use this structure to pass information to
45 struct get_relocs_info
54 usage
PARAMS ((FILE *, int));
57 set_print_radix
PARAMS ((char *));
60 set_output_format
PARAMS ((char *));
63 display_archive
PARAMS ((bfd
*));
66 display_file
PARAMS ((char *filename
));
69 display_rel_file
PARAMS ((bfd
* file
, bfd
* archive
));
72 filter_symbols
PARAMS ((bfd
*, boolean
, PTR
, long, unsigned int));
75 sort_symbols_by_size
PARAMS ((bfd
*, boolean
, PTR
, long, unsigned int,
79 print_symbols
PARAMS ((bfd
*, boolean
, PTR
, long, unsigned int, bfd
*));
82 print_size_symbols
PARAMS ((bfd
*, boolean
, struct size_sym
*, long, bfd
*));
85 print_symname
PARAMS ((const char *, const char *, bfd
*));
88 print_symbol
PARAMS ((bfd
*, asymbol
*, bfd
*));
91 print_symdef_entry
PARAMS ((bfd
* abfd
));
93 /* The sorting functions. */
96 numeric_forward
PARAMS ((const PTR
, const PTR
));
99 numeric_reverse
PARAMS ((const PTR
, const PTR
));
102 non_numeric_forward
PARAMS ((const PTR
, const PTR
));
105 non_numeric_reverse
PARAMS ((const PTR
, const PTR
));
108 size_forward1
PARAMS ((const PTR
, const PTR
));
111 size_forward2
PARAMS ((const PTR
, const PTR
));
113 /* The output formatting functions. */
116 print_object_filename_bsd
PARAMS ((char *filename
));
119 print_object_filename_sysv
PARAMS ((char *filename
));
122 print_object_filename_posix
PARAMS ((char *filename
));
126 print_archive_filename_bsd
PARAMS ((char *filename
));
129 print_archive_filename_sysv
PARAMS ((char *filename
));
132 print_archive_filename_posix
PARAMS ((char *filename
));
136 print_archive_member_bsd
PARAMS ((char *archive
, CONST
char *filename
));
139 print_archive_member_sysv
PARAMS ((char *archive
, CONST
char *filename
));
142 print_archive_member_posix
PARAMS ((char *archive
, CONST
char *filename
));
146 print_symbol_filename_bsd
PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
149 print_symbol_filename_sysv
PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
152 print_symbol_filename_posix
PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
156 print_value
PARAMS ((bfd
*, bfd_vma
));
159 print_symbol_info_bsd
PARAMS ((symbol_info
* info
, bfd
* abfd
));
162 print_symbol_info_sysv
PARAMS ((symbol_info
* info
, bfd
* abfd
));
165 print_symbol_info_posix
PARAMS ((symbol_info
* info
, bfd
* abfd
));
168 get_relocs
PARAMS ((bfd
*, asection
*, PTR
));
170 /* Support for different output formats. */
173 /* Print the name of an object file given on the command line. */
174 void (*print_object_filename
) PARAMS ((char *filename
));
176 /* Print the name of an archive file given on the command line. */
177 void (*print_archive_filename
) PARAMS ((char *filename
));
179 /* Print the name of an archive member file. */
180 void (*print_archive_member
) PARAMS ((char *archive
, CONST
char *filename
));
182 /* Print the name of the file (and archive, if there is one)
183 containing a symbol. */
184 void (*print_symbol_filename
) PARAMS ((bfd
* archive_bfd
, bfd
* abfd
));
186 /* Print a line of information about a symbol. */
187 void (*print_symbol_info
) PARAMS ((symbol_info
* info
, bfd
* abfd
));
189 static struct output_fns formats
[] =
191 {print_object_filename_bsd
,
192 print_archive_filename_bsd
,
193 print_archive_member_bsd
,
194 print_symbol_filename_bsd
,
195 print_symbol_info_bsd
},
196 {print_object_filename_sysv
,
197 print_archive_filename_sysv
,
198 print_archive_member_sysv
,
199 print_symbol_filename_sysv
,
200 print_symbol_info_sysv
},
201 {print_object_filename_posix
,
202 print_archive_filename_posix
,
203 print_archive_member_posix
,
204 print_symbol_filename_posix
,
205 print_symbol_info_posix
}
208 /* Indices in `formats'. */
210 #define FORMAT_SYSV 1
211 #define FORMAT_POSIX 2
212 #define FORMAT_DEFAULT FORMAT_BSD
214 /* The output format to use. */
215 static struct output_fns
*format
= &formats
[FORMAT_DEFAULT
];
218 /* Command options. */
220 static int do_demangle
= 0; /* Pretty print C++ symbol names. */
221 static int external_only
= 0; /* print external symbols only */
222 static int defined_only
= 0; /* Print defined symbols only */
223 static int no_sort
= 0; /* don't sort; print syms in order found */
224 static int print_debug_syms
= 0; /* print debugger-only symbols too */
225 static int print_armap
= 0; /* describe __.SYMDEF data in archive files. */
226 static int reverse_sort
= 0; /* sort in downward(alpha or numeric) order */
227 static int sort_numerically
= 0; /* sort in numeric rather than alpha order */
228 static int sort_by_size
= 0; /* sort by size of symbol */
229 static int undefined_only
= 0; /* print undefined symbols only */
230 static int dynamic
= 0; /* print dynamic symbols. */
231 static int show_version
= 0; /* show the version number */
232 static int show_stats
= 0; /* show statistics */
233 static int line_numbers
= 0; /* print line numbers for symbols */
235 /* When to print the names of files. Not mutually exclusive in SYSV format. */
236 static int filename_per_file
= 0; /* Once per file, on its own line. */
237 static int filename_per_symbol
= 0; /* Once per symbol, at start of line. */
239 /* Print formats for printing a symbol value. */
241 static char value_format
[] = "%08lx";
243 #if BFD_HOST_64BIT_LONG
244 static char value_format
[] = "%016lx";
246 /* We don't use value_format for this case. */
250 static int print_width
= 16;
252 static int print_width
= 8;
254 static int print_radix
= 16;
255 /* Print formats for printing stab info. */
256 static char other_format
[] = "%02x";
257 static char desc_format
[] = "%04x";
259 static char *target
= NULL
;
261 /* Used to cache the line numbers for a BFD. */
262 static bfd
*lineno_cache_bfd
;
263 static bfd
*lineno_cache_rel_bfd
;
265 #define OPTION_TARGET 200
267 static struct option long_options
[] =
269 {"debug-syms", no_argument
, &print_debug_syms
, 1},
270 {"demangle", optional_argument
, 0, 'C'},
271 {"dynamic", no_argument
, &dynamic
, 1},
272 {"extern-only", no_argument
, &external_only
, 1},
273 {"format", required_argument
, 0, 'f'},
274 {"help", no_argument
, 0, 'h'},
275 {"line-numbers", no_argument
, 0, 'l'},
276 {"no-cplus", no_argument
, &do_demangle
, 0}, /* Linux compatibility. */
277 {"no-demangle", no_argument
, &do_demangle
, 0},
278 {"no-sort", no_argument
, &no_sort
, 1},
279 {"numeric-sort", no_argument
, &sort_numerically
, 1},
280 {"portability", no_argument
, 0, 'P'},
281 {"print-armap", no_argument
, &print_armap
, 1},
282 {"print-file-name", no_argument
, 0, 'o'},
283 {"radix", required_argument
, 0, 't'},
284 {"reverse-sort", no_argument
, &reverse_sort
, 1},
285 {"size-sort", no_argument
, &sort_by_size
, 1},
286 {"stats", no_argument
, &show_stats
, 1},
287 {"target", required_argument
, 0, OPTION_TARGET
},
288 {"defined-only", no_argument
, &defined_only
, 1},
289 {"undefined-only", no_argument
, &undefined_only
, 1},
290 {"version", no_argument
, &show_version
, 1},
291 {0, no_argument
, 0, 0}
294 /* Some error-reporting functions */
297 usage (stream
, status
)
301 fprintf (stream
, _("Usage: %s [option(s)] [file(s)]\n"), program_name
);
302 fprintf (stream
, _(" List symbols in [file(s)] (a.out by default).\n"));
303 fprintf (stream
, _(" The options are:\n\
304 -a, --debug-syms Display debugger-only symbols\n\
305 -A, --print-file-name Print name of the input file before every symbol\n\
306 -B Same as --format=bsd\n\
307 -C, --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
308 The STYLE, if specified, can be `auto' (the default),\n\
309 `gnu', 'lucid', 'arm', 'hp', 'edg' or 'gnu-new-abi'\n\
310 --no-demangle Do not demangle low-level symbol names\n\
311 -D, --dynamic Display dynamic symbols instead of normal symbols\n\
312 --defined-only Display only defined symbols\n\
314 -f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',\n\
315 `sysv' or `posix'. The default is `bsd'\n\
316 -g, --extern-only Display only external symbols\n\
317 -l, --line-numbers Use debugging information to find a filename and\n\
318 line number for each symbol\n\
319 -n, --numeric-sort Sort symbols numerically by address\n\
321 -p, --no-sort Do not sort the symbols\n\
322 -P, --portability Same as --format=posix\n\
323 -r, --reverse-sort Reverse the sense of the sort\n\
324 -s, --print-armap Include index for symbols from archive members\n\
325 --size-sort Sort symbols by size\n\
326 -t, --radix=RADIX Use RADIX for printing symbol values\n\
327 --target=BFDNAME Specify the target object format as BFDNAME\n\
328 -u, --undefined-only Display only undefined symbols\n\
329 -X 32_64 (ignored)\n\
330 -h, --help Display this information\n\
331 -V, --version Display this program's version number\n\
333 list_supported_targets (program_name
, stream
);
335 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
339 /* Set the radix for the symbol value and size according to RADIX. */
342 set_print_radix (radix
)
356 value_format
[4] = *radix
;
358 #if BFD_HOST_64BIT_LONG
359 value_format
[5] = *radix
;
361 /* This case requires special handling for octal and decimal
365 other_format
[3] = desc_format
[3] = *radix
;
368 fatal (_("%s: invalid radix"), radix
);
373 set_output_format (f
)
393 fatal (_("%s: invalid output format"), f
);
395 format
= &formats
[i
];
398 int main
PARAMS ((int, char **));
408 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
409 setlocale (LC_MESSAGES
, "");
411 #if defined (HAVE_SETLOCALE)
412 setlocale (LC_CTYPE
, "");
414 bindtextdomain (PACKAGE
, LOCALEDIR
);
415 textdomain (PACKAGE
);
417 program_name
= *argv
;
418 xmalloc_set_program_name (program_name
);
420 START_PROGRESS (program_name
, 0);
423 set_default_bfd_target ();
425 while ((c
= getopt_long (argc
, argv
, "aABCDef:gHhlnopPrst:uvVvX:",
426 long_options
, (int *) 0)) != EOF
)
431 print_debug_syms
= 1;
435 filename_per_symbol
= 1;
437 case 'B': /* For MIPS compatibility. */
438 set_output_format ("bsd");
444 enum demangling_styles style
;
446 style
= cplus_demangle_name_to_style (optarg
);
447 if (style
== unknown_demangling
)
448 fatal (_("unknown demangling style `%s'"),
451 cplus_demangle_set_style (style
);
458 /* Ignored for HP/UX compatibility. */
461 set_output_format (optarg
);
474 sort_numerically
= 1;
480 set_output_format ("posix");
489 set_print_radix (optarg
);
498 /* Ignored for (partial) AIX compatibility. On AIX, the
499 argument has values 32, 64, or 32_64, and specfies that
500 only 32-bit, only 64-bit, or both kinds of objects should
501 be examined. The default is 32. So plain AIX nm on a
502 library archive with both kinds of objects will ignore
503 the 64-bit ones. For GNU nm, the default is and always
504 has been -X 32_64, and other options are not supported. */
505 if (strcmp (optarg
, "32_64") != 0)
506 fatal (_("Only -X 32_64 is supported"));
509 case OPTION_TARGET
: /* --target */
513 case 0: /* A long option that just sets a flag. */
522 print_version ("nm");
524 /* OK, all options now parsed. If no filename specified, do a.out. */
526 return !display_file ("a.out");
530 if (argc
- optind
> 1)
531 filename_per_file
= 1;
533 /* We were given several filenames to do. */
534 while (optind
< argc
)
537 if (!display_file (argv
[optind
++]))
541 END_PROGRESS (program_name
);
546 char *lim
= (char *) sbrk (0);
548 non_fatal (_("data size %ld"), (long) (lim
- (char *) &environ
));
557 display_archive (file
)
561 bfd
*last_arfile
= NULL
;
564 (*format
->print_archive_filename
) (bfd_get_filename (file
));
567 print_symdef_entry (file
);
573 arfile
= bfd_openr_next_archived_file (file
, arfile
);
577 if (bfd_get_error () != bfd_error_no_more_archived_files
)
578 bfd_fatal (bfd_get_filename (file
));
582 if (bfd_check_format_matches (arfile
, bfd_object
, &matching
))
584 (*format
->print_archive_member
) (bfd_get_filename (file
),
585 bfd_get_filename (arfile
));
586 display_rel_file (arfile
, file
);
590 bfd_nonfatal (bfd_get_filename (arfile
));
591 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
593 list_matching_formats (matching
);
598 if (last_arfile
!= NULL
)
600 bfd_close (last_arfile
);
601 lineno_cache_bfd
= NULL
;
602 lineno_cache_rel_bfd
= NULL
;
604 last_arfile
= arfile
;
607 if (last_arfile
!= NULL
)
609 bfd_close (last_arfile
);
610 lineno_cache_bfd
= NULL
;
611 lineno_cache_rel_bfd
= NULL
;
616 display_file (filename
)
619 boolean retval
= true;
623 file
= bfd_openr (filename
, target
);
626 bfd_nonfatal (filename
);
630 if (bfd_check_format (file
, bfd_archive
))
632 display_archive (file
);
634 else if (bfd_check_format_matches (file
, bfd_object
, &matching
))
636 (*format
->print_object_filename
) (filename
);
637 display_rel_file (file
, NULL
);
641 bfd_nonfatal (filename
);
642 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
644 list_matching_formats (matching
);
650 if (bfd_close (file
) == false)
651 bfd_fatal (filename
);
653 lineno_cache_bfd
= NULL
;
654 lineno_cache_rel_bfd
= NULL
;
659 /* These globals are used to pass information into the sorting
661 static bfd
*sort_bfd
;
662 static boolean sort_dynamic
;
663 static asymbol
*sort_x
;
664 static asymbol
*sort_y
;
666 /* Symbol-sorting predicates */
667 #define valueof(x) ((x)->section->vma + (x)->value)
669 /* Numeric sorts. Undefined symbols are always considered "less than"
670 defined symbols with zero values. Common symbols are not treated
671 specially -- i.e., their sizes are used as their "values". */
674 numeric_forward (P_x
, P_y
)
681 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
682 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
683 if (x
== NULL
|| y
== NULL
)
684 bfd_fatal (bfd_get_filename (sort_bfd
));
686 xs
= bfd_get_section (x
);
687 ys
= bfd_get_section (y
);
689 if (bfd_is_und_section (xs
))
691 if (! bfd_is_und_section (ys
))
694 else if (bfd_is_und_section (ys
))
696 else if (valueof (x
) != valueof (y
))
697 return valueof (x
) < valueof (y
) ? -1 : 1;
699 return non_numeric_forward (P_x
, P_y
);
703 numeric_reverse (x
, y
)
707 return - numeric_forward (x
, y
);
711 non_numeric_forward (P_x
, P_y
)
718 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
719 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
720 if (x
== NULL
|| y
== NULL
)
721 bfd_fatal (bfd_get_filename (sort_bfd
));
723 xn
= bfd_asymbol_name (x
);
724 yn
= bfd_asymbol_name (y
);
726 return ((xn
== NULL
) ? ((yn
== NULL
) ? 0 : -1) :
727 ((yn
== NULL
) ? 1 : strcmp (xn
, yn
)));
731 non_numeric_reverse (x
, y
)
735 return - non_numeric_forward (x
, y
);
738 static int (*(sorters
[2][2])) PARAMS ((const PTR
, const PTR
)) =
740 { non_numeric_forward
, non_numeric_reverse
},
741 { numeric_forward
, numeric_reverse
}
744 /* This sort routine is used by sort_symbols_by_size. It is similar
745 to numeric_forward, but when symbols have the same value it sorts
746 by section VMA. This simplifies the sort_symbols_by_size code
747 which handles symbols at the end of sections. Also, this routine
748 tries to sort file names before other symbols with the same value.
749 That will make the file name have a zero size, which will make
750 sort_symbols_by_size choose the non file name symbol, leading to
751 more meaningful output. For similar reasons, this code sorts
752 gnu_compiled_* and gcc2_compiled before other symbols with the same
756 size_forward1 (P_x
, P_y
)
766 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
767 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
768 if (x
== NULL
|| y
== NULL
)
769 bfd_fatal (bfd_get_filename (sort_bfd
));
771 xs
= bfd_get_section (x
);
772 ys
= bfd_get_section (y
);
774 if (bfd_is_und_section (xs
))
776 if (bfd_is_und_section (ys
))
779 if (valueof (x
) != valueof (y
))
780 return valueof (x
) < valueof (y
) ? -1 : 1;
782 if (xs
->vma
!= ys
->vma
)
783 return xs
->vma
< ys
->vma
? -1 : 1;
785 xn
= bfd_asymbol_name (x
);
786 yn
= bfd_asymbol_name (y
);
790 /* The symbols gnu_compiled and gcc2_compiled convey even less
791 information than the file name, so sort them out first. */
793 xf
= (strstr (xn
, "gnu_compiled") != NULL
794 || strstr (xn
, "gcc2_compiled") != NULL
);
795 yf
= (strstr (yn
, "gnu_compiled") != NULL
796 || strstr (yn
, "gcc2_compiled") != NULL
);
803 /* We use a heuristic for the file name. It may not work on non
804 Unix systems, but it doesn't really matter; the only difference
805 is precisely which symbol names get printed. */
807 #define file_symbol(s, sn, snl) \
808 (((s)->flags & BSF_FILE) != 0 \
809 || ((sn)[(snl) - 2] == '.' \
810 && ((sn)[(snl) - 1] == 'o' \
811 || (sn)[(snl) - 1] == 'a')))
813 xf
= file_symbol (x
, xn
, xnl
);
814 yf
= file_symbol (y
, yn
, ynl
);
821 return non_numeric_forward (P_x
, P_y
);
824 /* This sort routine is used by sort_symbols_by_size. It is sorting
825 an array of size_sym structures into size order. */
828 size_forward2 (P_x
, P_y
)
832 const struct size_sym
*x
= (const struct size_sym
*) P_x
;
833 const struct size_sym
*y
= (const struct size_sym
*) P_y
;
835 if (x
->size
< y
->size
)
836 return reverse_sort
? 1 : -1;
837 else if (x
->size
> y
->size
)
838 return reverse_sort
? -1 : 1;
840 return sorters
[0][reverse_sort
] (x
->minisym
, y
->minisym
);
843 /* Sort the symbols by size. ELF provides a size but for other formats
844 we have to make a guess by assuming that the difference between the
845 address of a symbol and the address of the next higher symbol is the
849 sort_symbols_by_size (abfd
, dynamic
, minisyms
, symcount
, size
, symsizesp
)
855 struct size_sym
**symsizesp
;
857 struct size_sym
*symsizes
;
858 bfd_byte
*from
, *fromend
;
860 asymbol
*store_sym
, *store_next
;
862 qsort (minisyms
, symcount
, size
, size_forward1
);
864 /* We are going to return a special set of symbols and sizes to
866 symsizes
= (struct size_sym
*) xmalloc (symcount
* sizeof (struct size_sym
));
867 *symsizesp
= symsizes
;
869 /* Note that filter_symbols has already removed all absolute and
870 undefined symbols. Here we remove all symbols whose size winds
873 from
= (bfd_byte
*) minisyms
;
874 fromend
= from
+ symcount
* size
;
881 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, (const PTR
) from
,
884 bfd_fatal (bfd_get_filename (abfd
));
887 for (; from
< fromend
; from
+= size
)
894 if (from
+ size
< fromend
)
896 next
= bfd_minisymbol_to_symbol (abfd
,
898 (const PTR
) (from
+ size
),
901 bfd_fatal (bfd_get_filename (abfd
));
906 sec
= bfd_get_section (sym
);
908 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
909 sz
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
910 else if (bfd_is_com_section (sec
))
914 if (from
+ size
< fromend
915 && sec
== bfd_get_section (next
))
916 sz
= valueof (next
) - valueof (sym
);
918 sz
= (bfd_get_section_vma (abfd
, sec
)
919 + bfd_section_size (abfd
, sec
)
925 symsizes
->minisym
= (const PTR
) from
;
933 store_sym
= store_next
;
937 symcount
= symsizes
- *symsizesp
;
939 /* We must now sort again by size. */
940 qsort ((PTR
) *symsizesp
, symcount
, sizeof (struct size_sym
), size_forward2
);
945 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */
948 display_rel_file (abfd
, archive_bfd
)
955 struct size_sym
*symsizes
;
960 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
962 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
967 symcount
= bfd_read_minisymbols (abfd
, dynamic
, &minisyms
, &size
);
969 bfd_fatal (bfd_get_filename (abfd
));
973 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
977 bfd_sprintf_vma (abfd
, buf
, (bfd_vma
) -1);
978 print_width
= strlen (buf
);
980 /* Discard the symbols we don't want to print.
981 It's OK to do this in place; we'll free the storage anyway
984 symcount
= filter_symbols (abfd
, dynamic
, minisyms
, symcount
, size
);
990 sort_dynamic
= dynamic
;
991 sort_x
= bfd_make_empty_symbol (abfd
);
992 sort_y
= bfd_make_empty_symbol (abfd
);
993 if (sort_x
== NULL
|| sort_y
== NULL
)
994 bfd_fatal (bfd_get_filename (abfd
));
997 qsort (minisyms
, symcount
, size
,
998 sorters
[sort_numerically
][reverse_sort
]);
1000 symcount
= sort_symbols_by_size (abfd
, dynamic
, minisyms
, symcount
,
1005 print_symbols (abfd
, dynamic
, minisyms
, symcount
, size
, archive_bfd
);
1007 print_size_symbols (abfd
, dynamic
, symsizes
, symcount
, archive_bfd
);
1012 /* Choose which symbol entries to print;
1013 compact them downward to get rid of the rest.
1014 Return the number of symbols to be printed. */
1017 filter_symbols (abfd
, dynamic
, minisyms
, symcount
, size
)
1024 bfd_byte
*from
, *fromend
, *to
;
1027 store
= bfd_make_empty_symbol (abfd
);
1029 bfd_fatal (bfd_get_filename (abfd
));
1031 from
= (bfd_byte
*) minisyms
;
1032 fromend
= from
+ symcount
* size
;
1033 to
= (bfd_byte
*) minisyms
;
1035 for (; from
< fromend
; from
+= size
)
1042 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, (const PTR
) from
, store
);
1044 bfd_fatal (bfd_get_filename (abfd
));
1047 keep
= bfd_is_und_section (sym
->section
);
1048 else if (external_only
)
1049 keep
= ((sym
->flags
& BSF_GLOBAL
) != 0
1050 || (sym
->flags
& BSF_WEAK
) != 0
1051 || bfd_is_und_section (sym
->section
)
1052 || bfd_is_com_section (sym
->section
));
1057 && ! print_debug_syms
1058 && (sym
->flags
& BSF_DEBUGGING
) != 0)
1063 && (bfd_is_abs_section (sym
->section
)
1064 || bfd_is_und_section (sym
->section
)))
1070 if (bfd_is_und_section (sym
->section
))
1076 memcpy (to
, from
, size
);
1081 return (to
- (bfd_byte
*) minisyms
) / size
;
1084 /* Print symbol name NAME, read from ABFD, with printf format FORMAT,
1085 demangling it if requested. */
1088 print_symname (format
, name
, abfd
)
1093 if (do_demangle
&& *name
)
1097 /* In this mode, give a user-level view of the symbol name
1098 even if it's not mangled; strip off any leading
1100 if (bfd_get_symbol_leading_char (abfd
) == name
[0])
1103 res
= cplus_demangle (name
, DMGL_ANSI
| DMGL_PARAMS
);
1106 printf (format
, res
);
1112 printf (format
, name
);
1115 /* Print the symbols. If ARCHIVE_BFD is non-NULL, it is the archive
1119 print_symbols (abfd
, dynamic
, minisyms
, symcount
, size
, archive_bfd
)
1128 bfd_byte
*from
, *fromend
;
1130 store
= bfd_make_empty_symbol (abfd
);
1132 bfd_fatal (bfd_get_filename (abfd
));
1134 from
= (bfd_byte
*) minisyms
;
1135 fromend
= from
+ symcount
* size
;
1136 for (; from
< fromend
; from
+= size
)
1140 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, from
, store
);
1142 bfd_fatal (bfd_get_filename (abfd
));
1144 print_symbol (abfd
, sym
, archive_bfd
);
1148 /* Print the symbols when sorting by size. */
1151 print_size_symbols (abfd
, dynamic
, symsizes
, symcount
, archive_bfd
)
1154 struct size_sym
*symsizes
;
1159 struct size_sym
*from
, *fromend
;
1161 store
= bfd_make_empty_symbol (abfd
);
1163 bfd_fatal (bfd_get_filename (abfd
));
1166 fromend
= from
+ symcount
;
1167 for (; from
< fromend
; from
++)
1171 sym
= bfd_minisymbol_to_symbol (abfd
, dynamic
, from
->minisym
, store
);
1173 bfd_fatal (bfd_get_filename (abfd
));
1175 /* Set the symbol value so that we actually display the symbol
1177 sym
->value
= from
->size
- bfd_section_vma (abfd
, bfd_get_section (sym
));
1179 print_symbol (abfd
, sym
, archive_bfd
);
1183 /* Print a single symbol. */
1186 print_symbol (abfd
, sym
, archive_bfd
)
1193 (*format
->print_symbol_filename
) (archive_bfd
, abfd
);
1197 if (bfd_is_und_section (bfd_get_section (sym
)))
1198 print_symname ("%s", bfd_asymbol_name (sym
), abfd
);
1202 symbol_info syminfo
;
1204 bfd_get_symbol_info (abfd
, sym
, &syminfo
);
1205 (*format
->print_symbol_info
) (&syminfo
, abfd
);
1210 static asymbol
**syms
;
1211 static long symcount
;
1212 const char *filename
, *functionname
;
1213 unsigned int lineno
;
1215 /* We need to get the canonical symbols in order to call
1216 bfd_find_nearest_line. This is inefficient, but, then, you
1217 don't have to use --line-numbers. */
1218 if (abfd
!= lineno_cache_bfd
&& syms
!= NULL
)
1227 symsize
= bfd_get_symtab_upper_bound (abfd
);
1229 bfd_fatal (bfd_get_filename (abfd
));
1230 syms
= (asymbol
**) xmalloc (symsize
);
1231 symcount
= bfd_canonicalize_symtab (abfd
, syms
);
1233 bfd_fatal (bfd_get_filename (abfd
));
1234 lineno_cache_bfd
= abfd
;
1237 if (bfd_is_und_section (bfd_get_section (sym
)))
1239 static asection
**secs
;
1240 static arelent
***relocs
;
1241 static long *relcount
;
1242 static unsigned int seccount
;
1244 const char *symname
;
1246 /* For an undefined symbol, we try to find a reloc for the
1247 symbol, and print the line number of the reloc. */
1249 if (abfd
!= lineno_cache_rel_bfd
&& relocs
!= NULL
)
1251 for (i
= 0; i
< seccount
; i
++)
1252 if (relocs
[i
] != NULL
)
1264 struct get_relocs_info info
;
1266 seccount
= bfd_count_sections (abfd
);
1268 secs
= (asection
**) xmalloc (seccount
* sizeof *secs
);
1269 relocs
= (arelent
***) xmalloc (seccount
* sizeof *relocs
);
1270 relcount
= (long *) xmalloc (seccount
* sizeof *relcount
);
1273 info
.relocs
= relocs
;
1274 info
.relcount
= relcount
;
1276 bfd_map_over_sections (abfd
, get_relocs
, (PTR
) &info
);
1277 lineno_cache_rel_bfd
= abfd
;
1280 symname
= bfd_asymbol_name (sym
);
1281 for (i
= 0; i
< seccount
; i
++)
1285 for (j
= 0; j
< relcount
[i
]; j
++)
1290 if (r
->sym_ptr_ptr
!= NULL
1291 && (*r
->sym_ptr_ptr
)->section
== sym
->section
1292 && (*r
->sym_ptr_ptr
)->value
== sym
->value
1294 bfd_asymbol_name (*r
->sym_ptr_ptr
)) == 0
1295 && bfd_find_nearest_line (abfd
, secs
[i
], syms
,
1296 r
->address
, &filename
,
1297 &functionname
, &lineno
)
1298 && filename
!= NULL
)
1300 /* We only print the first one we find. */
1301 printf ("\t%s:%u", filename
, lineno
);
1308 else if (bfd_get_section (sym
)->owner
== abfd
)
1310 if (bfd_find_nearest_line (abfd
, bfd_get_section (sym
), syms
,
1311 sym
->value
, &filename
, &functionname
,
1316 printf ("\t%s:%u", filename
, lineno
);
1324 /* The following 3 groups of functions are called unconditionally,
1325 once at the start of processing each file of the appropriate type.
1326 They should check `filename_per_file' and `filename_per_symbol',
1327 as appropriate for their output format, to determine whether to
1330 /* Print the name of an object file given on the command line. */
1333 print_object_filename_bsd (filename
)
1336 if (filename_per_file
&& !filename_per_symbol
)
1337 printf ("\n%s:\n", filename
);
1341 print_object_filename_sysv (filename
)
1345 printf (_("\n\nUndefined symbols from %s:\n\n"), filename
);
1347 printf (_("\n\nSymbols from %s:\n\n"), filename
);
1349 Name Value Class Type Size Line Section\n\n"));
1353 print_object_filename_posix (filename
)
1356 if (filename_per_file
&& !filename_per_symbol
)
1357 printf ("%s:\n", filename
);
1360 /* Print the name of an archive file given on the command line. */
1363 print_archive_filename_bsd (filename
)
1366 if (filename_per_file
)
1367 printf ("\n%s:\n", filename
);
1371 print_archive_filename_sysv (filename
)
1372 char *filename ATTRIBUTE_UNUSED
;
1377 print_archive_filename_posix (filename
)
1378 char *filename ATTRIBUTE_UNUSED
;
1382 /* Print the name of an archive member file. */
1385 print_archive_member_bsd (archive
, filename
)
1386 char *archive ATTRIBUTE_UNUSED
;
1387 CONST
char *filename
;
1389 if (!filename_per_symbol
)
1390 printf ("\n%s:\n", filename
);
1394 print_archive_member_sysv (archive
, filename
)
1396 CONST
char *filename
;
1399 printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive
, filename
);
1401 printf (_("\n\nSymbols from %s[%s]:\n\n"), archive
, filename
);
1403 Name Value Class Type Size Line Section\n\n"));
1407 print_archive_member_posix (archive
, filename
)
1409 CONST
char *filename
;
1411 if (!filename_per_symbol
)
1412 printf ("%s[%s]:\n", archive
, filename
);
1415 /* Print the name of the file (and archive, if there is one)
1416 containing a symbol. */
1419 print_symbol_filename_bsd (archive_bfd
, abfd
)
1420 bfd
*archive_bfd
, *abfd
;
1422 if (filename_per_symbol
)
1425 printf ("%s:", bfd_get_filename (archive_bfd
));
1426 printf ("%s:", bfd_get_filename (abfd
));
1431 print_symbol_filename_sysv (archive_bfd
, abfd
)
1432 bfd
*archive_bfd
, *abfd
;
1434 if (filename_per_symbol
)
1437 printf ("%s:", bfd_get_filename (archive_bfd
));
1438 printf ("%s:", bfd_get_filename (abfd
));
1443 print_symbol_filename_posix (archive_bfd
, abfd
)
1444 bfd
*archive_bfd
, *abfd
;
1446 if (filename_per_symbol
)
1449 printf ("%s[%s]: ", bfd_get_filename (archive_bfd
),
1450 bfd_get_filename (abfd
));
1452 printf ("%s: ", bfd_get_filename (abfd
));
1456 /* Print a symbol value. */
1459 print_value (abfd
, val
)
1460 bfd
*abfd ATTRIBUTE_UNUSED
;
1463 #if ! defined (BFD64) || BFD_HOST_64BIT_LONG
1464 printf (value_format
, val
);
1466 /* We have a 64 bit value to print, but the host is only 32 bit. */
1467 if (print_radix
== 16)
1468 bfd_fprintf_vma (abfd
, stdout
, val
);
1474 s
= buf
+ sizeof buf
;
1478 *--s
= (val
% print_radix
) + '0';
1481 while ((buf
+ sizeof buf
- 1) - s
< 16)
1488 /* Print a line of information about a symbol. */
1491 print_symbol_info_bsd (info
, abfd
)
1495 if (bfd_is_undefined_symclass (info
->type
))
1497 if (print_width
== 16)
1502 print_value (abfd
, info
->value
);
1503 printf (" %c", info
->type
);
1504 if (info
->type
== '-')
1508 printf (other_format
, info
->stab_other
);
1510 printf (desc_format
, info
->stab_desc
);
1511 printf (" %5s", info
->stab_name
);
1513 print_symname (" %s", info
->name
, abfd
);
1517 print_symbol_info_sysv (info
, abfd
)
1521 print_symname ("%-20s|", info
->name
, abfd
); /* Name */
1522 if (bfd_is_undefined_symclass (info
->type
))
1523 printf (" "); /* Value */
1525 print_value (abfd
, info
->value
);
1526 printf ("| %c |", info
->type
); /* Class */
1527 if (info
->type
== '-')
1530 printf ("%18s| ", info
->stab_name
); /* (C) Type */
1531 printf (desc_format
, info
->stab_desc
); /* Size */
1532 printf ("| |"); /* Line, Section */
1535 printf (" | | |"); /* Type, Size, Line, Section */
1539 print_symbol_info_posix (info
, abfd
)
1543 print_symname ("%s ", info
->name
, abfd
);
1544 printf ("%c ", info
->type
);
1545 if (bfd_is_undefined_symclass (info
->type
))
1548 print_value (abfd
, info
->value
);
1549 /* POSIX.2 wants the symbol size printed here, when applicable;
1550 BFD currently doesn't provide it, so we take the easy way out by
1551 considering it to never be applicable. */
1555 print_symdef_entry (abfd
)
1558 symindex idx
= BFD_NO_MORE_SYMBOLS
;
1560 boolean everprinted
= false;
1562 for (idx
= bfd_get_next_mapent (abfd
, idx
, &thesym
);
1563 idx
!= BFD_NO_MORE_SYMBOLS
;
1564 idx
= bfd_get_next_mapent (abfd
, idx
, &thesym
))
1569 printf (_("\nArchive index:\n"));
1572 elt
= bfd_get_elt_at_index (abfd
, idx
);
1574 bfd_fatal ("bfd_get_elt_at_index");
1575 if (thesym
->name
!= (char *) NULL
)
1577 print_symname ("%s", thesym
->name
, abfd
);
1578 printf (" in %s\n", bfd_get_filename (elt
));
1583 /* This function is used to get the relocs for a particular section.
1584 It is called via bfd_map_over_sections. */
1587 get_relocs (abfd
, sec
, dataarg
)
1592 struct get_relocs_info
*data
= (struct get_relocs_info
*) dataarg
;
1596 if ((sec
->flags
& SEC_RELOC
) == 0)
1598 *data
->relocs
= NULL
;
1599 *data
->relcount
= 0;
1605 relsize
= bfd_get_reloc_upper_bound (abfd
, sec
);
1607 bfd_fatal (bfd_get_filename (abfd
));
1609 *data
->relocs
= (arelent
**) xmalloc (relsize
);
1610 *data
->relcount
= bfd_canonicalize_reloc (abfd
, sec
, *data
->relocs
,
1612 if (*data
->relcount
< 0)
1613 bfd_fatal (bfd_get_filename (abfd
));