/src/binutils-gdb/binutils/fuzz_nm.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* nm.c -- Describe symbol table of a rel file. |
2 | | Copyright (C) 1991-2023 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of GNU Binutils. |
5 | | |
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 3 of the License, or |
9 | | (at your option) any later version. |
10 | | |
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. |
15 | | |
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., 51 Franklin Street - Fifth Floor, Boston, MA |
19 | | 02110-1301, USA. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include "bfd.h" |
23 | | #include "getopt.h" |
24 | | #include "aout/stab_gnu.h" |
25 | | #include "aout/ranlib.h" |
26 | | #include "demangle.h" |
27 | | #include "libiberty.h" |
28 | | #include "elf-bfd.h" |
29 | | #include "elf/common.h" |
30 | | #define DO_NOT_DEFINE_AOUTHDR |
31 | | #define DO_NOT_DEFINE_FILHDR |
32 | | #define DO_NOT_DEFINE_LINENO |
33 | | #define DO_NOT_DEFINE_SCNHDR |
34 | | #include "coff/external.h" |
35 | | #include "coff/internal.h" |
36 | | #include "libcoff.h" |
37 | | #include "bucomm.h" |
38 | | #include "demanguse.h" |
39 | | #include "plugin-api.h" |
40 | | #include "plugin.h" |
41 | | #include "safe-ctype.h" |
42 | | |
43 | | #ifndef streq |
44 | 0 | #define streq(a,b) (strcmp ((a),(b)) == 0) |
45 | | #endif |
46 | | |
47 | | /* When sorting by size, we use this structure to hold the size and a |
48 | | pointer to the minisymbol. */ |
49 | | |
50 | | struct size_sym |
51 | | { |
52 | | const void *minisym; |
53 | | bfd_vma size; |
54 | | }; |
55 | | |
56 | | /* line number related info cached in bfd usrdata. */ |
57 | | |
58 | | struct lineno_cache |
59 | | { |
60 | | asection **secs; |
61 | | arelent ***relocs; |
62 | | long *relcount; |
63 | | asymbol **syms; |
64 | | long symcount; |
65 | | unsigned int seccount; |
66 | | }; |
67 | | |
68 | | struct extended_symbol_info |
69 | | { |
70 | | symbol_info *sinfo; |
71 | | bfd_vma ssize; |
72 | | elf_symbol_type *elfinfo; |
73 | | coff_symbol_type *coffinfo; |
74 | | /* FIXME: We should add more fields for Type, Line, Section. */ |
75 | | }; |
76 | 1.29M | #define SYM_VALUE(sym) (sym->sinfo->value) |
77 | 4.18M | #define SYM_TYPE(sym) (sym->sinfo->type) |
78 | 4.64k | #define SYM_STAB_NAME(sym) (sym->sinfo->stab_name) |
79 | 4.64k | #define SYM_STAB_DESC(sym) (sym->sinfo->stab_desc) |
80 | 4.64k | #define SYM_STAB_OTHER(sym) (sym->sinfo->stab_other) |
81 | | #define SYM_SIZE(sym) \ |
82 | 0 | (sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize) |
83 | | |
84 | | /* The output formatting functions. */ |
85 | | static void print_object_filename_bsd (const char *); |
86 | | static void print_object_filename_sysv (const char *); |
87 | | static void print_object_filename_posix (const char *); |
88 | | static void do_not_print_object_filename (const char *); |
89 | | |
90 | | static void print_archive_filename_bsd (const char *); |
91 | | static void print_archive_filename_sysv (const char *); |
92 | | static void print_archive_filename_posix (const char *); |
93 | | static void do_not_print_archive_filename (const char *); |
94 | | |
95 | | static void print_archive_member_bsd (const char *, const char *); |
96 | | static void print_archive_member_sysv (const char *, const char *); |
97 | | static void print_archive_member_posix (const char *, const char *); |
98 | | static void do_not_print_archive_member (const char *, const char *); |
99 | | |
100 | | static void print_symbol_filename_bsd (bfd *, bfd *); |
101 | | static void print_symbol_filename_sysv (bfd *, bfd *); |
102 | | static void print_symbol_filename_posix (bfd *, bfd *); |
103 | | static void do_not_print_symbol_filename (bfd *, bfd *); |
104 | | |
105 | | static void print_symbol_info_bsd (struct extended_symbol_info *, bfd *); |
106 | | static void print_symbol_info_sysv (struct extended_symbol_info *, bfd *); |
107 | | static void print_symbol_info_posix (struct extended_symbol_info *, bfd *); |
108 | | static void just_print_symbol_name (struct extended_symbol_info *, bfd *); |
109 | | |
110 | | static void print_value (bfd *, bfd_vma); |
111 | | |
112 | | /* Support for different output formats. */ |
113 | | struct output_fns |
114 | | { |
115 | | /* Print the name of an object file given on the command line. */ |
116 | | void (*print_object_filename) (const char *); |
117 | | |
118 | | /* Print the name of an archive file given on the command line. */ |
119 | | void (*print_archive_filename) (const char *); |
120 | | |
121 | | /* Print the name of an archive member file. */ |
122 | | void (*print_archive_member) (const char *, const char *); |
123 | | |
124 | | /* Print the name of the file (and archive, if there is one) |
125 | | containing a symbol. */ |
126 | | void (*print_symbol_filename) (bfd *, bfd *); |
127 | | |
128 | | /* Print a line of information about a symbol. */ |
129 | | void (*print_symbol_info) (struct extended_symbol_info *, bfd *); |
130 | | }; |
131 | | |
132 | | /* Indices in `formats'. */ |
133 | | enum formats |
134 | | { |
135 | | FORMAT_BSD = 0, |
136 | | FORMAT_SYSV, |
137 | | FORMAT_POSIX, |
138 | | FORMAT_JUST_SYMBOLS, |
139 | | FORMAT_MAX |
140 | | }; |
141 | | |
142 | | #define FORMAT_DEFAULT FORMAT_BSD |
143 | | |
144 | | static const struct output_fns formats[FORMAT_MAX] = |
145 | | { |
146 | | {print_object_filename_bsd, |
147 | | print_archive_filename_bsd, |
148 | | print_archive_member_bsd, |
149 | | print_symbol_filename_bsd, |
150 | | print_symbol_info_bsd}, |
151 | | {print_object_filename_sysv, |
152 | | print_archive_filename_sysv, |
153 | | print_archive_member_sysv, |
154 | | print_symbol_filename_sysv, |
155 | | print_symbol_info_sysv}, |
156 | | {print_object_filename_posix, |
157 | | print_archive_filename_posix, |
158 | | print_archive_member_posix, |
159 | | print_symbol_filename_posix, |
160 | | print_symbol_info_posix}, |
161 | | {do_not_print_object_filename, |
162 | | do_not_print_archive_filename, |
163 | | do_not_print_archive_member, |
164 | | do_not_print_symbol_filename, |
165 | | just_print_symbol_name} |
166 | | }; |
167 | | |
168 | | |
169 | | /* The output format to use. */ |
170 | | static const struct output_fns *format = &formats[FORMAT_DEFAULT]; |
171 | | static unsigned int print_format = FORMAT_DEFAULT; |
172 | | static const char *print_format_string = NULL; |
173 | | |
174 | | /* Command options. */ |
175 | | |
176 | | static int do_demangle = 0; /* Pretty print C++ symbol names. */ |
177 | | static int external_only = 0; /* Print external symbols only. */ |
178 | | static int defined_only = 0; /* Print defined symbols only. */ |
179 | | static int non_weak = 0; /* Ignore weak symbols. */ |
180 | | static int no_sort = 0; /* Don't sort; print syms in order found. */ |
181 | | static int print_debug_syms = 0;/* Print debugger-only symbols too. */ |
182 | | static int print_armap = 0; /* Describe __.SYMDEF data in archive files. */ |
183 | | static int print_size = 0; /* Print size of defined symbols. */ |
184 | | static int reverse_sort = 0; /* Sort in downward(alpha or numeric) order. */ |
185 | | static int sort_numerically = 0;/* Sort in numeric rather than alpha order. */ |
186 | | static int sort_by_size = 0; /* Sort by size of symbol. */ |
187 | | static int undefined_only = 0; /* Print undefined symbols only. */ |
188 | | static int dynamic = 0; /* Print dynamic symbols. */ |
189 | | static int show_version = 0; /* Show the version number. */ |
190 | | static int show_synthetic = 0; /* Display synthesized symbols too. */ |
191 | | static int line_numbers = 0; /* Print line numbers for symbols. */ |
192 | | static int allow_special_symbols = 0; /* Allow special symbols. */ |
193 | | static int with_symbol_versions = -1; /* Output symbol version information. */ |
194 | | static int quiet = 0; /* Suppress "no symbols" diagnostic. */ |
195 | | |
196 | | /* The characters to use for global and local ifunc symbols. */ |
197 | | #if DEFAULT_F_FOR_IFUNC_SYMBOLS |
198 | | static const char * ifunc_type_chars = "Ff"; |
199 | | #else |
200 | | static const char * ifunc_type_chars = NULL; |
201 | | #endif |
202 | | |
203 | | static int demangle_flags = DMGL_ANSI | DMGL_PARAMS; |
204 | | |
205 | | /* When to print the names of files. Not mutually exclusive in SYSV format. */ |
206 | | static int filename_per_file = 0; /* Once per file, on its own line. */ |
207 | | static int filename_per_symbol = 0; /* Once per symbol, at start of line. */ |
208 | | |
209 | | static int print_width = 0; |
210 | | static int print_radix = 16; |
211 | | /* Print formats for printing stab info. */ |
212 | | static char other_format[] = "%02x"; |
213 | | static char desc_format[] = "%04x"; |
214 | | |
215 | | static char *target = NULL; |
216 | | #if BFD_SUPPORTS_PLUGINS |
217 | | static const char *plugin_target = "plugin"; |
218 | | #else |
219 | | static const char *plugin_target = NULL; |
220 | | #endif |
221 | | |
222 | | typedef enum unicode_display_type |
223 | | { |
224 | | unicode_default = 0, |
225 | | unicode_locale, |
226 | | unicode_escape, |
227 | | unicode_hex, |
228 | | unicode_highlight, |
229 | | unicode_invalid |
230 | | } unicode_display_type; |
231 | | |
232 | | static unicode_display_type unicode_display = unicode_default; |
233 | | |
234 | | enum long_option_values |
235 | | { |
236 | | OPTION_TARGET = 200, |
237 | | OPTION_PLUGIN, |
238 | | OPTION_SIZE_SORT, |
239 | | OPTION_RECURSE_LIMIT, |
240 | | OPTION_NO_RECURSE_LIMIT, |
241 | | OPTION_IFUNC_CHARS, |
242 | | OPTION_UNICODE, |
243 | | OPTION_QUIET |
244 | | }; |
245 | | |
246 | | static struct option long_options[] = |
247 | | { |
248 | | {"debug-syms", no_argument, &print_debug_syms, 1}, |
249 | | {"demangle", optional_argument, 0, 'C'}, |
250 | | {"dynamic", no_argument, &dynamic, 1}, |
251 | | {"extern-only", no_argument, &external_only, 1}, |
252 | | {"format", required_argument, 0, 'f'}, |
253 | | {"help", no_argument, 0, 'h'}, |
254 | | {"ifunc-chars", required_argument, 0, OPTION_IFUNC_CHARS}, |
255 | | {"just-symbols", no_argument, 0, 'j'}, |
256 | | {"line-numbers", no_argument, 0, 'l'}, |
257 | | {"no-cplus", no_argument, &do_demangle, 0}, /* Linux compatibility. */ |
258 | | {"no-demangle", no_argument, &do_demangle, 0}, |
259 | | {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, |
260 | | {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT}, |
261 | | {"no-sort", no_argument, 0, 'p'}, |
262 | | {"numeric-sort", no_argument, 0, 'n'}, |
263 | | {"plugin", required_argument, 0, OPTION_PLUGIN}, |
264 | | {"portability", no_argument, 0, 'P'}, |
265 | | {"print-armap", no_argument, &print_armap, 1}, |
266 | | {"print-file-name", no_argument, 0, 'o'}, |
267 | | {"print-size", no_argument, 0, 'S'}, |
268 | | {"quiet", no_argument, 0, OPTION_QUIET}, |
269 | | {"radix", required_argument, 0, 't'}, |
270 | | {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, |
271 | | {"recursion-limit", no_argument, NULL, OPTION_RECURSE_LIMIT}, |
272 | | {"reverse-sort", no_argument, &reverse_sort, 1}, |
273 | | {"size-sort", no_argument, 0, OPTION_SIZE_SORT}, |
274 | | {"special-syms", no_argument, &allow_special_symbols, 1}, |
275 | | {"synthetic", no_argument, &show_synthetic, 1}, |
276 | | {"target", required_argument, 0, OPTION_TARGET}, |
277 | | {"defined-only", no_argument, 0, 'U'}, |
278 | | {"undefined-only", no_argument, 0, 'u'}, |
279 | | {"unicode", required_argument, NULL, OPTION_UNICODE}, |
280 | | {"version", no_argument, &show_version, 1}, |
281 | | {"no-weak", no_argument, 0, 'W'}, |
282 | | {"with-symbol-versions", no_argument, &with_symbol_versions, 1}, |
283 | | {"without-symbol-versions", no_argument, &with_symbol_versions, 0}, |
284 | | {0, no_argument, 0, 0} |
285 | | }; |
286 | | |
287 | | /* Some error-reporting functions. */ |
288 | | |
289 | | ATTRIBUTE_NORETURN static void |
290 | | usage (FILE *stream, int status) |
291 | 0 | { |
292 | 0 | fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name); |
293 | 0 | fprintf (stream, _(" List symbols in [file(s)] (a.out by default).\n")); |
294 | 0 | fprintf (stream, _(" The options are:\n")); |
295 | 0 | fprintf (stream, _("\ |
296 | 0 | -a, --debug-syms Display debugger-only symbols\n")); |
297 | 0 | fprintf (stream, _("\ |
298 | 0 | -A, --print-file-name Print name of the input file before every symbol\n")); |
299 | 0 | fprintf (stream, _("\ |
300 | 0 | -B Same as --format=bsd\n")); |
301 | 0 | fprintf (stream, _("\ |
302 | 0 | -C, --demangle[=STYLE] Decode mangled/processed symbol names\n")); |
303 | 0 | display_demangler_styles (stream, _("\ |
304 | 0 | STYLE can be ")); |
305 | 0 | fprintf (stream, _("\ |
306 | 0 | --no-demangle Do not demangle low-level symbol names\n")); |
307 | 0 | fprintf (stream, _("\ |
308 | 0 | --recurse-limit Enable a demangling recursion limit. (default)\n")); |
309 | 0 | fprintf (stream, _("\ |
310 | 0 | --no-recurse-limit Disable a demangling recursion limit.\n")); |
311 | 0 | fprintf (stream, _("\ |
312 | 0 | -D, --dynamic Display dynamic symbols instead of normal symbols\n")); |
313 | 0 | fprintf (stream, _("\ |
314 | 0 | -e (ignored)\n")); |
315 | 0 | fprintf (stream, _("\ |
316 | 0 | -f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',\n\ |
317 | 0 | `sysv', `posix' or 'just-symbols'.\n\ |
318 | 0 | The default is `bsd'\n")); |
319 | 0 | fprintf (stream, _("\ |
320 | 0 | -g, --extern-only Display only external symbols\n")); |
321 | 0 | fprintf (stream, _("\ |
322 | 0 | --ifunc-chars=CHARS Characters to use when displaying ifunc symbols\n")); |
323 | 0 | fprintf (stream, _("\ |
324 | 0 | -j, --just-symbols Same as --format=just-symbols\n")); |
325 | 0 | fprintf (stream, _("\ |
326 | 0 | -l, --line-numbers Use debugging information to find a filename and\n\ |
327 | 0 | line number for each symbol\n")); |
328 | 0 | fprintf (stream, _("\ |
329 | 0 | -n, --numeric-sort Sort symbols numerically by address\n")); |
330 | 0 | fprintf (stream, _("\ |
331 | 0 | -o Same as -A\n")); |
332 | 0 | fprintf (stream, _("\ |
333 | 0 | -p, --no-sort Do not sort the symbols\n")); |
334 | 0 | fprintf (stream, _("\ |
335 | 0 | -P, --portability Same as --format=posix\n")); |
336 | 0 | fprintf (stream, _("\ |
337 | 0 | -r, --reverse-sort Reverse the sense of the sort\n")); |
338 | 0 | #if BFD_SUPPORTS_PLUGINS |
339 | 0 | fprintf (stream, _("\ |
340 | 0 | --plugin NAME Load the specified plugin\n")); |
341 | 0 | #endif |
342 | 0 | fprintf (stream, _("\ |
343 | 0 | -S, --print-size Print size of defined symbols\n")); |
344 | 0 | fprintf (stream, _("\ |
345 | 0 | -s, --print-armap Include index for symbols from archive members\n")); |
346 | 0 | fprintf (stream, _("\ |
347 | 0 | --quiet Suppress \"no symbols\" diagnostic\n")); |
348 | 0 | fprintf (stream, _("\ |
349 | 0 | --size-sort Sort symbols by size\n")); |
350 | 0 | fprintf (stream, _("\ |
351 | 0 | --special-syms Include special symbols in the output\n")); |
352 | 0 | fprintf (stream, _("\ |
353 | 0 | --synthetic Display synthetic symbols as well\n")); |
354 | 0 | fprintf (stream, _("\ |
355 | 0 | -t, --radix=RADIX Use RADIX for printing symbol values\n")); |
356 | 0 | fprintf (stream, _("\ |
357 | 0 | --target=BFDNAME Specify the target object format as BFDNAME\n")); |
358 | 0 | fprintf (stream, _("\ |
359 | 0 | -u, --undefined-only Display only undefined symbols\n")); |
360 | 0 | fprintf (stream, _("\ |
361 | 0 | -U, --defined-only Display only defined symbols\n")); |
362 | 0 | fprintf (stream, _("\ |
363 | 0 | --unicode={default|show|invalid|hex|escape|highlight}\n\ |
364 | 0 | Specify how to treat UTF-8 encoded unicode characters\n")); |
365 | 0 | fprintf (stream, _("\ |
366 | 0 | -W, --no-weak Ignore weak symbols\n")); |
367 | 0 | fprintf (stream, _("\ |
368 | 0 | --with-symbol-versions Display version strings after symbol names\n")); |
369 | 0 | fprintf (stream, _("\ |
370 | 0 | -X 32_64 (ignored)\n")); |
371 | 0 | fprintf (stream, _("\ |
372 | 0 | @FILE Read options from FILE\n")); |
373 | 0 | fprintf (stream, _("\ |
374 | 0 | -h, --help Display this information\n")); |
375 | 0 | fprintf (stream, _("\ |
376 | 0 | -V, --version Display this program's version number\n")); |
377 | |
|
378 | 0 | list_supported_targets (program_name, stream); |
379 | 0 | if (REPORT_BUGS_TO[0] && status == 0) |
380 | 0 | fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO); |
381 | 0 | exit (status); |
382 | 0 | } |
383 | | |
384 | | /* Set the radix for the symbol value and size according to RADIX. */ |
385 | | |
386 | | static void |
387 | | set_print_radix (char *radix) |
388 | 0 | { |
389 | 0 | switch (*radix) |
390 | 0 | { |
391 | 0 | case 'x': print_radix = 16; break; |
392 | 0 | case 'd': print_radix = 10; break; |
393 | 0 | case 'o': print_radix = 8; break; |
394 | | |
395 | 0 | default: |
396 | 0 | fatal (_("%s: invalid radix"), radix); |
397 | 0 | } |
398 | | |
399 | 0 | other_format[3] = desc_format[3] = *radix; |
400 | 0 | } |
401 | | |
402 | | static void |
403 | | set_output_format (char *f) |
404 | 0 | { |
405 | 0 | int i; |
406 | |
|
407 | 0 | switch (*f) |
408 | 0 | { |
409 | 0 | case 'b': |
410 | 0 | case 'B': |
411 | 0 | i = FORMAT_BSD; |
412 | 0 | break; |
413 | 0 | case 'p': |
414 | 0 | case 'P': |
415 | 0 | i = FORMAT_POSIX; |
416 | 0 | break; |
417 | 0 | case 's': |
418 | 0 | case 'S': |
419 | 0 | i = FORMAT_SYSV; |
420 | 0 | break; |
421 | 0 | case 'j': |
422 | 0 | case 'J': |
423 | 0 | i = FORMAT_JUST_SYMBOLS; |
424 | 0 | break; |
425 | 0 | default: |
426 | 0 | fatal (_("%s: invalid output format"), f); |
427 | 0 | } |
428 | 0 | format = &formats[i]; |
429 | 0 | print_format = i; |
430 | 0 | } |
431 | | |
432 | | static const char * |
433 | | get_elf_symbol_type (unsigned int type) |
434 | 0 | { |
435 | 0 | static char *bufp; |
436 | 0 | int n; |
437 | |
|
438 | 0 | switch (type) |
439 | 0 | { |
440 | 0 | case STT_NOTYPE: return "NOTYPE"; |
441 | 0 | case STT_OBJECT: return "OBJECT"; |
442 | 0 | case STT_FUNC: return "FUNC"; |
443 | 0 | case STT_SECTION: return "SECTION"; |
444 | 0 | case STT_FILE: return "FILE"; |
445 | 0 | case STT_COMMON: return "COMMON"; |
446 | 0 | case STT_TLS: return "TLS"; |
447 | 0 | } |
448 | | |
449 | 0 | free (bufp); |
450 | 0 | if (type >= STT_LOPROC && type <= STT_HIPROC) |
451 | 0 | n = asprintf (&bufp, _("<processor specific>: %d"), type); |
452 | 0 | else if (type >= STT_LOOS && type <= STT_HIOS) |
453 | 0 | n = asprintf (&bufp, _("<OS specific>: %d"), type); |
454 | 0 | else |
455 | 0 | n = asprintf (&bufp, _("<unknown>: %d"), type); |
456 | 0 | if (n < 0) |
457 | 0 | fatal ("%s", xstrerror (errno)); |
458 | 0 | return bufp; |
459 | 0 | } |
460 | | |
461 | | static const char * |
462 | | get_coff_symbol_type (const struct internal_syment *sym) |
463 | 0 | { |
464 | 0 | static char *bufp; |
465 | 0 | int n; |
466 | |
|
467 | 0 | switch (sym->n_sclass) |
468 | 0 | { |
469 | 0 | case C_BLOCK: return "Block"; |
470 | 0 | case C_FILE: return "File"; |
471 | 0 | case C_LINE: return "Line"; |
472 | 0 | } |
473 | | |
474 | 0 | if (!sym->n_type) |
475 | 0 | return "None"; |
476 | | |
477 | 0 | switch (DTYPE(sym->n_type)) |
478 | 0 | { |
479 | 0 | case DT_FCN: return "Function"; |
480 | 0 | case DT_PTR: return "Pointer"; |
481 | 0 | case DT_ARY: return "Array"; |
482 | 0 | } |
483 | | |
484 | 0 | free (bufp); |
485 | 0 | n = asprintf (&bufp, _("<unknown>: %d/%d"), sym->n_sclass, sym->n_type); |
486 | 0 | if (n < 0) |
487 | 0 | fatal ("%s", xstrerror (errno)); |
488 | 0 | return bufp; |
489 | 0 | } |
490 | | |
491 | | /* Convert a potential UTF-8 encoded sequence in IN into characters in OUT. |
492 | | The conversion format is controlled by the unicode_display variable. |
493 | | Returns the number of characters added to OUT. |
494 | | Returns the number of bytes consumed from IN in CONSUMED. |
495 | | Always consumes at least one byte and displays at least one character. */ |
496 | | |
497 | | static unsigned int |
498 | | display_utf8 (const unsigned char * in, char * out, unsigned int * consumed) |
499 | 0 | { |
500 | 0 | char * orig_out = out; |
501 | 0 | unsigned int nchars = 0; |
502 | 0 | unsigned int j; |
503 | |
|
504 | 0 | if (unicode_display == unicode_default) |
505 | 0 | goto invalid; |
506 | | |
507 | 0 | if (in[0] < 0xc0) |
508 | 0 | goto invalid; |
509 | | |
510 | 0 | if ((in[1] & 0xc0) != 0x80) |
511 | 0 | goto invalid; |
512 | | |
513 | 0 | if ((in[0] & 0x20) == 0) |
514 | 0 | { |
515 | 0 | nchars = 2; |
516 | 0 | goto valid; |
517 | 0 | } |
518 | | |
519 | 0 | if ((in[2] & 0xc0) != 0x80) |
520 | 0 | goto invalid; |
521 | | |
522 | 0 | if ((in[0] & 0x10) == 0) |
523 | 0 | { |
524 | 0 | nchars = 3; |
525 | 0 | goto valid; |
526 | 0 | } |
527 | | |
528 | 0 | if ((in[3] & 0xc0) != 0x80) |
529 | 0 | goto invalid; |
530 | | |
531 | 0 | nchars = 4; |
532 | |
|
533 | 0 | valid: |
534 | 0 | switch (unicode_display) |
535 | 0 | { |
536 | 0 | case unicode_locale: |
537 | | /* Copy the bytes into the output buffer as is. */ |
538 | 0 | memcpy (out, in, nchars); |
539 | 0 | out += nchars; |
540 | 0 | break; |
541 | | |
542 | 0 | case unicode_invalid: |
543 | 0 | case unicode_hex: |
544 | 0 | *out++ = unicode_display == unicode_hex ? '<' : '{'; |
545 | 0 | *out++ = '0'; |
546 | 0 | *out++ = 'x'; |
547 | 0 | for (j = 0; j < nchars; j++) |
548 | 0 | out += sprintf (out, "%02x", in [j]); |
549 | 0 | *out++ = unicode_display == unicode_hex ? '>' : '}'; |
550 | 0 | break; |
551 | | |
552 | 0 | case unicode_highlight: |
553 | 0 | if (isatty (1)) |
554 | 0 | out += sprintf (out, "\x1B[31;47m"); /* Red. */ |
555 | | /* Fall through. */ |
556 | 0 | case unicode_escape: |
557 | 0 | switch (nchars) |
558 | 0 | { |
559 | 0 | case 2: |
560 | 0 | out += sprintf (out, "\\u%02x%02x", |
561 | 0 | ((in[0] & 0x1c) >> 2), |
562 | 0 | ((in[0] & 0x03) << 6) | (in[1] & 0x3f)); |
563 | 0 | break; |
564 | | |
565 | 0 | case 3: |
566 | 0 | out += sprintf (out, "\\u%02x%02x", |
567 | 0 | ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2), |
568 | 0 | ((in[1] & 0x03) << 6) | ((in[2] & 0x3f))); |
569 | 0 | break; |
570 | | |
571 | 0 | case 4: |
572 | 0 | out += sprintf (out, "\\u%02x%02x%02x", |
573 | 0 | ((in[0] & 0x07) << 6) | ((in[1] & 0x3c) >> 2), |
574 | 0 | ((in[1] & 0x03) << 6) | ((in[2] & 0x3c) >> 2), |
575 | 0 | ((in[2] & 0x03) << 6) | ((in[3] & 0x3f))); |
576 | 0 | break; |
577 | 0 | default: |
578 | | /* URG. */ |
579 | 0 | break; |
580 | 0 | } |
581 | | |
582 | 0 | if (unicode_display == unicode_highlight && isatty (1)) |
583 | 0 | out += sprintf (out, "\x1B[0m"); /* Default colour. */ |
584 | 0 | break; |
585 | | |
586 | 0 | default: |
587 | | /* URG */ |
588 | 0 | break; |
589 | 0 | } |
590 | | |
591 | 0 | * consumed = nchars; |
592 | 0 | return out - orig_out; |
593 | | |
594 | 0 | invalid: |
595 | | /* Not a valid UTF-8 sequence. */ |
596 | 0 | *out = *in; |
597 | 0 | * consumed = 1; |
598 | 0 | return 1; |
599 | 0 | } |
600 | | |
601 | | /* Convert any UTF-8 encoded characters in NAME into the form specified by |
602 | | unicode_display. Also converts control characters. Returns a static |
603 | | buffer if conversion was necessary. |
604 | | Code stolen from objdump.c:sanitize_string(). */ |
605 | | |
606 | | static const char * |
607 | | convert_utf8 (const char * in) |
608 | 0 | { |
609 | 0 | static char * buffer = NULL; |
610 | 0 | static size_t buffer_len = 0; |
611 | 0 | const char * original = in; |
612 | 0 | char * out; |
613 | | |
614 | | /* Paranoia. */ |
615 | 0 | if (in == NULL) |
616 | 0 | return ""; |
617 | | |
618 | | /* See if any conversion is necessary. |
619 | | In the majority of cases it will not be needed. */ |
620 | 0 | do |
621 | 0 | { |
622 | 0 | unsigned char c = *in++; |
623 | |
|
624 | 0 | if (c == 0) |
625 | 0 | return original; |
626 | | |
627 | 0 | if (ISCNTRL (c)) |
628 | 0 | break; |
629 | | |
630 | 0 | if (unicode_display != unicode_default && c >= 0xc0) |
631 | 0 | break; |
632 | 0 | } |
633 | 0 | while (1); |
634 | | |
635 | | /* Copy the input, translating as needed. */ |
636 | 0 | in = original; |
637 | | /* For 2 char unicode, max out is 12 (colour escapes) + 6, ie. 9 per in |
638 | | For hex, max out is 8 for 2 char unicode, ie. 4 per in. |
639 | | 3 and 4 char unicode produce less output for input. */ |
640 | 0 | size_t max_needed = strlen (in) * 9 + 1; |
641 | 0 | if (buffer_len < max_needed) |
642 | 0 | { |
643 | 0 | buffer_len = max_needed; |
644 | 0 | free (buffer); |
645 | 0 | buffer = xmalloc (buffer_len); |
646 | 0 | } |
647 | |
|
648 | 0 | out = buffer; |
649 | 0 | do |
650 | 0 | { |
651 | 0 | unsigned char c = *in++; |
652 | |
|
653 | 0 | if (c == 0) |
654 | 0 | break; |
655 | | |
656 | 0 | if (ISCNTRL (c)) |
657 | 0 | { |
658 | 0 | *out++ = '^'; |
659 | 0 | *out++ = c + 0x40; |
660 | 0 | } |
661 | 0 | else if (unicode_display != unicode_default && c >= 0xc0) |
662 | 0 | { |
663 | 0 | unsigned int num_consumed; |
664 | |
|
665 | 0 | out += display_utf8 ((const unsigned char *) --in, out, &num_consumed); |
666 | 0 | in += num_consumed; |
667 | 0 | } |
668 | 0 | else |
669 | 0 | *out++ = c; |
670 | 0 | } |
671 | 0 | while (1); |
672 | | |
673 | 0 | *out = 0; |
674 | 0 | return buffer; |
675 | 0 | } |
676 | | |
677 | | /* Print symbol name NAME, read from ABFD, with printf format FORM, |
678 | | demangling it if requested. */ |
679 | | |
680 | | static void |
681 | | print_symname (const char *form, struct extended_symbol_info *info, |
682 | | const char *name, bfd *abfd) |
683 | 1.39M | { |
684 | 1.39M | char *alloc = NULL; |
685 | 1.39M | char *atver = NULL; |
686 | | |
687 | 1.39M | if (name == NULL) |
688 | 1.39M | name = info->sinfo->name; |
689 | | |
690 | 1.39M | if (!with_symbol_versions |
691 | 1.39M | && bfd_get_flavour (abfd) == bfd_target_elf_flavour) |
692 | 0 | { |
693 | 0 | atver = strchr (name, '@'); |
694 | 0 | if (atver) |
695 | 0 | *atver = 0; |
696 | 0 | } |
697 | | |
698 | 1.39M | if (do_demangle && *name) |
699 | 0 | { |
700 | 0 | alloc = bfd_demangle (abfd, name, demangle_flags); |
701 | 0 | if (alloc != NULL) |
702 | 0 | name = alloc; |
703 | 0 | } |
704 | | |
705 | 1.39M | if (unicode_display != unicode_default) |
706 | 0 | { |
707 | 0 | name = convert_utf8 (name); |
708 | 0 | } |
709 | | |
710 | 1.39M | if (info != NULL && info->elfinfo && with_symbol_versions) |
711 | 156k | { |
712 | 156k | const char *version_string; |
713 | 156k | bool hidden; |
714 | | |
715 | 156k | version_string |
716 | 156k | = bfd_get_symbol_version_string (abfd, &info->elfinfo->symbol, |
717 | 156k | false, &hidden); |
718 | 156k | if (version_string && version_string[0]) |
719 | 0 | { |
720 | 0 | const char *at = "@@"; |
721 | 0 | if (hidden || bfd_is_und_section (info->elfinfo->symbol.section)) |
722 | 0 | at = "@"; |
723 | 0 | alloc = reconcat (alloc, name, at, version_string, NULL); |
724 | 0 | if (alloc != NULL) |
725 | 0 | name = alloc; |
726 | 0 | } |
727 | 156k | } |
728 | 1.39M | printf (form, name); |
729 | 1.39M | if (atver) |
730 | 0 | *atver = '@'; |
731 | 1.39M | free (alloc); |
732 | 1.39M | } |
733 | | |
734 | | static void |
735 | | print_symdef_entry (bfd *abfd) |
736 | 0 | { |
737 | 0 | symindex idx = BFD_NO_MORE_SYMBOLS; |
738 | 0 | carsym *thesym; |
739 | 0 | bool everprinted = false; |
740 | |
|
741 | 0 | for (idx = bfd_get_next_mapent (abfd, idx, &thesym); |
742 | 0 | idx != BFD_NO_MORE_SYMBOLS; |
743 | 0 | idx = bfd_get_next_mapent (abfd, idx, &thesym)) |
744 | 0 | { |
745 | 0 | if (!everprinted) |
746 | 0 | { |
747 | 0 | printf (_("\nArchive index:\n")); |
748 | 0 | everprinted = true; |
749 | 0 | } |
750 | 0 | if (thesym->name != NULL) |
751 | 0 | { |
752 | 0 | print_symname ("%s", NULL, thesym->name, abfd); |
753 | 0 | bfd *elt = bfd_get_elt_at_index (abfd, idx); |
754 | 0 | if (elt) |
755 | 0 | printf (" in %s\n", bfd_get_filename (elt)); |
756 | 0 | else |
757 | 0 | printf ("\n"); |
758 | 0 | } |
759 | 0 | } |
760 | 0 | } |
761 | | |
762 | | |
763 | | /* True when we can report missing plugin error. */ |
764 | | bool report_plugin_err = true; |
765 | | |
766 | | /* Choose which symbol entries to print; |
767 | | compact them downward to get rid of the rest. |
768 | | Return the number of symbols to be printed. */ |
769 | | |
770 | | static long |
771 | | filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms, |
772 | | long symcount, unsigned int size) |
773 | 2.53k | { |
774 | 2.53k | bfd_byte *from, *fromend, *to; |
775 | 2.53k | asymbol *store; |
776 | | |
777 | 2.53k | store = bfd_make_empty_symbol (abfd); |
778 | 2.53k | if (store == NULL) |
779 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
780 | | |
781 | 2.53k | from = (bfd_byte *) minisyms; |
782 | 2.53k | fromend = from + symcount * size; |
783 | 2.53k | to = (bfd_byte *) minisyms; |
784 | | |
785 | 3.66M | for (; from < fromend; from += size) |
786 | 3.65M | { |
787 | 3.65M | int keep = 0; |
788 | 3.65M | asymbol *sym; |
789 | | |
790 | 3.65M | sym = bfd_minisymbol_to_symbol (abfd, is_dynamic, from, store); |
791 | 3.65M | if (sym == NULL) |
792 | 2.16M | continue; |
793 | | |
794 | 1.49M | if (sym->name != NULL |
795 | 1.49M | && sym->name[0] == '_' |
796 | 1.49M | && sym->name[1] == '_' |
797 | 1.49M | && strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0 |
798 | 1.49M | && report_plugin_err) |
799 | 0 | { |
800 | 0 | report_plugin_err = false; |
801 | 0 | non_fatal (_("%s: plugin needed to handle lto object"), |
802 | 0 | bfd_get_filename (abfd)); |
803 | 0 | } |
804 | | |
805 | 1.49M | if (undefined_only) |
806 | 0 | keep = bfd_is_und_section (sym->section); |
807 | 1.49M | else if (external_only) |
808 | | /* PR binutls/12753: Unique symbols are global too. */ |
809 | 0 | keep = ((sym->flags & (BSF_GLOBAL |
810 | 0 | | BSF_WEAK |
811 | 0 | | BSF_GNU_UNIQUE)) != 0 |
812 | 0 | || bfd_is_und_section (sym->section) |
813 | 0 | || bfd_is_com_section (sym->section)); |
814 | 1.49M | else if (non_weak) |
815 | 0 | keep = ((sym->flags & BSF_WEAK) == 0); |
816 | 1.49M | else |
817 | 1.49M | keep = 1; |
818 | | |
819 | 1.49M | if (keep |
820 | 1.49M | && ! print_debug_syms |
821 | 1.49M | && (sym->flags & BSF_DEBUGGING) != 0) |
822 | 100k | keep = 0; |
823 | | |
824 | 1.49M | if (keep |
825 | 1.49M | && sort_by_size |
826 | 1.49M | && (bfd_is_abs_section (sym->section) |
827 | 0 | || bfd_is_und_section (sym->section))) |
828 | 0 | keep = 0; |
829 | | |
830 | 1.49M | if (keep |
831 | 1.49M | && defined_only) |
832 | 0 | { |
833 | 0 | if (bfd_is_und_section (sym->section)) |
834 | 0 | keep = 0; |
835 | 0 | } |
836 | | |
837 | 1.49M | if (keep |
838 | 1.49M | && bfd_is_target_special_symbol (abfd, sym) |
839 | 1.49M | && ! allow_special_symbols) |
840 | 50 | keep = 0; |
841 | | |
842 | 1.49M | if (keep) |
843 | 1.39M | { |
844 | 1.39M | if (to != from) |
845 | 1.31M | memcpy (to, from, size); |
846 | 1.39M | to += size; |
847 | 1.39M | } |
848 | 1.49M | } |
849 | | |
850 | 2.53k | return (to - (bfd_byte *) minisyms) / size; |
851 | 2.53k | } |
852 | | |
853 | | /* These globals are used to pass information into the sorting |
854 | | routines. */ |
855 | | static bfd *sort_bfd; |
856 | | static bool sort_dynamic; |
857 | | static asymbol *sort_x; |
858 | | static asymbol *sort_y; |
859 | | |
860 | | /* Symbol-sorting predicates */ |
861 | 38.9M | #define valueof(x) ((x)->section->vma + (x)->value) |
862 | | |
863 | | /* Numeric sorts. Undefined symbols are always considered "less than" |
864 | | defined symbols with zero values. Common symbols are not treated |
865 | | specially -- i.e., their sizes are used as their "values". */ |
866 | | |
867 | | static int |
868 | | non_numeric_forward (const void *P_x, const void *P_y) |
869 | 7.07M | { |
870 | 7.07M | asymbol *x, *y; |
871 | 7.07M | const char *xn, *yn; |
872 | | |
873 | 7.07M | x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x); |
874 | 7.07M | y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y); |
875 | 7.07M | if (x == NULL || y == NULL) |
876 | 0 | bfd_fatal (bfd_get_filename (sort_bfd)); |
877 | | |
878 | 7.07M | xn = bfd_asymbol_name (x); |
879 | 7.07M | yn = bfd_asymbol_name (y); |
880 | | |
881 | 7.07M | if (yn == NULL) |
882 | 0 | return xn != NULL; |
883 | 7.07M | if (xn == NULL) |
884 | 0 | return -1; |
885 | | |
886 | | /* Solaris 2.5 has a bug in strcoll. |
887 | | strcoll returns invalid values when confronted with empty strings. */ |
888 | 7.07M | if (*yn == '\0') |
889 | 6.65M | return *xn != '\0'; |
890 | 427k | if (*xn == '\0') |
891 | 11.0k | return -1; |
892 | | |
893 | 416k | return strcoll (xn, yn); |
894 | 427k | } |
895 | | |
896 | | static int |
897 | | non_numeric_reverse (const void *x, const void *y) |
898 | 0 | { |
899 | 0 | return - non_numeric_forward (x, y); |
900 | 0 | } |
901 | | |
902 | | static int |
903 | | numeric_forward (const void *P_x, const void *P_y) |
904 | 13.6M | { |
905 | 13.6M | asymbol *x, *y; |
906 | 13.6M | asection *xs, *ys; |
907 | | |
908 | 13.6M | x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x); |
909 | 13.6M | y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y); |
910 | 13.6M | if (x == NULL || y == NULL) |
911 | 0 | bfd_fatal (bfd_get_filename (sort_bfd)); |
912 | | |
913 | 13.6M | xs = bfd_asymbol_section (x); |
914 | 13.6M | ys = bfd_asymbol_section (y); |
915 | | |
916 | 13.6M | if (bfd_is_und_section (xs)) |
917 | 568k | { |
918 | 568k | if (! bfd_is_und_section (ys)) |
919 | 33.3k | return -1; |
920 | 568k | } |
921 | 13.1M | else if (bfd_is_und_section (ys)) |
922 | 112k | return 1; |
923 | 13.0M | else if (valueof (x) != valueof (y)) |
924 | 6.46M | return valueof (x) < valueof (y) ? -1 : 1; |
925 | | |
926 | 7.07M | return non_numeric_forward (P_x, P_y); |
927 | 13.6M | } |
928 | | |
929 | | static int |
930 | | numeric_reverse (const void *x, const void *y) |
931 | 0 | { |
932 | 0 | return - numeric_forward (x, y); |
933 | 0 | } |
934 | | |
935 | | static int (*(sorters[2][2])) (const void *, const void *) = |
936 | | { |
937 | | { non_numeric_forward, non_numeric_reverse }, |
938 | | { numeric_forward, numeric_reverse } |
939 | | }; |
940 | | |
941 | | /* This sort routine is used by sort_symbols_by_size. It is similar |
942 | | to numeric_forward, but when symbols have the same value it sorts |
943 | | by section VMA. This simplifies the sort_symbols_by_size code |
944 | | which handles symbols at the end of sections. Also, this routine |
945 | | tries to sort file names before other symbols with the same value. |
946 | | That will make the file name have a zero size, which will make |
947 | | sort_symbols_by_size choose the non file name symbol, leading to |
948 | | more meaningful output. For similar reasons, this code sorts |
949 | | gnu_compiled_* and gcc2_compiled before other symbols with the same |
950 | | value. */ |
951 | | |
952 | | static int |
953 | | size_forward1 (const void *P_x, const void *P_y) |
954 | 0 | { |
955 | 0 | asymbol *x, *y; |
956 | 0 | asection *xs, *ys; |
957 | 0 | const char *xn, *yn; |
958 | 0 | size_t xnl, ynl; |
959 | 0 | int xf, yf; |
960 | |
|
961 | 0 | x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x); |
962 | 0 | y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y); |
963 | 0 | if (x == NULL || y == NULL) |
964 | 0 | bfd_fatal (bfd_get_filename (sort_bfd)); |
965 | | |
966 | 0 | xs = bfd_asymbol_section (x); |
967 | 0 | ys = bfd_asymbol_section (y); |
968 | |
|
969 | 0 | if (bfd_is_und_section (xs)) |
970 | 0 | abort (); |
971 | 0 | if (bfd_is_und_section (ys)) |
972 | 0 | abort (); |
973 | | |
974 | 0 | if (valueof (x) != valueof (y)) |
975 | 0 | return valueof (x) < valueof (y) ? -1 : 1; |
976 | | |
977 | 0 | if (xs->vma != ys->vma) |
978 | 0 | return xs->vma < ys->vma ? -1 : 1; |
979 | | |
980 | 0 | xn = bfd_asymbol_name (x); |
981 | 0 | yn = bfd_asymbol_name (y); |
982 | 0 | xnl = strlen (xn); |
983 | 0 | ynl = strlen (yn); |
984 | | |
985 | | /* The symbols gnu_compiled and gcc2_compiled convey even less |
986 | | information than the file name, so sort them out first. */ |
987 | |
|
988 | 0 | xf = (strstr (xn, "gnu_compiled") != NULL |
989 | 0 | || strstr (xn, "gcc2_compiled") != NULL); |
990 | 0 | yf = (strstr (yn, "gnu_compiled") != NULL |
991 | 0 | || strstr (yn, "gcc2_compiled") != NULL); |
992 | |
|
993 | 0 | if (xf && ! yf) |
994 | 0 | return -1; |
995 | 0 | if (! xf && yf) |
996 | 0 | return 1; |
997 | | |
998 | | /* We use a heuristic for the file name. It may not work on non |
999 | | Unix systems, but it doesn't really matter; the only difference |
1000 | | is precisely which symbol names get printed. */ |
1001 | | |
1002 | 0 | #define file_symbol(s, sn, snl) \ |
1003 | 0 | (((s)->flags & BSF_FILE) != 0 \ |
1004 | 0 | || ((snl) > 2 \ |
1005 | 0 | && (sn)[(snl) - 2] == '.' \ |
1006 | 0 | && ((sn)[(snl) - 1] == 'o' \ |
1007 | 0 | || (sn)[(snl) - 1] == 'a'))) |
1008 | | |
1009 | 0 | xf = file_symbol (x, xn, xnl); |
1010 | 0 | yf = file_symbol (y, yn, ynl); |
1011 | |
|
1012 | 0 | if (xf && ! yf) |
1013 | 0 | return -1; |
1014 | 0 | if (! xf && yf) |
1015 | 0 | return 1; |
1016 | | |
1017 | 0 | return non_numeric_forward (P_x, P_y); |
1018 | 0 | } |
1019 | | |
1020 | | /* This sort routine is used by sort_symbols_by_size. It is sorting |
1021 | | an array of size_sym structures into size order. */ |
1022 | | |
1023 | | static int |
1024 | | size_forward2 (const void *P_x, const void *P_y) |
1025 | 0 | { |
1026 | 0 | const struct size_sym *x = (const struct size_sym *) P_x; |
1027 | 0 | const struct size_sym *y = (const struct size_sym *) P_y; |
1028 | |
|
1029 | 0 | if (x->size < y->size) |
1030 | 0 | return reverse_sort ? 1 : -1; |
1031 | 0 | else if (x->size > y->size) |
1032 | 0 | return reverse_sort ? -1 : 1; |
1033 | 0 | else |
1034 | 0 | return sorters[0][reverse_sort] (x->minisym, y->minisym); |
1035 | 0 | } |
1036 | | |
1037 | | /* Sort the symbols by size. ELF provides a size but for other formats |
1038 | | we have to make a guess by assuming that the difference between the |
1039 | | address of a symbol and the address of the next higher symbol is the |
1040 | | size. */ |
1041 | | |
1042 | | static long |
1043 | | sort_symbols_by_size (bfd *abfd, bool is_dynamic, void *minisyms, |
1044 | | long symcount, unsigned int size, |
1045 | | struct size_sym **symsizesp) |
1046 | 0 | { |
1047 | 0 | struct size_sym *symsizes; |
1048 | 0 | bfd_byte *from, *fromend; |
1049 | 0 | asymbol *sym = NULL; |
1050 | 0 | asymbol *store_sym, *store_next; |
1051 | |
|
1052 | 0 | qsort (minisyms, symcount, size, size_forward1); |
1053 | | |
1054 | | /* We are going to return a special set of symbols and sizes to |
1055 | | print. */ |
1056 | 0 | symsizes = (struct size_sym *) xmalloc (symcount * sizeof (struct size_sym)); |
1057 | 0 | *symsizesp = symsizes; |
1058 | | |
1059 | | /* Note that filter_symbols has already removed all absolute and |
1060 | | undefined symbols. Here we remove all symbols whose size winds |
1061 | | up as zero. */ |
1062 | 0 | from = (bfd_byte *) minisyms; |
1063 | 0 | fromend = from + symcount * size; |
1064 | |
|
1065 | 0 | store_sym = sort_x; |
1066 | 0 | store_next = sort_y; |
1067 | |
|
1068 | 0 | if (from < fromend) |
1069 | 0 | { |
1070 | 0 | sym = bfd_minisymbol_to_symbol (abfd, is_dynamic, (const void *) from, |
1071 | 0 | store_sym); |
1072 | 0 | if (sym == NULL) |
1073 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1074 | 0 | } |
1075 | | |
1076 | 0 | for (; from < fromend; from += size) |
1077 | 0 | { |
1078 | 0 | asymbol *next; |
1079 | 0 | asection *sec; |
1080 | 0 | bfd_vma sz; |
1081 | 0 | asymbol *temp; |
1082 | |
|
1083 | 0 | if (from + size < fromend) |
1084 | 0 | { |
1085 | 0 | next = bfd_minisymbol_to_symbol (abfd, |
1086 | 0 | is_dynamic, |
1087 | 0 | (const void *) (from + size), |
1088 | 0 | store_next); |
1089 | 0 | if (next == NULL) |
1090 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1091 | 0 | } |
1092 | 0 | else |
1093 | 0 | next = NULL; |
1094 | | |
1095 | 0 | sec = bfd_asymbol_section (sym); |
1096 | | |
1097 | | /* Synthetic symbols don't have a full type set of data available, thus |
1098 | | we can't rely on that information for the symbol size. Ditto for |
1099 | | bfd/section.c:global_syms like *ABS*. */ |
1100 | 0 | if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 |
1101 | 0 | && bfd_get_flavour (abfd) == bfd_target_elf_flavour) |
1102 | 0 | sz = ((elf_symbol_type *) sym)->internal_elf_sym.st_size; |
1103 | 0 | else if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0 |
1104 | 0 | && bfd_is_com_section (sec)) |
1105 | 0 | sz = sym->value; |
1106 | 0 | else |
1107 | 0 | { |
1108 | 0 | if (from + size < fromend |
1109 | 0 | && sec == bfd_asymbol_section (next)) |
1110 | 0 | sz = valueof (next) - valueof (sym); |
1111 | 0 | else |
1112 | 0 | sz = (bfd_section_vma (sec) |
1113 | 0 | + bfd_section_size (sec) |
1114 | 0 | - valueof (sym)); |
1115 | 0 | } |
1116 | |
|
1117 | 0 | if (sz != 0) |
1118 | 0 | { |
1119 | 0 | symsizes->minisym = (const void *) from; |
1120 | 0 | symsizes->size = sz; |
1121 | 0 | ++symsizes; |
1122 | 0 | } |
1123 | |
|
1124 | 0 | sym = next; |
1125 | |
|
1126 | 0 | temp = store_sym; |
1127 | 0 | store_sym = store_next; |
1128 | 0 | store_next = temp; |
1129 | 0 | } |
1130 | | |
1131 | 0 | symcount = symsizes - *symsizesp; |
1132 | | |
1133 | | /* We must now sort again by size. */ |
1134 | 0 | qsort ((void *) *symsizesp, symcount, sizeof (struct size_sym), size_forward2); |
1135 | |
|
1136 | 0 | return symcount; |
1137 | 0 | } |
1138 | | |
1139 | | /* This function is used to get the relocs for a particular section. |
1140 | | It is called via bfd_map_over_sections. */ |
1141 | | |
1142 | | static void |
1143 | | get_relocs (bfd *abfd, asection *sec, void *dataarg) |
1144 | 814k | { |
1145 | 814k | struct lineno_cache *data = (struct lineno_cache *) dataarg; |
1146 | | |
1147 | 814k | *data->secs = sec; |
1148 | 814k | *data->relocs = NULL; |
1149 | 814k | *data->relcount = 0; |
1150 | | |
1151 | 814k | if ((sec->flags & SEC_RELOC) != 0) |
1152 | 537k | { |
1153 | 537k | long relsize = bfd_get_reloc_upper_bound (abfd, sec); |
1154 | 537k | if (relsize > 0) |
1155 | 116k | { |
1156 | 116k | *data->relocs = (arelent **) xmalloc (relsize); |
1157 | 116k | *data->relcount = bfd_canonicalize_reloc (abfd, sec, *data->relocs, |
1158 | 116k | data->syms); |
1159 | 116k | } |
1160 | 537k | } |
1161 | | |
1162 | 814k | ++data->secs; |
1163 | 814k | ++data->relocs; |
1164 | 814k | ++data->relcount; |
1165 | 814k | } |
1166 | | |
1167 | | static void |
1168 | | free_lineno_cache (bfd *abfd) |
1169 | 16.3k | { |
1170 | 16.3k | struct lineno_cache *lc = bfd_usrdata (abfd); |
1171 | | |
1172 | 16.3k | if (lc) |
1173 | 2.48k | { |
1174 | 2.48k | if (lc->relocs) |
1175 | 816k | for (unsigned int i = 0; i < lc->seccount; i++) |
1176 | 814k | free (lc->relocs[i]); |
1177 | 2.48k | free (lc->relcount); |
1178 | 2.48k | free (lc->relocs); |
1179 | 2.48k | free (lc->secs); |
1180 | 2.48k | free (lc->syms); |
1181 | 2.48k | free (lc); |
1182 | 2.48k | bfd_set_usrdata (abfd, NULL); |
1183 | 2.48k | } |
1184 | 16.3k | } |
1185 | | |
1186 | | /* Print a single symbol. */ |
1187 | | |
1188 | | static void |
1189 | | print_symbol (bfd * abfd, |
1190 | | asymbol * sym, |
1191 | | bfd_vma ssize, |
1192 | | bfd * archive_bfd) |
1193 | 1.39M | { |
1194 | 1.39M | symbol_info syminfo; |
1195 | 1.39M | struct extended_symbol_info info; |
1196 | | |
1197 | 1.39M | format->print_symbol_filename (archive_bfd, abfd); |
1198 | | |
1199 | 1.39M | bfd_get_symbol_info (abfd, sym, &syminfo); |
1200 | | |
1201 | | /* PR 22967 - Distinguish between local and global ifunc symbols. */ |
1202 | 1.39M | if (syminfo.type == 'i' |
1203 | 1.39M | && sym->flags & BSF_GNU_INDIRECT_FUNCTION) |
1204 | 1.42k | { |
1205 | 1.42k | if (ifunc_type_chars == NULL || ifunc_type_chars[0] == 0) |
1206 | 1.42k | ; /* Change nothing. */ |
1207 | 0 | else if (sym->flags & BSF_GLOBAL) |
1208 | 0 | syminfo.type = ifunc_type_chars[0]; |
1209 | 0 | else if (ifunc_type_chars[1] != 0) |
1210 | 0 | syminfo.type = ifunc_type_chars[1]; |
1211 | 1.42k | } |
1212 | | |
1213 | 1.39M | info.sinfo = &syminfo; |
1214 | 1.39M | info.ssize = ssize; |
1215 | | /* Synthetic symbols do not have a full symbol type set of data available. |
1216 | | Nor do bfd/section.c:global_syms like *ABS*. */ |
1217 | 1.39M | if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) != 0) |
1218 | 0 | { |
1219 | 0 | info.elfinfo = NULL; |
1220 | 0 | info.coffinfo = NULL; |
1221 | 0 | } |
1222 | 1.39M | else |
1223 | 1.39M | { |
1224 | 1.39M | info.elfinfo = elf_symbol_from (sym); |
1225 | 1.39M | info.coffinfo = coff_symbol_from (sym); |
1226 | 1.39M | } |
1227 | | |
1228 | 1.39M | format->print_symbol_info (&info, abfd); |
1229 | | |
1230 | 1.39M | if (line_numbers) |
1231 | 1.39M | { |
1232 | 1.39M | struct lineno_cache *lc = bfd_usrdata (abfd); |
1233 | 1.39M | const char *filename, *functionname; |
1234 | 1.39M | unsigned int lineno; |
1235 | | |
1236 | | /* We need to get the canonical symbols in order to call |
1237 | | bfd_find_nearest_line. This is inefficient, but, then, you |
1238 | | don't have to use --line-numbers. */ |
1239 | 1.39M | if (lc == NULL) |
1240 | 2.48k | { |
1241 | 2.48k | lc = xcalloc (1, sizeof (*lc)); |
1242 | 2.48k | bfd_set_usrdata (abfd, lc); |
1243 | 2.48k | } |
1244 | 1.39M | if (lc->syms == NULL && lc->symcount == 0) |
1245 | 2.48k | { |
1246 | 2.48k | long symsize = bfd_get_symtab_upper_bound (abfd); |
1247 | 2.48k | if (symsize <= 0) |
1248 | 117 | lc->symcount = -1; |
1249 | 2.37k | else |
1250 | 2.37k | { |
1251 | 2.37k | lc->syms = xmalloc (symsize); |
1252 | 2.37k | lc->symcount = bfd_canonicalize_symtab (abfd, lc->syms); |
1253 | 2.37k | } |
1254 | 2.48k | } |
1255 | | |
1256 | 1.39M | if (lc->symcount <= 0) |
1257 | 1.17M | ; |
1258 | 220k | else if (bfd_is_und_section (bfd_asymbol_section (sym))) |
1259 | 93.4k | { |
1260 | 93.4k | unsigned int i; |
1261 | 93.4k | const char *symname; |
1262 | | |
1263 | | /* For an undefined symbol, we try to find a reloc for the |
1264 | | symbol, and print the line number of the reloc. */ |
1265 | 93.4k | if (lc->relocs == NULL) |
1266 | 1.99k | { |
1267 | 1.99k | unsigned int seccount = bfd_count_sections (abfd); |
1268 | 1.99k | lc->seccount = seccount; |
1269 | 1.99k | lc->secs = xmalloc (seccount * sizeof (*lc->secs)); |
1270 | 1.99k | lc->relocs = xmalloc (seccount * sizeof (*lc->relocs)); |
1271 | 1.99k | lc->relcount = xmalloc (seccount * sizeof (*lc->relcount)); |
1272 | | |
1273 | 1.99k | struct lineno_cache rinfo = *lc; |
1274 | 1.99k | bfd_map_over_sections (abfd, get_relocs, &rinfo); |
1275 | 1.99k | } |
1276 | | |
1277 | 93.4k | symname = bfd_asymbol_name (sym); |
1278 | 4.43M | for (i = 0; i < lc->seccount; i++) |
1279 | 4.34M | { |
1280 | 4.34M | long j; |
1281 | | |
1282 | 16.0M | for (j = 0; j < lc->relcount[i]; j++) |
1283 | 11.7M | { |
1284 | 11.7M | arelent *r; |
1285 | | |
1286 | 11.7M | r = lc->relocs[i][j]; |
1287 | 11.7M | if (r->sym_ptr_ptr != NULL |
1288 | 11.7M | && (*r->sym_ptr_ptr)->section == sym->section |
1289 | 11.7M | && (*r->sym_ptr_ptr)->value == sym->value |
1290 | 11.7M | && strcmp (symname, |
1291 | 2.78M | bfd_asymbol_name (*r->sym_ptr_ptr)) == 0 |
1292 | 11.7M | && bfd_find_nearest_line (abfd, lc->secs[i], lc->syms, |
1293 | 11.7M | r->address, &filename, |
1294 | 11.7M | &functionname, &lineno) |
1295 | 11.7M | && filename != NULL) |
1296 | 12.0k | { |
1297 | | /* We only print the first one we find. */ |
1298 | 12.0k | printf ("\t%s:%u", filename, lineno); |
1299 | 12.0k | i = lc->seccount; |
1300 | 12.0k | break; |
1301 | 12.0k | } |
1302 | 11.7M | } |
1303 | 4.34M | } |
1304 | 93.4k | } |
1305 | 126k | else if (bfd_asymbol_section (sym)->owner == abfd) |
1306 | 51.3k | { |
1307 | 51.3k | if ((bfd_find_line (abfd, lc->syms, sym, &filename, &lineno) |
1308 | 51.3k | || bfd_find_nearest_line (abfd, bfd_asymbol_section (sym), |
1309 | 51.3k | lc->syms, sym->value, &filename, |
1310 | 51.3k | &functionname, &lineno)) |
1311 | 51.3k | && filename != NULL |
1312 | 51.3k | && lineno != 0) |
1313 | 7.60k | printf ("\t%s:%u", filename, lineno); |
1314 | 51.3k | } |
1315 | 1.39M | } |
1316 | | |
1317 | 1.39M | putchar ('\n'); |
1318 | 1.39M | } |
1319 | | |
1320 | | /* Print the symbols when sorting by size. */ |
1321 | | |
1322 | | static void |
1323 | | print_size_symbols (bfd *abfd, |
1324 | | bool is_dynamic, |
1325 | | struct size_sym *symsizes, |
1326 | | long symcount, |
1327 | | bfd *archive_bfd) |
1328 | 0 | { |
1329 | 0 | asymbol *store; |
1330 | 0 | struct size_sym *from; |
1331 | 0 | struct size_sym *fromend; |
1332 | |
|
1333 | 0 | store = bfd_make_empty_symbol (abfd); |
1334 | 0 | if (store == NULL) |
1335 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1336 | | |
1337 | 0 | from = symsizes; |
1338 | 0 | fromend = from + symcount; |
1339 | |
|
1340 | 0 | for (; from < fromend; from++) |
1341 | 0 | { |
1342 | 0 | asymbol *sym; |
1343 | |
|
1344 | 0 | sym = bfd_minisymbol_to_symbol (abfd, is_dynamic, from->minisym, store); |
1345 | 0 | if (sym == NULL) |
1346 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1347 | | |
1348 | 0 | print_symbol (abfd, sym, from->size, archive_bfd); |
1349 | 0 | } |
1350 | 0 | } |
1351 | | |
1352 | | |
1353 | | /* Print the symbols of ABFD that are held in MINISYMS. |
1354 | | |
1355 | | If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. |
1356 | | |
1357 | | SYMCOUNT is the number of symbols in MINISYMS. |
1358 | | |
1359 | | SIZE is the size of a symbol in MINISYMS. */ |
1360 | | |
1361 | | static void |
1362 | | print_symbols (bfd *abfd, |
1363 | | bool is_dynamic, |
1364 | | void *minisyms, |
1365 | | long symcount, |
1366 | | unsigned int size, |
1367 | | bfd *archive_bfd) |
1368 | 2.53k | { |
1369 | 2.53k | asymbol *store; |
1370 | 2.53k | bfd_byte *from; |
1371 | 2.53k | bfd_byte *fromend; |
1372 | | |
1373 | 2.53k | store = bfd_make_empty_symbol (abfd); |
1374 | 2.53k | if (store == NULL) |
1375 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1376 | | |
1377 | 2.53k | from = (bfd_byte *) minisyms; |
1378 | 2.53k | fromend = from + symcount * size; |
1379 | | |
1380 | 1.39M | for (; from < fromend; from += size) |
1381 | 1.39M | { |
1382 | 1.39M | asymbol *sym; |
1383 | | |
1384 | 1.39M | sym = bfd_minisymbol_to_symbol (abfd, is_dynamic, from, store); |
1385 | 1.39M | if (sym == NULL) |
1386 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1387 | | |
1388 | 1.39M | print_symbol (abfd, sym, (bfd_vma) 0, archive_bfd); |
1389 | 1.39M | } |
1390 | 2.53k | } |
1391 | | |
1392 | | /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */ |
1393 | | |
1394 | | static void |
1395 | | display_rel_file (bfd *abfd, bfd *archive_bfd) |
1396 | 8.03k | { |
1397 | 8.03k | long symcount; |
1398 | 8.03k | void *minisyms; |
1399 | 8.03k | unsigned int size; |
1400 | 8.03k | struct size_sym *symsizes; |
1401 | 8.03k | asymbol *synthsyms = NULL; |
1402 | | |
1403 | 8.03k | if (! dynamic) |
1404 | 8.03k | { |
1405 | 8.03k | if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) |
1406 | 909 | { |
1407 | 909 | if (!quiet) |
1408 | 909 | non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); |
1409 | 909 | return; |
1410 | 909 | } |
1411 | 8.03k | } |
1412 | | |
1413 | 7.12k | symcount = bfd_read_minisymbols (abfd, dynamic, &minisyms, &size); |
1414 | 7.12k | if (symcount <= 0) |
1415 | 4.58k | { |
1416 | 4.58k | if (!quiet) |
1417 | 4.58k | non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); |
1418 | 4.58k | return; |
1419 | 4.58k | } |
1420 | | |
1421 | 2.53k | if (show_synthetic && size == sizeof (asymbol *)) |
1422 | 0 | { |
1423 | 0 | asymbol **static_syms = NULL; |
1424 | 0 | asymbol **dyn_syms = NULL; |
1425 | 0 | long static_count = 0; |
1426 | 0 | long dyn_count = 0; |
1427 | 0 | long synth_count; |
1428 | |
|
1429 | 0 | if (dynamic) |
1430 | 0 | { |
1431 | 0 | dyn_count = symcount; |
1432 | 0 | dyn_syms = (asymbol **) minisyms; |
1433 | 0 | } |
1434 | 0 | else |
1435 | 0 | { |
1436 | 0 | long storage = bfd_get_dynamic_symtab_upper_bound (abfd); |
1437 | |
|
1438 | 0 | static_count = symcount; |
1439 | 0 | static_syms = (asymbol **) minisyms; |
1440 | |
|
1441 | 0 | if (storage > 0) |
1442 | 0 | { |
1443 | 0 | dyn_syms = (asymbol **) xmalloc (storage); |
1444 | 0 | dyn_count = bfd_canonicalize_dynamic_symtab (abfd, dyn_syms); |
1445 | 0 | if (dyn_count < 0) |
1446 | 0 | dyn_count = 0; |
1447 | 0 | } |
1448 | 0 | } |
1449 | |
|
1450 | 0 | synth_count = bfd_get_synthetic_symtab (abfd, static_count, static_syms, |
1451 | 0 | dyn_count, dyn_syms, &synthsyms); |
1452 | 0 | if (synth_count > 0) |
1453 | 0 | { |
1454 | 0 | asymbol **symp; |
1455 | 0 | long i; |
1456 | |
|
1457 | 0 | minisyms = xrealloc (minisyms, |
1458 | 0 | (symcount + synth_count + 1) * sizeof (*symp)); |
1459 | 0 | symp = (asymbol **) minisyms + symcount; |
1460 | 0 | for (i = 0; i < synth_count; i++) |
1461 | 0 | *symp++ = synthsyms + i; |
1462 | 0 | *symp = 0; |
1463 | 0 | symcount += synth_count; |
1464 | 0 | } |
1465 | 0 | if (!dynamic && dyn_syms != NULL) |
1466 | 0 | free (dyn_syms); |
1467 | 0 | } |
1468 | | |
1469 | | /* lto_slim_object is set to false when a bfd is loaded with a compiler |
1470 | | LTO plugin. */ |
1471 | 2.53k | if (abfd->lto_slim_object) |
1472 | 1 | { |
1473 | 1 | report_plugin_err = false; |
1474 | 1 | non_fatal (_("%s: plugin needed to handle lto object"), |
1475 | 1 | bfd_get_filename (abfd)); |
1476 | 1 | } |
1477 | | |
1478 | | /* Discard the symbols we don't want to print. |
1479 | | It's OK to do this in place; we'll free the storage anyway |
1480 | | (after printing). */ |
1481 | | |
1482 | 2.53k | symcount = filter_symbols (abfd, dynamic, minisyms, symcount, size); |
1483 | | |
1484 | 2.53k | symsizes = NULL; |
1485 | 2.53k | if (! no_sort) |
1486 | 2.53k | { |
1487 | 2.53k | sort_bfd = abfd; |
1488 | 2.53k | sort_dynamic = dynamic; |
1489 | 2.53k | sort_x = bfd_make_empty_symbol (abfd); |
1490 | 2.53k | sort_y = bfd_make_empty_symbol (abfd); |
1491 | 2.53k | if (sort_x == NULL || sort_y == NULL) |
1492 | 0 | bfd_fatal (bfd_get_filename (abfd)); |
1493 | | |
1494 | 2.53k | if (! sort_by_size) |
1495 | 2.53k | qsort (minisyms, symcount, size, |
1496 | 2.53k | sorters[sort_numerically][reverse_sort]); |
1497 | 0 | else |
1498 | 0 | symcount = sort_symbols_by_size (abfd, dynamic, minisyms, symcount, |
1499 | 0 | size, &symsizes); |
1500 | 2.53k | } |
1501 | | |
1502 | 2.53k | if (! sort_by_size) |
1503 | 2.53k | print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd); |
1504 | 0 | else |
1505 | 0 | print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd); |
1506 | | |
1507 | 2.53k | if (synthsyms) |
1508 | 0 | free (synthsyms); |
1509 | 2.53k | free (minisyms); |
1510 | 2.53k | free (symsizes); |
1511 | 2.53k | } |
1512 | | |
1513 | | /* Construct a formatting string for printing symbol values. */ |
1514 | | |
1515 | | static const char * |
1516 | | get_print_format (void) |
1517 | 8.03k | { |
1518 | 8.03k | const char * padding; |
1519 | 8.03k | if (print_format == FORMAT_POSIX || print_format == FORMAT_JUST_SYMBOLS) |
1520 | 0 | { |
1521 | | /* POSIX compatible output does not have any padding. */ |
1522 | 0 | padding = ""; |
1523 | 0 | } |
1524 | 8.03k | else if (print_width == 32) |
1525 | 4.76k | { |
1526 | 4.76k | padding ="08"; |
1527 | 4.76k | } |
1528 | 3.27k | else /* print_width == 64 */ |
1529 | 3.27k | { |
1530 | 3.27k | padding = "016"; |
1531 | 3.27k | } |
1532 | | |
1533 | 8.03k | const char * radix = NULL; |
1534 | 8.03k | switch (print_radix) |
1535 | 8.03k | { |
1536 | 0 | case 8: radix = PRIo64; break; |
1537 | 0 | case 10: radix = PRId64; break; |
1538 | 8.03k | case 16: radix = PRIx64; break; |
1539 | 8.03k | } |
1540 | | |
1541 | 8.03k | return concat ("%", padding, radix, NULL); |
1542 | 8.03k | } |
1543 | | |
1544 | | static void |
1545 | | set_print_width (bfd *file) |
1546 | 8.03k | { |
1547 | 8.03k | print_width = bfd_get_arch_size (file); |
1548 | | |
1549 | 8.03k | if (print_width == -1) |
1550 | 0 | { |
1551 | | /* PR binutils/4292 |
1552 | | Guess the target's bitsize based on its name. |
1553 | | We assume here than any 64-bit format will include |
1554 | | "64" somewhere in its name. The only known exception |
1555 | | is the MMO object file format. */ |
1556 | 0 | if (strstr (bfd_get_target (file), "64") != NULL |
1557 | 0 | || strcmp (bfd_get_target (file), "mmo") == 0) |
1558 | 0 | print_width = 64; |
1559 | 0 | else |
1560 | 0 | print_width = 32; |
1561 | 0 | } |
1562 | 8.03k | free ((char *) print_format_string); |
1563 | 8.03k | print_format_string = get_print_format (); |
1564 | 8.03k | } |
1565 | | |
1566 | | static void |
1567 | | display_archive (bfd *file) |
1568 | 1.04k | { |
1569 | 1.04k | bfd *arfile = NULL; |
1570 | 1.04k | bfd *last_arfile = NULL; |
1571 | 1.04k | char **matching; |
1572 | | |
1573 | 1.04k | format->print_archive_filename (bfd_get_filename (file)); |
1574 | | |
1575 | 1.04k | if (print_armap) |
1576 | 0 | print_symdef_entry (file); |
1577 | | |
1578 | 1.04k | for (;;) |
1579 | 4.19k | { |
1580 | 4.19k | arfile = bfd_openr_next_archived_file (file, arfile); |
1581 | | |
1582 | 4.19k | if (arfile == NULL) |
1583 | 1.04k | { |
1584 | 1.04k | if (bfd_get_error () != bfd_error_no_more_archived_files) |
1585 | 336 | bfd_nonfatal (bfd_get_filename (file)); |
1586 | 1.04k | break; |
1587 | 1.04k | } |
1588 | | |
1589 | 3.15k | if (bfd_check_format_matches (arfile, bfd_object, &matching)) |
1590 | 375 | { |
1591 | 375 | set_print_width (arfile); |
1592 | 375 | format->print_archive_member (bfd_get_filename (file), |
1593 | 375 | bfd_get_filename (arfile)); |
1594 | 375 | display_rel_file (arfile, file); |
1595 | 375 | } |
1596 | 2.77k | else |
1597 | 2.77k | { |
1598 | 2.77k | bfd_nonfatal (bfd_get_filename (arfile)); |
1599 | 2.77k | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) |
1600 | 22 | list_matching_formats (matching); |
1601 | 2.77k | } |
1602 | | |
1603 | 3.15k | if (last_arfile != NULL) |
1604 | 2.32k | { |
1605 | 2.32k | free_lineno_cache (last_arfile); |
1606 | 2.32k | bfd_close (last_arfile); |
1607 | 2.32k | if (arfile == last_arfile) |
1608 | 0 | return; |
1609 | 2.32k | } |
1610 | 3.15k | last_arfile = arfile; |
1611 | 3.15k | } |
1612 | | |
1613 | 1.04k | if (last_arfile != NULL) |
1614 | 826 | { |
1615 | 826 | free_lineno_cache (last_arfile); |
1616 | 826 | bfd_close (last_arfile); |
1617 | 826 | } |
1618 | 1.04k | } |
1619 | | |
1620 | | static bool |
1621 | | display_file (char *filename) |
1622 | 13.1k | { |
1623 | 13.1k | bool retval = true; |
1624 | 13.1k | bfd *file; |
1625 | 13.1k | char **matching; |
1626 | | |
1627 | 13.1k | if (get_file_size (filename) < 1) |
1628 | 0 | return false; |
1629 | | |
1630 | 13.1k | file = bfd_openr (filename, target ? target : plugin_target); |
1631 | 13.1k | if (file == NULL) |
1632 | 0 | { |
1633 | 0 | bfd_nonfatal (filename); |
1634 | 0 | return false; |
1635 | 0 | } |
1636 | | |
1637 | | /* If printing line numbers, decompress the debug sections. */ |
1638 | 13.1k | if (line_numbers) |
1639 | 13.1k | file->flags |= BFD_DECOMPRESS; |
1640 | | |
1641 | 13.1k | if (bfd_check_format (file, bfd_archive)) |
1642 | 1.04k | { |
1643 | 1.04k | display_archive (file); |
1644 | 1.04k | } |
1645 | 12.1k | else if (bfd_check_format_matches (file, bfd_object, &matching)) |
1646 | 7.65k | { |
1647 | 7.65k | set_print_width (file); |
1648 | 7.65k | format->print_object_filename (filename); |
1649 | 7.65k | display_rel_file (file, NULL); |
1650 | 7.65k | } |
1651 | 4.48k | else |
1652 | 4.48k | { |
1653 | 4.48k | bfd_nonfatal (filename); |
1654 | 4.48k | if (bfd_get_error () == bfd_error_file_ambiguously_recognized) |
1655 | 827 | list_matching_formats (matching); |
1656 | 4.48k | retval = false; |
1657 | 4.48k | } |
1658 | | |
1659 | 13.1k | free_lineno_cache (file); |
1660 | 13.1k | if (!bfd_close (file)) |
1661 | 0 | retval = false; |
1662 | | |
1663 | 13.1k | return retval; |
1664 | 13.1k | } |
1665 | | |
1666 | | /* The following 3 groups of functions are called unconditionally, |
1667 | | once at the start of processing each file of the appropriate type. |
1668 | | They should check `filename_per_file' and `filename_per_symbol', |
1669 | | as appropriate for their output format, to determine whether to |
1670 | | print anything. */ |
1671 | | |
1672 | | /* Print the name of an object file given on the command line. */ |
1673 | | |
1674 | | static void |
1675 | | print_object_filename_bsd (const char *filename) |
1676 | 7.65k | { |
1677 | 7.65k | if (filename_per_file && !filename_per_symbol) |
1678 | 0 | printf ("\n%s:\n", filename); |
1679 | 7.65k | } |
1680 | | |
1681 | | static void |
1682 | | print_object_filename_sysv (const char *filename) |
1683 | 0 | { |
1684 | 0 | if (undefined_only) |
1685 | 0 | printf (_("\n\nUndefined symbols from %s:\n\n"), filename); |
1686 | 0 | else |
1687 | 0 | printf (_("\n\nSymbols from %s:\n\n"), filename); |
1688 | 0 | if (print_width == 32) |
1689 | 0 | printf (_("\ |
1690 | 0 | Name Value Class Type Size Line Section\n\n")); |
1691 | 0 | else |
1692 | 0 | printf (_("\ |
1693 | 0 | Name Value Class Type Size Line Section\n\n")); |
1694 | 0 | } |
1695 | | |
1696 | | static void |
1697 | | print_object_filename_posix (const char *filename) |
1698 | 0 | { |
1699 | 0 | if (filename_per_file && !filename_per_symbol) |
1700 | 0 | printf ("%s:\n", filename); |
1701 | 0 | } |
1702 | | |
1703 | | static void |
1704 | | do_not_print_object_filename (const char *filename ATTRIBUTE_UNUSED) |
1705 | 0 | { |
1706 | 0 | } |
1707 | | |
1708 | | /* Print the name of an archive file given on the command line. */ |
1709 | | |
1710 | | static void |
1711 | | print_archive_filename_bsd (const char *filename) |
1712 | 1.04k | { |
1713 | 1.04k | if (filename_per_file) |
1714 | 0 | printf ("\n%s:\n", filename); |
1715 | 1.04k | } |
1716 | | |
1717 | | static void |
1718 | | print_archive_filename_sysv (const char *filename ATTRIBUTE_UNUSED) |
1719 | 0 | { |
1720 | 0 | } |
1721 | | |
1722 | | static void |
1723 | | print_archive_filename_posix (const char *filename ATTRIBUTE_UNUSED) |
1724 | 0 | { |
1725 | 0 | } |
1726 | | |
1727 | | static void |
1728 | | do_not_print_archive_filename (const char *filename ATTRIBUTE_UNUSED) |
1729 | 0 | { |
1730 | 0 | } |
1731 | | |
1732 | | /* Print the name of an archive member file. */ |
1733 | | |
1734 | | static void |
1735 | | print_archive_member_bsd (const char *archive ATTRIBUTE_UNUSED, |
1736 | | const char *filename) |
1737 | 375 | { |
1738 | 375 | if (!filename_per_symbol) |
1739 | 0 | printf ("\n%s:\n", filename); |
1740 | 375 | } |
1741 | | |
1742 | | static void |
1743 | | print_archive_member_sysv (const char *archive, const char *filename) |
1744 | 0 | { |
1745 | 0 | if (undefined_only) |
1746 | 0 | printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename); |
1747 | 0 | else |
1748 | 0 | printf (_("\n\nSymbols from %s[%s]:\n\n"), archive, filename); |
1749 | 0 | if (print_width == 32) |
1750 | 0 | printf (_("\ |
1751 | 0 | Name Value Class Type Size Line Section\n\n")); |
1752 | 0 | else |
1753 | 0 | printf (_("\ |
1754 | 0 | Name Value Class Type Size Line Section\n\n")); |
1755 | 0 | } |
1756 | | |
1757 | | static void |
1758 | | print_archive_member_posix (const char *archive, const char *filename) |
1759 | 0 | { |
1760 | 0 | if (!filename_per_symbol) |
1761 | 0 | printf ("%s[%s]:\n", archive, filename); |
1762 | 0 | } |
1763 | | |
1764 | | static void |
1765 | | do_not_print_archive_member (const char *archive ATTRIBUTE_UNUSED, |
1766 | | const char *filename ATTRIBUTE_UNUSED) |
1767 | 0 | { |
1768 | 0 | } |
1769 | | |
1770 | | |
1771 | | /* Print the name of the file (and archive, if there is one) |
1772 | | containing a symbol. */ |
1773 | | |
1774 | | static void |
1775 | | print_symbol_filename_bsd (bfd *archive_bfd, bfd *abfd) |
1776 | 1.39M | { |
1777 | 1.39M | if (filename_per_symbol) |
1778 | 1.39M | { |
1779 | 1.39M | if (archive_bfd) |
1780 | 39.3k | printf ("%s:", bfd_get_filename (archive_bfd)); |
1781 | 1.39M | printf ("%s:", bfd_get_filename (abfd)); |
1782 | 1.39M | } |
1783 | 1.39M | } |
1784 | | |
1785 | | static void |
1786 | | print_symbol_filename_sysv (bfd *archive_bfd, bfd *abfd) |
1787 | 0 | { |
1788 | 0 | if (filename_per_symbol) |
1789 | 0 | { |
1790 | 0 | if (archive_bfd) |
1791 | 0 | printf ("%s:", bfd_get_filename (archive_bfd)); |
1792 | 0 | printf ("%s:", bfd_get_filename (abfd)); |
1793 | 0 | } |
1794 | 0 | } |
1795 | | |
1796 | | static void |
1797 | | print_symbol_filename_posix (bfd *archive_bfd, bfd *abfd) |
1798 | 0 | { |
1799 | 0 | if (filename_per_symbol) |
1800 | 0 | { |
1801 | 0 | if (archive_bfd) |
1802 | 0 | printf ("%s[%s]: ", bfd_get_filename (archive_bfd), |
1803 | 0 | bfd_get_filename (abfd)); |
1804 | 0 | else |
1805 | 0 | printf ("%s: ", bfd_get_filename (abfd)); |
1806 | 0 | } |
1807 | 0 | } |
1808 | | |
1809 | | static void |
1810 | | do_not_print_symbol_filename (bfd *archive_bfd ATTRIBUTE_UNUSED, |
1811 | | bfd *abfd ATTRIBUTE_UNUSED) |
1812 | 0 | { |
1813 | 0 | } |
1814 | | |
1815 | | |
1816 | | /* Print a symbol value. */ |
1817 | | |
1818 | | static void |
1819 | | print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val) |
1820 | 1.29M | { |
1821 | 1.29M | switch (print_width) |
1822 | 1.29M | { |
1823 | 1.25M | case 32: |
1824 | 1.29M | case 64: |
1825 | 1.29M | printf (print_format_string, (uint64_t) val); |
1826 | 1.29M | break; |
1827 | | |
1828 | 0 | default: |
1829 | 0 | fatal (_("Print width has not been initialized (%d)"), print_width); |
1830 | 0 | break; |
1831 | 1.29M | } |
1832 | 1.29M | } |
1833 | | |
1834 | | /* Print a line of information about a symbol. */ |
1835 | | |
1836 | | static void |
1837 | | print_symbol_info_bsd (struct extended_symbol_info *info, bfd *abfd) |
1838 | 1.39M | { |
1839 | 1.39M | if (bfd_is_undefined_symclass (SYM_TYPE (info))) |
1840 | 95.1k | { |
1841 | 95.1k | if (print_width == 64) |
1842 | 52.5k | printf (" "); |
1843 | 95.1k | printf (" "); |
1844 | 95.1k | } |
1845 | 1.29M | else |
1846 | 1.29M | { |
1847 | | /* Normally we print the value of the symbol. If we are printing the |
1848 | | size or sorting by size then we print its size, except for the |
1849 | | (weird) special case where both flags are defined, in which case we |
1850 | | print both values. This conforms to documented behaviour. */ |
1851 | 1.29M | if (sort_by_size && !print_size) |
1852 | 0 | print_value (abfd, SYM_SIZE (info)); |
1853 | 1.29M | else |
1854 | 1.29M | print_value (abfd, SYM_VALUE (info)); |
1855 | 1.29M | if (print_size && SYM_SIZE (info)) |
1856 | 0 | { |
1857 | 0 | printf (" "); |
1858 | 0 | print_value (abfd, SYM_SIZE (info)); |
1859 | 0 | } |
1860 | 1.29M | } |
1861 | | |
1862 | 1.39M | printf (" %c", SYM_TYPE (info)); |
1863 | | |
1864 | 1.39M | if (SYM_TYPE (info) == '-') |
1865 | 4.64k | { |
1866 | | /* A stab. */ |
1867 | 4.64k | printf (" "); |
1868 | 4.64k | printf (other_format, SYM_STAB_OTHER (info)); |
1869 | 4.64k | printf (" "); |
1870 | 4.64k | printf (desc_format, SYM_STAB_DESC (info)); |
1871 | 4.64k | printf (" %5s", SYM_STAB_NAME (info)); |
1872 | 4.64k | } |
1873 | 1.39M | print_symname (" %s", info, NULL, abfd); |
1874 | 1.39M | } |
1875 | | |
1876 | | static void |
1877 | | print_symbol_info_sysv (struct extended_symbol_info *info, bfd *abfd) |
1878 | 0 | { |
1879 | 0 | print_symname ("%-20s|", info, NULL, abfd); |
1880 | |
|
1881 | 0 | if (bfd_is_undefined_symclass (SYM_TYPE (info))) |
1882 | 0 | { |
1883 | 0 | if (print_width == 32) |
1884 | 0 | printf (" "); |
1885 | 0 | else |
1886 | 0 | printf (" "); |
1887 | 0 | } |
1888 | 0 | else |
1889 | 0 | print_value (abfd, SYM_VALUE (info)); |
1890 | |
|
1891 | 0 | printf ("| %c |", SYM_TYPE (info)); |
1892 | |
|
1893 | 0 | if (SYM_TYPE (info) == '-') |
1894 | 0 | { |
1895 | | /* A stab. */ |
1896 | 0 | printf ("%18s| ", SYM_STAB_NAME (info)); /* (C) Type. */ |
1897 | 0 | printf (desc_format, SYM_STAB_DESC (info)); /* Size. */ |
1898 | 0 | printf ("| |"); /* Line, Section. */ |
1899 | 0 | } |
1900 | 0 | else |
1901 | 0 | { |
1902 | | /* Type, Size, Line, Section */ |
1903 | 0 | if (info->elfinfo) |
1904 | 0 | printf ("%18s|", |
1905 | 0 | get_elf_symbol_type (ELF_ST_TYPE (info->elfinfo->internal_elf_sym.st_info))); |
1906 | 0 | else if (info->coffinfo) |
1907 | 0 | printf ("%18s|", |
1908 | 0 | get_coff_symbol_type (&info->coffinfo->native->u.syment)); |
1909 | 0 | else |
1910 | 0 | printf (" |"); |
1911 | |
|
1912 | 0 | if (SYM_SIZE (info)) |
1913 | 0 | print_value (abfd, SYM_SIZE (info)); |
1914 | 0 | else |
1915 | 0 | { |
1916 | 0 | if (print_width == 32) |
1917 | 0 | printf (" "); |
1918 | 0 | else |
1919 | 0 | printf (" "); |
1920 | 0 | } |
1921 | |
|
1922 | 0 | if (info->elfinfo) |
1923 | 0 | printf("| |%s", info->elfinfo->symbol.section->name); |
1924 | 0 | else if (info->coffinfo) |
1925 | 0 | printf("| |%s", info->coffinfo->symbol.section->name); |
1926 | 0 | else |
1927 | 0 | printf("| |"); |
1928 | 0 | } |
1929 | 0 | } |
1930 | | |
1931 | | static void |
1932 | | print_symbol_info_posix (struct extended_symbol_info *info, bfd *abfd) |
1933 | 0 | { |
1934 | 0 | print_symname ("%s ", info, NULL, abfd); |
1935 | 0 | printf ("%c ", SYM_TYPE (info)); |
1936 | |
|
1937 | 0 | if (bfd_is_undefined_symclass (SYM_TYPE (info))) |
1938 | 0 | printf (" "); |
1939 | 0 | else |
1940 | 0 | { |
1941 | 0 | print_value (abfd, SYM_VALUE (info)); |
1942 | 0 | printf (" "); |
1943 | 0 | if (SYM_SIZE (info)) |
1944 | 0 | print_value (abfd, SYM_SIZE (info)); |
1945 | 0 | } |
1946 | 0 | } |
1947 | | |
1948 | | static void |
1949 | | just_print_symbol_name (struct extended_symbol_info *info, bfd *abfd) |
1950 | 0 | { |
1951 | 0 | print_symname ("%s", info, NULL, abfd); |
1952 | 0 | } |
1953 | | |
1954 | | int |
1955 | | old_main32 (int argc, char **argv); |
1956 | | int old_main32 (int argc, char **argv) |
1957 | 0 | { |
1958 | 0 | int c; |
1959 | 0 | int retval; |
1960 | |
|
1961 | 0 | #ifdef HAVE_LC_MESSAGES |
1962 | 0 | setlocale (LC_MESSAGES, ""); |
1963 | 0 | #endif |
1964 | 0 | setlocale (LC_CTYPE, ""); |
1965 | 0 | setlocale (LC_COLLATE, ""); |
1966 | 0 | bindtextdomain (PACKAGE, LOCALEDIR); |
1967 | 0 | textdomain (PACKAGE); |
1968 | |
|
1969 | 0 | program_name = *argv; |
1970 | 0 | xmalloc_set_program_name (program_name); |
1971 | 0 | bfd_set_error_program_name (program_name); |
1972 | 0 | #if BFD_SUPPORTS_PLUGINS |
1973 | 0 | bfd_plugin_set_program_name (program_name); |
1974 | 0 | #endif |
1975 | |
|
1976 | 0 | expandargv (&argc, &argv); |
1977 | |
|
1978 | 0 | if (bfd_init () != BFD_INIT_MAGIC) |
1979 | 0 | fatal (_("fatal error: libbfd ABI mismatch")); |
1980 | 0 | set_default_bfd_target (); |
1981 | |
|
1982 | 0 | while ((c = getopt_long (argc, argv, "aABCDef:gHhjJlnopPrSst:uU:vVvWX:", |
1983 | 0 | long_options, (int *) 0)) != EOF) |
1984 | 0 | { |
1985 | 0 | switch (c) |
1986 | 0 | { |
1987 | 0 | case 'a': |
1988 | 0 | print_debug_syms = 1; |
1989 | 0 | break; |
1990 | 0 | case 'A': |
1991 | 0 | case 'o': |
1992 | 0 | filename_per_symbol = 1; |
1993 | 0 | break; |
1994 | 0 | case 'B': /* For MIPS compatibility. */ |
1995 | 0 | set_output_format ("bsd"); |
1996 | 0 | break; |
1997 | 0 | case 'C': |
1998 | 0 | do_demangle = 1; |
1999 | 0 | if (optarg != NULL) |
2000 | 0 | { |
2001 | 0 | enum demangling_styles style; |
2002 | |
|
2003 | 0 | style = cplus_demangle_name_to_style (optarg); |
2004 | 0 | if (style == unknown_demangling) |
2005 | 0 | fatal (_("unknown demangling style `%s'"), |
2006 | 0 | optarg); |
2007 | | |
2008 | 0 | cplus_demangle_set_style (style); |
2009 | 0 | } |
2010 | 0 | break; |
2011 | 0 | case OPTION_RECURSE_LIMIT: |
2012 | 0 | demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT; |
2013 | 0 | break; |
2014 | 0 | case OPTION_NO_RECURSE_LIMIT: |
2015 | 0 | demangle_flags |= DMGL_NO_RECURSE_LIMIT; |
2016 | 0 | break; |
2017 | 0 | case OPTION_QUIET: |
2018 | 0 | quiet = 1; |
2019 | 0 | break; |
2020 | 0 | case 'D': |
2021 | 0 | dynamic = 1; |
2022 | 0 | break; |
2023 | 0 | case 'e': |
2024 | | /* Ignored for HP/UX compatibility. */ |
2025 | 0 | break; |
2026 | 0 | case 'f': |
2027 | 0 | set_output_format (optarg); |
2028 | 0 | break; |
2029 | 0 | case 'g': |
2030 | 0 | external_only = 1; |
2031 | 0 | break; |
2032 | 0 | case 'H': |
2033 | 0 | case 'h': |
2034 | 0 | usage (stdout, 0); |
2035 | 0 | case 'l': |
2036 | 0 | line_numbers = 1; |
2037 | 0 | break; |
2038 | 0 | case 'n': |
2039 | 0 | case 'v': |
2040 | 0 | no_sort = 0; |
2041 | 0 | sort_numerically = 1; |
2042 | 0 | sort_by_size = 0; |
2043 | 0 | break; |
2044 | 0 | case 'p': |
2045 | 0 | no_sort = 1; |
2046 | 0 | sort_numerically = 0; |
2047 | 0 | sort_by_size = 0; |
2048 | 0 | break; |
2049 | 0 | case OPTION_SIZE_SORT: |
2050 | 0 | no_sort = 0; |
2051 | 0 | sort_numerically = 0; |
2052 | 0 | sort_by_size = 1; |
2053 | 0 | break; |
2054 | 0 | case 'P': |
2055 | 0 | set_output_format ("posix"); |
2056 | 0 | break; |
2057 | 0 | case 'j': |
2058 | 0 | set_output_format ("just-symbols"); |
2059 | 0 | break; |
2060 | 0 | case 'r': |
2061 | 0 | reverse_sort = 1; |
2062 | 0 | break; |
2063 | 0 | case 's': |
2064 | 0 | print_armap = 1; |
2065 | 0 | break; |
2066 | 0 | case 'S': |
2067 | 0 | print_size = 1; |
2068 | 0 | break; |
2069 | 0 | case 't': |
2070 | 0 | set_print_radix (optarg); |
2071 | 0 | break; |
2072 | 0 | case 'u': |
2073 | 0 | undefined_only = 1; |
2074 | 0 | defined_only = 0; |
2075 | 0 | break; |
2076 | 0 | case 'U': |
2077 | 0 | defined_only = 1; |
2078 | 0 | undefined_only = 0; |
2079 | 0 | break; |
2080 | | |
2081 | 0 | case OPTION_UNICODE: |
2082 | 0 | if (streq (optarg, "default") || streq (optarg, "d")) |
2083 | 0 | unicode_display = unicode_default; |
2084 | 0 | else if (streq (optarg, "locale") || streq (optarg, "l")) |
2085 | 0 | unicode_display = unicode_locale; |
2086 | 0 | else if (streq (optarg, "escape") || streq (optarg, "e")) |
2087 | 0 | unicode_display = unicode_escape; |
2088 | 0 | else if (streq (optarg, "invalid") || streq (optarg, "i")) |
2089 | 0 | unicode_display = unicode_invalid; |
2090 | 0 | else if (streq (optarg, "hex") || streq (optarg, "x")) |
2091 | 0 | unicode_display = unicode_hex; |
2092 | 0 | else if (streq (optarg, "highlight") || streq (optarg, "h")) |
2093 | 0 | unicode_display = unicode_highlight; |
2094 | 0 | else |
2095 | 0 | fatal (_("invalid argument to -U/--unicode: %s"), optarg); |
2096 | 0 | break; |
2097 | | |
2098 | 0 | case 'V': |
2099 | 0 | show_version = 1; |
2100 | 0 | break; |
2101 | 0 | case 'W': |
2102 | 0 | non_weak = 1; |
2103 | 0 | break; |
2104 | 0 | case 'X': |
2105 | | /* Ignored for (partial) AIX compatibility. On AIX, the |
2106 | | argument has values 32, 64, or 32_64, and specifies that |
2107 | | only 32-bit, only 64-bit, or both kinds of objects should |
2108 | | be examined. The default is 32. So plain AIX nm on a |
2109 | | library archive with both kinds of objects will ignore |
2110 | | the 64-bit ones. For GNU nm, the default is and always |
2111 | | has been -X 32_64, and other options are not supported. */ |
2112 | 0 | if (strcmp (optarg, "32_64") != 0) |
2113 | 0 | fatal (_("Only -X 32_64 is supported")); |
2114 | 0 | break; |
2115 | | |
2116 | 0 | case OPTION_TARGET: /* --target */ |
2117 | 0 | target = optarg; |
2118 | 0 | break; |
2119 | | |
2120 | 0 | case OPTION_PLUGIN: /* --plugin */ |
2121 | 0 | #if BFD_SUPPORTS_PLUGINS |
2122 | 0 | bfd_plugin_set_plugin (optarg); |
2123 | | #else |
2124 | | fatal (_("sorry - this program has been built without plugin support\n")); |
2125 | | #endif |
2126 | 0 | break; |
2127 | | |
2128 | 0 | case OPTION_IFUNC_CHARS: |
2129 | 0 | ifunc_type_chars = optarg; |
2130 | 0 | break; |
2131 | | |
2132 | 0 | case 0: /* A long option that just sets a flag. */ |
2133 | 0 | break; |
2134 | | |
2135 | 0 | default: |
2136 | 0 | usage (stderr, 1); |
2137 | 0 | } |
2138 | 0 | } |
2139 | | |
2140 | 0 | if (show_version) |
2141 | 0 | print_version ("nm"); |
2142 | |
|
2143 | 0 | if (sort_by_size && undefined_only) |
2144 | 0 | { |
2145 | 0 | non_fatal (_("Using the --size-sort and --undefined-only options together")); |
2146 | 0 | non_fatal (_("will produce no output, since undefined symbols have no size.")); |
2147 | 0 | return 0; |
2148 | 0 | } |
2149 | | |
2150 | | /* OK, all options now parsed. If no filename specified, do a.out. */ |
2151 | 0 | if (optind == argc) |
2152 | 0 | return !display_file ("a.out"); |
2153 | | |
2154 | 0 | retval = 0; |
2155 | |
|
2156 | 0 | if (argc - optind > 1) |
2157 | 0 | filename_per_file = 1; |
2158 | | |
2159 | | /* We were given several filenames to do. */ |
2160 | 0 | while (optind < argc) |
2161 | 0 | { |
2162 | 0 | if (!display_file (argv[optind++])) |
2163 | 0 | retval++; |
2164 | 0 | } |
2165 | |
|
2166 | 0 | exit (retval); |
2167 | 0 | return retval; |
2168 | 0 | } |