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