1 /* nm.c -- Describe symbol table of a rel file.
2 Copyright (C) 1991-2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 #include "aout/stab_gnu.h"
26 #include "aout/ranlib.h"
28 #include "libiberty.h"
30 #include "elf/common.h"
31 #define DO_NOT_DEFINE_AOUTHDR
32 #define DO_NOT_DEFINE_FILHDR
33 #define DO_NOT_DEFINE_LINENO
34 #define DO_NOT_DEFINE_SCNHDR
35 #include "coff/external.h"
36 #include "coff/internal.h"
39 #include "plugin-api.h"
42 /* When sorting by size, we use this structure to hold the size and a
43 pointer to the minisymbol. */
51 /* When fetching relocs, we use this structure to pass information to
54 struct get_relocs_info
62 struct extended_symbol_info
66 elf_symbol_type
*elfinfo
;
67 coff_symbol_type
*coffinfo
;
68 /* FIXME: We should add more fields for Type, Line, Section. */
70 #define SYM_VALUE(sym) (sym->sinfo->value)
71 #define SYM_TYPE(sym) (sym->sinfo->type)
72 #define SYM_STAB_NAME(sym) (sym->sinfo->stab_name)
73 #define SYM_STAB_DESC(sym) (sym->sinfo->stab_desc)
74 #define SYM_STAB_OTHER(sym) (sym->sinfo->stab_other)
75 #define SYM_SIZE(sym) \
76 (sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize)
78 /* The output formatting functions. */
79 static void print_object_filename_bsd (const char *);
80 static void print_object_filename_sysv (const char *);
81 static void print_object_filename_posix (const char *);
82 static void do_not_print_object_filename (const char *);
84 static void print_archive_filename_bsd (const char *);
85 static void print_archive_filename_sysv (const char *);
86 static void print_archive_filename_posix (const char *);
87 static void do_not_print_archive_filename (const char *);
89 static void print_archive_member_bsd (const char *, const char *);
90 static void print_archive_member_sysv (const char *, const char *);
91 static void print_archive_member_posix (const char *, const char *);
92 static void do_not_print_archive_member (const char *, const char *);
94 static void print_symbol_filename_bsd (bfd
*, bfd
*);
95 static void print_symbol_filename_sysv (bfd
*, bfd
*);
96 static void print_symbol_filename_posix (bfd
*, bfd
*);
97 static void do_not_print_symbol_filename (bfd
*, bfd
*);
99 static void print_symbol_info_bsd (struct extended_symbol_info
*, bfd
*);
100 static void print_symbol_info_sysv (struct extended_symbol_info
*, bfd
*);
101 static void print_symbol_info_posix (struct extended_symbol_info
*, bfd
*);
102 static void just_print_symbol_name (struct extended_symbol_info
*, bfd
*);
104 static void print_value (bfd
*, bfd_vma
);
106 /* Support for different output formats. */
109 /* Print the name of an object file given on the command line. */
110 void (*print_object_filename
) (const char *);
112 /* Print the name of an archive file given on the command line. */
113 void (*print_archive_filename
) (const char *);
115 /* Print the name of an archive member file. */
116 void (*print_archive_member
) (const char *, const char *);
118 /* Print the name of the file (and archive, if there is one)
119 containing a symbol. */
120 void (*print_symbol_filename
) (bfd
*, bfd
*);
122 /* Print a line of information about a symbol. */
123 void (*print_symbol_info
) (struct extended_symbol_info
*, bfd
*);
126 /* Indices in `formats'. */
136 #define FORMAT_DEFAULT FORMAT_BSD
138 static struct output_fns formats
[FORMAT_MAX
] =
140 {print_object_filename_bsd
,
141 print_archive_filename_bsd
,
142 print_archive_member_bsd
,
143 print_symbol_filename_bsd
,
144 print_symbol_info_bsd
},
145 {print_object_filename_sysv
,
146 print_archive_filename_sysv
,
147 print_archive_member_sysv
,
148 print_symbol_filename_sysv
,
149 print_symbol_info_sysv
},
150 {print_object_filename_posix
,
151 print_archive_filename_posix
,
152 print_archive_member_posix
,
153 print_symbol_filename_posix
,
154 print_symbol_info_posix
},
155 {do_not_print_object_filename
,
156 do_not_print_archive_filename
,
157 do_not_print_archive_member
,
158 do_not_print_symbol_filename
,
159 just_print_symbol_name
}
163 /* The output format to use. */
164 static struct output_fns
*format
= &formats
[FORMAT_DEFAULT
];
165 static unsigned int print_format
= FORMAT_DEFAULT
;
166 static const char *print_format_string
= NULL
;
168 /* Command options. */
170 static int do_demangle
= 0; /* Pretty print C++ symbol names. */
171 static int external_only
= 0; /* Print external symbols only. */
172 static int defined_only
= 0; /* Print defined symbols only. */
173 static int no_sort
= 0; /* Don't sort; print syms in order found. */
174 static int print_debug_syms
= 0;/* Print debugger-only symbols too. */
175 static int print_armap
= 0; /* Describe __.SYMDEF data in archive files. */
176 static int print_size
= 0; /* Print size of defined symbols. */
177 static int reverse_sort
= 0; /* Sort in downward(alpha or numeric) order. */
178 static int sort_numerically
= 0;/* Sort in numeric rather than alpha order. */
179 static int sort_by_size
= 0; /* Sort by size of symbol. */
180 static int undefined_only
= 0; /* Print undefined symbols only. */
181 static int dynamic
= 0; /* Print dynamic symbols. */
182 static int show_version
= 0; /* Show the version number. */
183 static int show_synthetic
= 0; /* Display synthesized symbols too. */
184 static int line_numbers
= 0; /* Print line numbers for symbols. */
185 static int allow_special_symbols
= 0; /* Allow special symbols. */
186 static int with_symbol_versions
= -1; /* Output symbol version information. */
187 static int quiet
= 0; /* Suppress "no symbols" diagnostic. */
189 /* The characters to use for global and local ifunc symbols. */
190 #if DEFAULT_F_FOR_IFUNC_SYMBOLS
191 static const char * ifunc_type_chars
= "Ff";
193 static const char * ifunc_type_chars
= NULL
;
196 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
198 /* When to print the names of files. Not mutually exclusive in SYSV format. */
199 static int filename_per_file
= 0; /* Once per file, on its own line. */
200 static int filename_per_symbol
= 0; /* Once per symbol, at start of line. */
202 static int print_width
= 0;
203 static int print_radix
= 16;
204 /* Print formats for printing stab info. */
205 static char other_format
[] = "%02x";
206 static char desc_format
[] = "%04x";
208 static char *target
= NULL
;
209 #if BFD_SUPPORTS_PLUGINS
210 static const char *plugin_target
= "plugin";
212 static const char *plugin_target
= NULL
;
215 /* Used to cache the line numbers for a BFD. */
216 static bfd
*lineno_cache_bfd
;
217 static bfd
*lineno_cache_rel_bfd
;
219 enum long_option_values
224 OPTION_RECURSE_LIMIT
,
225 OPTION_NO_RECURSE_LIMIT
,
230 static struct option long_options
[] =
232 {"debug-syms", no_argument
, &print_debug_syms
, 1},
233 {"demangle", optional_argument
, 0, 'C'},
234 {"dynamic", no_argument
, &dynamic
, 1},
235 {"extern-only", no_argument
, &external_only
, 1},
236 {"format", required_argument
, 0, 'f'},
237 {"help", no_argument
, 0, 'h'},
238 {"ifunc-chars", required_argument
, 0, OPTION_IFUNC_CHARS
},
239 {"just-symbols", no_argument
, 0, 'j'},
240 {"line-numbers", no_argument
, 0, 'l'},
241 {"no-cplus", no_argument
, &do_demangle
, 0}, /* Linux compatibility. */
242 {"no-demangle", no_argument
, &do_demangle
, 0},
243 {"no-recurse-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
244 {"no-recursion-limit", no_argument
, NULL
, OPTION_NO_RECURSE_LIMIT
},
245 {"no-sort", no_argument
, 0, 'p'},
246 {"numeric-sort", no_argument
, 0, 'n'},
247 {"plugin", required_argument
, 0, OPTION_PLUGIN
},
248 {"portability", no_argument
, 0, 'P'},
249 {"print-armap", no_argument
, &print_armap
, 1},
250 {"print-file-name", no_argument
, 0, 'o'},
251 {"print-size", no_argument
, 0, 'S'},
252 {"quiet", no_argument
, 0, OPTION_QUIET
},
253 {"radix", required_argument
, 0, 't'},
254 {"recurse-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
255 {"recursion-limit", no_argument
, NULL
, OPTION_RECURSE_LIMIT
},
256 {"reverse-sort", no_argument
, &reverse_sort
, 1},
257 {"size-sort", no_argument
, 0, OPTION_SIZE_SORT
},
258 {"special-syms", no_argument
, &allow_special_symbols
, 1},
259 {"synthetic", no_argument
, &show_synthetic
, 1},
260 {"target", required_argument
, 0, OPTION_TARGET
},
261 {"defined-only", no_argument
, &defined_only
, 1},
262 {"undefined-only", no_argument
, &undefined_only
, 1},
263 {"version", no_argument
, &show_version
, 1},
264 {"with-symbol-versions", no_argument
, &with_symbol_versions
, 1},
265 {"without-symbol-versions", no_argument
, &with_symbol_versions
, 0},
266 {0, no_argument
, 0, 0}
269 /* Some error-reporting functions. */
271 ATTRIBUTE_NORETURN
static void
272 usage (FILE *stream
, int status
)
274 fprintf (stream
, _("Usage: %s [option(s)] [file(s)]\n"), program_name
);
275 fprintf (stream
, _(" List symbols in [file(s)] (a.out by default).\n"));
276 fprintf (stream
, _(" The options are:\n\
277 -a, --debug-syms Display debugger-only symbols\n\
278 -A, --print-file-name Print name of the input file before every symbol\n\
279 -B Same as --format=bsd\n\
280 -C, --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
281 The STYLE, if specified, can be `auto' (the default),\n\
282 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
284 --no-demangle Do not demangle low-level symbol names\n\
285 --recurse-limit Enable a demangling recursion limit. This is the default.\n\
286 --no-recurse-limit Disable a demangling recursion limit.\n\
287 -D, --dynamic Display dynamic symbols instead of normal symbols\n\
288 --defined-only Display only defined symbols\n\
290 -f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',\n\
291 `sysv', `posix' or 'just-symbols'. The default is `bsd'\n\
292 -g, --extern-only Display only external symbols\n\
293 --ifunc-chars=CHARS Characters to use when displaying ifunc symbols\n\
294 -j, --just-symbols Same as --format=just-symbols\n\
295 -l, --line-numbers Use debugging information to find a filename and\n\
296 line number for each symbol\n\
297 -n, --numeric-sort Sort symbols numerically by address\n\
299 -p, --no-sort Do not sort the symbols\n\
300 -P, --portability Same as --format=posix\n\
301 -r, --reverse-sort Reverse the sense of the sort\n"));
302 #if BFD_SUPPORTS_PLUGINS
303 fprintf (stream
, _("\
304 --plugin NAME Load the specified plugin\n"));
306 fprintf (stream
, _("\
307 -S, --print-size Print size of defined symbols\n\
308 -s, --print-armap Include index for symbols from archive members\n\
309 --quiet Suppress \"no symbols\" diagnostic\n\
310 --size-sort Sort symbols by size\n\
311 --special-syms Include special symbols in the output\n\
312 --synthetic Display synthetic symbols as well\n\
313 -t, --radix=RADIX Use RADIX for printing symbol values\n\
314 --target=BFDNAME Specify the target object format as BFDNAME\n\
315 -u, --undefined-only Display only undefined symbols\n\
316 --with-symbol-versions Display version strings after symbol names\n\
317 -X 32_64 (ignored)\n\
318 @FILE Read options from FILE\n\
319 -h, --help Display this information\n\
320 -V, --version Display this program's version number\n\
322 list_supported_targets (program_name
, stream
);
323 if (REPORT_BUGS_TO
[0] && status
== 0)
324 fprintf (stream
, _("Report bugs to %s.\n"), REPORT_BUGS_TO
);
328 /* Set the radix for the symbol value and size according to RADIX. */
331 set_print_radix (char *radix
)
335 case 'x': print_radix
= 16; break;
336 case 'd': print_radix
= 10; break;
337 case 'o': print_radix
= 8; break;
340 fatal (_("%s: invalid radix"), radix
);
343 other_format
[3] = desc_format
[3] = *radix
;
347 set_output_format (char *f
)
367 i
= FORMAT_JUST_SYMBOLS
;
370 fatal (_("%s: invalid output format"), f
);
372 format
= &formats
[i
];
377 get_elf_symbol_type (unsigned int type
)
384 case STT_NOTYPE
: return "NOTYPE";
385 case STT_OBJECT
: return "OBJECT";
386 case STT_FUNC
: return "FUNC";
387 case STT_SECTION
: return "SECTION";
388 case STT_FILE
: return "FILE";
389 case STT_COMMON
: return "COMMON";
390 case STT_TLS
: return "TLS";
394 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
395 n
= asprintf (&bufp
, _("<processor specific>: %d"), type
);
396 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
397 n
= asprintf (&bufp
, _("<OS specific>: %d"), type
);
399 n
= asprintf (&bufp
, _("<unknown>: %d"), type
);
401 fatal ("%s", xstrerror (errno
));
406 get_coff_symbol_type (const struct internal_syment
*sym
)
411 switch (sym
->n_sclass
)
413 case C_BLOCK
: return "Block";
414 case C_FILE
: return "File";
415 case C_LINE
: return "Line";
421 switch (DTYPE(sym
->n_type
))
423 case DT_FCN
: return "Function";
424 case DT_PTR
: return "Pointer";
425 case DT_ARY
: return "Array";
429 n
= asprintf (&bufp
, _("<unknown>: %d/%d"), sym
->n_sclass
, sym
->n_type
);
431 fatal ("%s", xstrerror (errno
));
435 /* Print symbol name NAME, read from ABFD, with printf format FORM,
436 demangling it if requested. */
439 print_symname (const char *form
, struct extended_symbol_info
*info
,
440 const char *name
, bfd
*abfd
)
446 name
= info
->sinfo
->name
;
447 if (!with_symbol_versions
448 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
450 atver
= strchr (name
, '@');
454 if (do_demangle
&& *name
)
456 alloc
= bfd_demangle (abfd
, name
, demangle_flags
);
461 if (info
!= NULL
&& info
->elfinfo
&& with_symbol_versions
)
463 const char *version_string
;
467 = bfd_get_symbol_version_string (abfd
, &info
->elfinfo
->symbol
,
469 if (version_string
&& version_string
[0])
471 const char *at
= "@@";
472 if (hidden
|| bfd_is_und_section (info
->elfinfo
->symbol
.section
))
474 alloc
= reconcat (alloc
, name
, at
, version_string
, NULL
);
486 print_symdef_entry (bfd
*abfd
)
488 symindex idx
= BFD_NO_MORE_SYMBOLS
;
490 bool everprinted
= false;
492 for (idx
= bfd_get_next_mapent (abfd
, idx
, &thesym
);
493 idx
!= BFD_NO_MORE_SYMBOLS
;
494 idx
= bfd_get_next_mapent (abfd
, idx
, &thesym
))
499 printf (_("\nArchive index:\n"));
502 elt
= bfd_get_elt_at_index (abfd
, idx
);
504 bfd_fatal ("bfd_get_elt_at_index");
505 if (thesym
->name
!= (char *) NULL
)
507 print_symname ("%s", NULL
, thesym
->name
, abfd
);
508 printf (" in %s\n", bfd_get_filename (elt
));
514 /* True when we can report missing plugin error. */
515 bool report_plugin_err
= true;
517 /* Choose which symbol entries to print;
518 compact them downward to get rid of the rest.
519 Return the number of symbols to be printed. */
522 filter_symbols (bfd
*abfd
, bool is_dynamic
, void *minisyms
,
523 long symcount
, unsigned int size
)
525 bfd_byte
*from
, *fromend
, *to
;
528 store
= bfd_make_empty_symbol (abfd
);
530 bfd_fatal (bfd_get_filename (abfd
));
532 from
= (bfd_byte
*) minisyms
;
533 fromend
= from
+ symcount
* size
;
534 to
= (bfd_byte
*) minisyms
;
536 for (; from
< fromend
; from
+= size
)
543 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, (const void *) from
, store
);
545 bfd_fatal (bfd_get_filename (abfd
));
547 if (sym
->name
[0] == '_'
548 && sym
->name
[1] == '_'
549 && strcmp (sym
->name
+ (sym
->name
[2] == '_'), "__gnu_lto_slim") == 0
550 && report_plugin_err
)
552 report_plugin_err
= false;
553 non_fatal (_("%s: plugin needed to handle lto object"),
554 bfd_get_filename (abfd
));
558 keep
= bfd_is_und_section (sym
->section
);
559 else if (external_only
)
560 /* PR binutls/12753: Unique symbols are global too. */
561 keep
= ((sym
->flags
& (BSF_GLOBAL
563 | BSF_GNU_UNIQUE
)) != 0
564 || bfd_is_und_section (sym
->section
)
565 || bfd_is_com_section (sym
->section
));
570 && ! print_debug_syms
571 && (sym
->flags
& BSF_DEBUGGING
) != 0)
576 && (bfd_is_abs_section (sym
->section
)
577 || bfd_is_und_section (sym
->section
)))
583 if (bfd_is_und_section (sym
->section
))
588 && bfd_is_target_special_symbol (abfd
, sym
)
589 && ! allow_special_symbols
)
595 memcpy (to
, from
, size
);
600 return (to
- (bfd_byte
*) minisyms
) / size
;
603 /* These globals are used to pass information into the sorting
605 static bfd
*sort_bfd
;
606 static bool sort_dynamic
;
607 static asymbol
*sort_x
;
608 static asymbol
*sort_y
;
610 /* Symbol-sorting predicates */
611 #define valueof(x) ((x)->section->vma + (x)->value)
613 /* Numeric sorts. Undefined symbols are always considered "less than"
614 defined symbols with zero values. Common symbols are not treated
615 specially -- i.e., their sizes are used as their "values". */
618 non_numeric_forward (const void *P_x
, const void *P_y
)
623 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
624 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
625 if (x
== NULL
|| y
== NULL
)
626 bfd_fatal (bfd_get_filename (sort_bfd
));
628 xn
= bfd_asymbol_name (x
);
629 yn
= bfd_asymbol_name (y
);
636 /* Solaris 2.5 has a bug in strcoll.
637 strcoll returns invalid values when confronted with empty strings. */
643 return strcoll (xn
, yn
);
647 non_numeric_reverse (const void *x
, const void *y
)
649 return - non_numeric_forward (x
, y
);
653 numeric_forward (const void *P_x
, const void *P_y
)
658 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
659 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
660 if (x
== NULL
|| y
== NULL
)
661 bfd_fatal (bfd_get_filename (sort_bfd
));
663 xs
= bfd_asymbol_section (x
);
664 ys
= bfd_asymbol_section (y
);
666 if (bfd_is_und_section (xs
))
668 if (! bfd_is_und_section (ys
))
671 else if (bfd_is_und_section (ys
))
673 else if (valueof (x
) != valueof (y
))
674 return valueof (x
) < valueof (y
) ? -1 : 1;
676 return non_numeric_forward (P_x
, P_y
);
680 numeric_reverse (const void *x
, const void *y
)
682 return - numeric_forward (x
, y
);
685 static int (*(sorters
[2][2])) (const void *, const void *) =
687 { non_numeric_forward
, non_numeric_reverse
},
688 { numeric_forward
, numeric_reverse
}
691 /* This sort routine is used by sort_symbols_by_size. It is similar
692 to numeric_forward, but when symbols have the same value it sorts
693 by section VMA. This simplifies the sort_symbols_by_size code
694 which handles symbols at the end of sections. Also, this routine
695 tries to sort file names before other symbols with the same value.
696 That will make the file name have a zero size, which will make
697 sort_symbols_by_size choose the non file name symbol, leading to
698 more meaningful output. For similar reasons, this code sorts
699 gnu_compiled_* and gcc2_compiled before other symbols with the same
703 size_forward1 (const void *P_x
, const void *P_y
)
711 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
712 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
713 if (x
== NULL
|| y
== NULL
)
714 bfd_fatal (bfd_get_filename (sort_bfd
));
716 xs
= bfd_asymbol_section (x
);
717 ys
= bfd_asymbol_section (y
);
719 if (bfd_is_und_section (xs
))
721 if (bfd_is_und_section (ys
))
724 if (valueof (x
) != valueof (y
))
725 return valueof (x
) < valueof (y
) ? -1 : 1;
727 if (xs
->vma
!= ys
->vma
)
728 return xs
->vma
< ys
->vma
? -1 : 1;
730 xn
= bfd_asymbol_name (x
);
731 yn
= bfd_asymbol_name (y
);
735 /* The symbols gnu_compiled and gcc2_compiled convey even less
736 information than the file name, so sort them out first. */
738 xf
= (strstr (xn
, "gnu_compiled") != NULL
739 || strstr (xn
, "gcc2_compiled") != NULL
);
740 yf
= (strstr (yn
, "gnu_compiled") != NULL
741 || strstr (yn
, "gcc2_compiled") != NULL
);
748 /* We use a heuristic for the file name. It may not work on non
749 Unix systems, but it doesn't really matter; the only difference
750 is precisely which symbol names get printed. */
752 #define file_symbol(s, sn, snl) \
753 (((s)->flags & BSF_FILE) != 0 \
755 && (sn)[(snl) - 2] == '.' \
756 && ((sn)[(snl) - 1] == 'o' \
757 || (sn)[(snl) - 1] == 'a')))
759 xf
= file_symbol (x
, xn
, xnl
);
760 yf
= file_symbol (y
, yn
, ynl
);
767 return non_numeric_forward (P_x
, P_y
);
770 /* This sort routine is used by sort_symbols_by_size. It is sorting
771 an array of size_sym structures into size order. */
774 size_forward2 (const void *P_x
, const void *P_y
)
776 const struct size_sym
*x
= (const struct size_sym
*) P_x
;
777 const struct size_sym
*y
= (const struct size_sym
*) P_y
;
779 if (x
->size
< y
->size
)
780 return reverse_sort
? 1 : -1;
781 else if (x
->size
> y
->size
)
782 return reverse_sort
? -1 : 1;
784 return sorters
[0][reverse_sort
] (x
->minisym
, y
->minisym
);
787 /* Sort the symbols by size. ELF provides a size but for other formats
788 we have to make a guess by assuming that the difference between the
789 address of a symbol and the address of the next higher symbol is the
793 sort_symbols_by_size (bfd
*abfd
, bool is_dynamic
, void *minisyms
,
794 long symcount
, unsigned int size
,
795 struct size_sym
**symsizesp
)
797 struct size_sym
*symsizes
;
798 bfd_byte
*from
, *fromend
;
800 asymbol
*store_sym
, *store_next
;
802 qsort (minisyms
, symcount
, size
, size_forward1
);
804 /* We are going to return a special set of symbols and sizes to
806 symsizes
= (struct size_sym
*) xmalloc (symcount
* sizeof (struct size_sym
));
807 *symsizesp
= symsizes
;
809 /* Note that filter_symbols has already removed all absolute and
810 undefined symbols. Here we remove all symbols whose size winds
812 from
= (bfd_byte
*) minisyms
;
813 fromend
= from
+ symcount
* size
;
820 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, (const void *) from
,
823 bfd_fatal (bfd_get_filename (abfd
));
826 for (; from
< fromend
; from
+= size
)
833 if (from
+ size
< fromend
)
835 next
= bfd_minisymbol_to_symbol (abfd
,
837 (const void *) (from
+ size
),
840 bfd_fatal (bfd_get_filename (abfd
));
845 sec
= bfd_asymbol_section (sym
);
847 /* Synthetic symbols don't have a full type set of data available, thus
848 we can't rely on that information for the symbol size. Ditto for
849 bfd/section.c:global_syms like *ABS*. */
850 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0
851 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
852 sz
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
853 else if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0
854 && bfd_is_com_section (sec
))
858 if (from
+ size
< fromend
859 && sec
== bfd_asymbol_section (next
))
860 sz
= valueof (next
) - valueof (sym
);
862 sz
= (bfd_section_vma (sec
)
863 + bfd_section_size (sec
)
869 symsizes
->minisym
= (const void *) from
;
877 store_sym
= store_next
;
881 symcount
= symsizes
- *symsizesp
;
883 /* We must now sort again by size. */
884 qsort ((void *) *symsizesp
, symcount
, sizeof (struct size_sym
), size_forward2
);
889 /* This function is used to get the relocs for a particular section.
890 It is called via bfd_map_over_sections. */
893 get_relocs (bfd
*abfd
, asection
*sec
, void *dataarg
)
895 struct get_relocs_info
*data
= (struct get_relocs_info
*) dataarg
;
899 if ((sec
->flags
& SEC_RELOC
) == 0)
901 *data
->relocs
= NULL
;
908 relsize
= bfd_get_reloc_upper_bound (abfd
, sec
);
910 bfd_fatal (bfd_get_filename (abfd
));
912 *data
->relocs
= (arelent
**) xmalloc (relsize
);
913 *data
->relcount
= bfd_canonicalize_reloc (abfd
, sec
, *data
->relocs
,
915 if (*data
->relcount
< 0)
916 bfd_fatal (bfd_get_filename (abfd
));
924 /* Print a single symbol. */
927 print_symbol (bfd
* abfd
,
933 struct extended_symbol_info info
;
937 format
->print_symbol_filename (archive_bfd
, abfd
);
939 bfd_get_symbol_info (abfd
, sym
, &syminfo
);
941 /* PR 22967 - Distinguish between local and global ifunc symbols. */
942 if (syminfo
.type
== 'i'
943 && sym
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
945 if (ifunc_type_chars
== NULL
|| ifunc_type_chars
[0] == 0)
946 ; /* Change nothing. */
947 else if (sym
->flags
& BSF_GLOBAL
)
948 syminfo
.type
= ifunc_type_chars
[0];
949 else if (ifunc_type_chars
[1] != 0)
950 syminfo
.type
= ifunc_type_chars
[1];
953 info
.sinfo
= &syminfo
;
955 /* Synthetic symbols do not have a full symbol type set of data available.
956 Nor do bfd/section.c:global_syms like *ABS*. */
957 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) != 0)
960 info
.coffinfo
= NULL
;
964 info
.elfinfo
= elf_symbol_from (sym
);
965 info
.coffinfo
= coff_symbol_from (sym
);
968 format
->print_symbol_info (&info
, abfd
);
972 static asymbol
**syms
;
973 static long symcount
;
974 const char *filename
, *functionname
;
977 /* We need to get the canonical symbols in order to call
978 bfd_find_nearest_line. This is inefficient, but, then, you
979 don't have to use --line-numbers. */
980 if (abfd
!= lineno_cache_bfd
&& syms
!= NULL
)
989 symsize
= bfd_get_symtab_upper_bound (abfd
);
991 bfd_fatal (bfd_get_filename (abfd
));
992 syms
= (asymbol
**) xmalloc (symsize
);
993 symcount
= bfd_canonicalize_symtab (abfd
, syms
);
995 bfd_fatal (bfd_get_filename (abfd
));
996 lineno_cache_bfd
= abfd
;
999 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1001 static asection
**secs
;
1002 static arelent
***relocs
;
1003 static long *relcount
;
1004 static unsigned int seccount
;
1006 const char *symname
;
1008 /* For an undefined symbol, we try to find a reloc for the
1009 symbol, and print the line number of the reloc. */
1010 if (abfd
!= lineno_cache_rel_bfd
&& relocs
!= NULL
)
1012 for (i
= 0; i
< seccount
; i
++)
1013 if (relocs
[i
] != NULL
)
1025 struct get_relocs_info rinfo
;
1027 seccount
= bfd_count_sections (abfd
);
1029 secs
= (asection
**) xmalloc (seccount
* sizeof *secs
);
1030 relocs
= (arelent
***) xmalloc (seccount
* sizeof *relocs
);
1031 relcount
= (long *) xmalloc (seccount
* sizeof *relcount
);
1034 rinfo
.relocs
= relocs
;
1035 rinfo
.relcount
= relcount
;
1037 bfd_map_over_sections (abfd
, get_relocs
, (void *) &rinfo
);
1038 lineno_cache_rel_bfd
= abfd
;
1041 symname
= bfd_asymbol_name (sym
);
1042 for (i
= 0; i
< seccount
; i
++)
1046 for (j
= 0; j
< relcount
[i
]; j
++)
1051 if (r
->sym_ptr_ptr
!= NULL
1052 && (*r
->sym_ptr_ptr
)->section
== sym
->section
1053 && (*r
->sym_ptr_ptr
)->value
== sym
->value
1055 bfd_asymbol_name (*r
->sym_ptr_ptr
)) == 0
1056 && bfd_find_nearest_line (abfd
, secs
[i
], syms
,
1057 r
->address
, &filename
,
1058 &functionname
, &lineno
)
1059 && filename
!= NULL
)
1061 /* We only print the first one we find. */
1062 printf ("\t%s:%u", filename
, lineno
);
1069 else if (bfd_asymbol_section (sym
)->owner
== abfd
)
1071 if ((bfd_find_line (abfd
, syms
, sym
, &filename
, &lineno
)
1072 || bfd_find_nearest_line (abfd
, bfd_asymbol_section (sym
),
1073 syms
, sym
->value
, &filename
,
1074 &functionname
, &lineno
))
1077 printf ("\t%s:%u", filename
, lineno
);
1084 /* Print the symbols when sorting by size. */
1087 print_size_symbols (bfd
*abfd
,
1089 struct size_sym
*symsizes
,
1094 struct size_sym
*from
;
1095 struct size_sym
*fromend
;
1097 store
= bfd_make_empty_symbol (abfd
);
1099 bfd_fatal (bfd_get_filename (abfd
));
1102 fromend
= from
+ symcount
;
1104 for (; from
< fromend
; from
++)
1108 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, from
->minisym
, store
);
1110 bfd_fatal (bfd_get_filename (abfd
));
1112 print_symbol (abfd
, sym
, from
->size
, archive_bfd
);
1117 /* Print the symbols of ABFD that are held in MINISYMS.
1119 If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD.
1121 SYMCOUNT is the number of symbols in MINISYMS.
1123 SIZE is the size of a symbol in MINISYMS. */
1126 print_symbols (bfd
*abfd
,
1137 store
= bfd_make_empty_symbol (abfd
);
1139 bfd_fatal (bfd_get_filename (abfd
));
1141 from
= (bfd_byte
*) minisyms
;
1142 fromend
= from
+ symcount
* size
;
1144 for (; from
< fromend
; from
+= size
)
1148 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, from
, store
);
1150 bfd_fatal (bfd_get_filename (abfd
));
1152 print_symbol (abfd
, sym
, (bfd_vma
) 0, archive_bfd
);
1156 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */
1159 display_rel_file (bfd
*abfd
, bfd
*archive_bfd
)
1164 struct size_sym
*symsizes
;
1165 asymbol
*synthsyms
= NULL
;
1169 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
1172 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
1177 symcount
= bfd_read_minisymbols (abfd
, dynamic
, &minisyms
, &size
);
1180 if (dynamic
&& bfd_get_error () == bfd_error_no_symbols
)
1183 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
1187 bfd_fatal (bfd_get_filename (abfd
));
1193 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
1197 if (show_synthetic
&& size
== sizeof (asymbol
*))
1199 asymbol
**static_syms
= NULL
;
1200 asymbol
**dyn_syms
= NULL
;
1201 long static_count
= 0;
1207 dyn_count
= symcount
;
1208 dyn_syms
= (asymbol
**) minisyms
;
1212 long storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
1214 static_count
= symcount
;
1215 static_syms
= (asymbol
**) minisyms
;
1219 dyn_syms
= (asymbol
**) xmalloc (storage
);
1220 dyn_count
= bfd_canonicalize_dynamic_symtab (abfd
, dyn_syms
);
1222 bfd_fatal (bfd_get_filename (abfd
));
1226 synth_count
= bfd_get_synthetic_symtab (abfd
, static_count
, static_syms
,
1227 dyn_count
, dyn_syms
, &synthsyms
);
1228 if (synth_count
> 0)
1233 minisyms
= xrealloc (minisyms
,
1234 (symcount
+ synth_count
+ 1) * sizeof (*symp
));
1235 symp
= (asymbol
**) minisyms
+ symcount
;
1236 for (i
= 0; i
< synth_count
; i
++)
1237 *symp
++ = synthsyms
+ i
;
1239 symcount
+= synth_count
;
1241 if (!dynamic
&& dyn_syms
!= NULL
)
1245 /* lto_slim_object is set to false when a bfd is loaded with a compiler
1247 if (abfd
->lto_slim_object
)
1249 report_plugin_err
= false;
1250 non_fatal (_("%s: plugin needed to handle lto object"),
1251 bfd_get_filename (abfd
));
1254 /* Discard the symbols we don't want to print.
1255 It's OK to do this in place; we'll free the storage anyway
1256 (after printing). */
1258 symcount
= filter_symbols (abfd
, dynamic
, minisyms
, symcount
, size
);
1264 sort_dynamic
= dynamic
;
1265 sort_x
= bfd_make_empty_symbol (abfd
);
1266 sort_y
= bfd_make_empty_symbol (abfd
);
1267 if (sort_x
== NULL
|| sort_y
== NULL
)
1268 bfd_fatal (bfd_get_filename (abfd
));
1271 qsort (minisyms
, symcount
, size
,
1272 sorters
[sort_numerically
][reverse_sort
]);
1274 symcount
= sort_symbols_by_size (abfd
, dynamic
, minisyms
, symcount
,
1279 print_symbols (abfd
, dynamic
, minisyms
, symcount
, size
, archive_bfd
);
1281 print_size_symbols (abfd
, dynamic
, symsizes
, symcount
, archive_bfd
);
1289 /* Construct a formatting string for printing symbol values. */
1292 get_print_format (void)
1294 const char * padding
;
1295 if (print_format
== FORMAT_POSIX
|| print_format
== FORMAT_JUST_SYMBOLS
)
1297 /* POSIX compatible output does not have any padding. */
1300 else if (print_width
== 32)
1304 else /* print_width == 64 */
1309 const char * length
= "l";
1310 if (print_width
== 64)
1312 #if BFD_HOST_64BIT_LONG
1314 #elif BFD_HOST_64BIT_LONG_LONG
1323 const char * radix
= NULL
;
1324 switch (print_radix
)
1326 case 8: radix
= "o"; break;
1327 case 10: radix
= "d"; break;
1328 case 16: radix
= "x"; break;
1331 return concat ("%", padding
, length
, radix
, NULL
);
1335 set_print_width (bfd
*file
)
1337 print_width
= bfd_get_arch_size (file
);
1339 if (print_width
== -1)
1342 Guess the target's bitsize based on its name.
1343 We assume here than any 64-bit format will include
1344 "64" somewhere in its name. The only known exception
1345 is the MMO object file format. */
1346 if (strstr (bfd_get_target (file
), "64") != NULL
1347 || strcmp (bfd_get_target (file
), "mmo") == 0)
1352 free ((char *) print_format_string
);
1353 print_format_string
= get_print_format ();
1357 display_archive (bfd
*file
)
1360 bfd
*last_arfile
= NULL
;
1363 format
->print_archive_filename (bfd_get_filename (file
));
1366 print_symdef_entry (file
);
1372 arfile
= bfd_openr_next_archived_file (file
, arfile
);
1376 if (bfd_get_error () != bfd_error_no_more_archived_files
)
1377 bfd_fatal (bfd_get_filename (file
));
1381 if (bfd_check_format_matches (arfile
, bfd_object
, &matching
))
1383 set_print_width (arfile
);
1384 format
->print_archive_member (bfd_get_filename (file
),
1385 bfd_get_filename (arfile
));
1386 display_rel_file (arfile
, file
);
1390 bfd_nonfatal (bfd_get_filename (arfile
));
1391 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
1393 list_matching_formats (matching
);
1398 if (last_arfile
!= NULL
)
1400 bfd_close (last_arfile
);
1401 lineno_cache_bfd
= NULL
;
1402 lineno_cache_rel_bfd
= NULL
;
1403 if (arfile
== last_arfile
)
1406 last_arfile
= arfile
;
1409 if (last_arfile
!= NULL
)
1411 bfd_close (last_arfile
);
1412 lineno_cache_bfd
= NULL
;
1413 lineno_cache_rel_bfd
= NULL
;
1418 display_file (char *filename
)
1424 if (get_file_size (filename
) < 1)
1427 file
= bfd_openr (filename
, target
? target
: plugin_target
);
1430 bfd_nonfatal (filename
);
1434 /* If printing line numbers, decompress the debug sections. */
1436 file
->flags
|= BFD_DECOMPRESS
;
1438 if (bfd_check_format (file
, bfd_archive
))
1440 display_archive (file
);
1442 else if (bfd_check_format_matches (file
, bfd_object
, &matching
))
1444 set_print_width (file
);
1445 format
->print_object_filename (filename
);
1446 display_rel_file (file
, NULL
);
1450 bfd_nonfatal (filename
);
1451 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
1453 list_matching_formats (matching
);
1459 if (!bfd_close (file
))
1460 bfd_fatal (filename
);
1462 lineno_cache_bfd
= NULL
;
1463 lineno_cache_rel_bfd
= NULL
;
1468 /* The following 3 groups of functions are called unconditionally,
1469 once at the start of processing each file of the appropriate type.
1470 They should check `filename_per_file' and `filename_per_symbol',
1471 as appropriate for their output format, to determine whether to
1474 /* Print the name of an object file given on the command line. */
1477 print_object_filename_bsd (const char *filename
)
1479 if (filename_per_file
&& !filename_per_symbol
)
1480 printf ("\n%s:\n", filename
);
1484 print_object_filename_sysv (const char *filename
)
1487 printf (_("\n\nUndefined symbols from %s:\n\n"), filename
);
1489 printf (_("\n\nSymbols from %s:\n\n"), filename
);
1490 if (print_width
== 32)
1492 Name Value Class Type Size Line Section\n\n"));
1495 Name Value Class Type Size Line Section\n\n"));
1499 print_object_filename_posix (const char *filename
)
1501 if (filename_per_file
&& !filename_per_symbol
)
1502 printf ("%s:\n", filename
);
1506 do_not_print_object_filename (const char *filename ATTRIBUTE_UNUSED
)
1510 /* Print the name of an archive file given on the command line. */
1513 print_archive_filename_bsd (const char *filename
)
1515 if (filename_per_file
)
1516 printf ("\n%s:\n", filename
);
1520 print_archive_filename_sysv (const char *filename ATTRIBUTE_UNUSED
)
1525 print_archive_filename_posix (const char *filename ATTRIBUTE_UNUSED
)
1530 do_not_print_archive_filename (const char *filename ATTRIBUTE_UNUSED
)
1534 /* Print the name of an archive member file. */
1537 print_archive_member_bsd (const char *archive ATTRIBUTE_UNUSED
,
1538 const char *filename
)
1540 if (!filename_per_symbol
)
1541 printf ("\n%s:\n", filename
);
1545 print_archive_member_sysv (const char *archive
, const char *filename
)
1548 printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive
, filename
);
1550 printf (_("\n\nSymbols from %s[%s]:\n\n"), archive
, filename
);
1551 if (print_width
== 32)
1553 Name Value Class Type Size Line Section\n\n"));
1556 Name Value Class Type Size Line Section\n\n"));
1560 print_archive_member_posix (const char *archive
, const char *filename
)
1562 if (!filename_per_symbol
)
1563 printf ("%s[%s]:\n", archive
, filename
);
1567 do_not_print_archive_member (const char *archive ATTRIBUTE_UNUSED
,
1568 const char *filename ATTRIBUTE_UNUSED
)
1573 /* Print the name of the file (and archive, if there is one)
1574 containing a symbol. */
1577 print_symbol_filename_bsd (bfd
*archive_bfd
, bfd
*abfd
)
1579 if (filename_per_symbol
)
1582 printf ("%s:", bfd_get_filename (archive_bfd
));
1583 printf ("%s:", bfd_get_filename (abfd
));
1588 print_symbol_filename_sysv (bfd
*archive_bfd
, bfd
*abfd
)
1590 if (filename_per_symbol
)
1593 printf ("%s:", bfd_get_filename (archive_bfd
));
1594 printf ("%s:", bfd_get_filename (abfd
));
1599 print_symbol_filename_posix (bfd
*archive_bfd
, bfd
*abfd
)
1601 if (filename_per_symbol
)
1604 printf ("%s[%s]: ", bfd_get_filename (archive_bfd
),
1605 bfd_get_filename (abfd
));
1607 printf ("%s: ", bfd_get_filename (abfd
));
1612 do_not_print_symbol_filename (bfd
*archive_bfd ATTRIBUTE_UNUSED
,
1613 bfd
*abfd ATTRIBUTE_UNUSED
)
1618 /* Print a symbol value. */
1621 print_value (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma val
)
1623 switch (print_width
)
1626 printf (print_format_string
, (unsigned long) val
);
1630 #if BFD_HOST_64BIT_LONG || BFD_HOST_64BIT_LONG_LONG
1631 printf (print_format_string
, val
);
1633 /* We have a 64 bit value to print, but the host is only 32 bit. */
1634 if (print_radix
== 16)
1635 bfd_fprintf_vma (abfd
, stdout
, val
);
1641 s
= buf
+ sizeof buf
;
1645 *--s
= (val
% print_radix
) + '0';
1648 while ((buf
+ sizeof buf
- 1) - s
< 16)
1656 fatal (_("Print width has not been initialized (%d)"), print_width
);
1661 /* Print a line of information about a symbol. */
1664 print_symbol_info_bsd (struct extended_symbol_info
*info
, bfd
*abfd
)
1666 if (bfd_is_undefined_symclass (SYM_TYPE (info
)))
1668 if (print_width
== 64)
1674 /* Normally we print the value of the symbol. If we are printing the
1675 size or sorting by size then we print its size, except for the
1676 (weird) special case where both flags are defined, in which case we
1677 print both values. This conforms to documented behaviour. */
1678 if (sort_by_size
&& !print_size
)
1679 print_value (abfd
, SYM_SIZE (info
));
1681 print_value (abfd
, SYM_VALUE (info
));
1682 if (print_size
&& SYM_SIZE (info
))
1685 print_value (abfd
, SYM_SIZE (info
));
1689 printf (" %c", SYM_TYPE (info
));
1691 if (SYM_TYPE (info
) == '-')
1695 printf (other_format
, SYM_STAB_OTHER (info
));
1697 printf (desc_format
, SYM_STAB_DESC (info
));
1698 printf (" %5s", SYM_STAB_NAME (info
));
1700 print_symname (" %s", info
, NULL
, abfd
);
1704 print_symbol_info_sysv (struct extended_symbol_info
*info
, bfd
*abfd
)
1706 print_symname ("%-20s|", info
, NULL
, abfd
);
1708 if (bfd_is_undefined_symclass (SYM_TYPE (info
)))
1710 if (print_width
== 32)
1716 print_value (abfd
, SYM_VALUE (info
));
1718 printf ("| %c |", SYM_TYPE (info
));
1720 if (SYM_TYPE (info
) == '-')
1723 printf ("%18s| ", SYM_STAB_NAME (info
)); /* (C) Type. */
1724 printf (desc_format
, SYM_STAB_DESC (info
)); /* Size. */
1725 printf ("| |"); /* Line, Section. */
1729 /* Type, Size, Line, Section */
1732 get_elf_symbol_type (ELF_ST_TYPE (info
->elfinfo
->internal_elf_sym
.st_info
)));
1733 else if (info
->coffinfo
)
1735 get_coff_symbol_type (&info
->coffinfo
->native
->u
.syment
));
1739 if (SYM_SIZE (info
))
1740 print_value (abfd
, SYM_SIZE (info
));
1743 if (print_width
== 32)
1750 printf("| |%s", info
->elfinfo
->symbol
.section
->name
);
1751 else if (info
->coffinfo
)
1752 printf("| |%s", info
->coffinfo
->symbol
.section
->name
);
1759 print_symbol_info_posix (struct extended_symbol_info
*info
, bfd
*abfd
)
1761 print_symname ("%s ", info
, NULL
, abfd
);
1762 printf ("%c ", SYM_TYPE (info
));
1764 if (bfd_is_undefined_symclass (SYM_TYPE (info
)))
1768 print_value (abfd
, SYM_VALUE (info
));
1770 if (SYM_SIZE (info
))
1771 print_value (abfd
, SYM_SIZE (info
));
1776 just_print_symbol_name (struct extended_symbol_info
*info
, bfd
*abfd
)
1778 print_symname ("%s", info
, NULL
, abfd
);
1782 main (int argc
, char **argv
)
1787 #ifdef HAVE_LC_MESSAGES
1788 setlocale (LC_MESSAGES
, "");
1790 setlocale (LC_CTYPE
, "");
1791 setlocale (LC_COLLATE
, "");
1792 bindtextdomain (PACKAGE
, LOCALEDIR
);
1793 textdomain (PACKAGE
);
1795 program_name
= *argv
;
1796 xmalloc_set_program_name (program_name
);
1797 bfd_set_error_program_name (program_name
);
1798 #if BFD_SUPPORTS_PLUGINS
1799 bfd_plugin_set_program_name (program_name
);
1802 START_PROGRESS (program_name
, 0);
1804 expandargv (&argc
, &argv
);
1806 if (bfd_init () != BFD_INIT_MAGIC
)
1807 fatal (_("fatal error: libbfd ABI mismatch"));
1808 set_default_bfd_target ();
1810 while ((c
= getopt_long (argc
, argv
, "aABCDef:gHhjJlnopPrSst:uvVvX:",
1811 long_options
, (int *) 0)) != EOF
)
1816 print_debug_syms
= 1;
1820 filename_per_symbol
= 1;
1822 case 'B': /* For MIPS compatibility. */
1823 set_output_format ("bsd");
1829 enum demangling_styles style
;
1831 style
= cplus_demangle_name_to_style (optarg
);
1832 if (style
== unknown_demangling
)
1833 fatal (_("unknown demangling style `%s'"),
1836 cplus_demangle_set_style (style
);
1839 case OPTION_RECURSE_LIMIT
:
1840 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
1842 case OPTION_NO_RECURSE_LIMIT
:
1843 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
1852 /* Ignored for HP/UX compatibility. */
1855 set_output_format (optarg
);
1869 sort_numerically
= 1;
1874 sort_numerically
= 0;
1877 case OPTION_SIZE_SORT
:
1879 sort_numerically
= 0;
1883 set_output_format ("posix");
1886 set_output_format ("just-symbols");
1898 set_print_radix (optarg
);
1907 /* Ignored for (partial) AIX compatibility. On AIX, the
1908 argument has values 32, 64, or 32_64, and specifies that
1909 only 32-bit, only 64-bit, or both kinds of objects should
1910 be examined. The default is 32. So plain AIX nm on a
1911 library archive with both kinds of objects will ignore
1912 the 64-bit ones. For GNU nm, the default is and always
1913 has been -X 32_64, and other options are not supported. */
1914 if (strcmp (optarg
, "32_64") != 0)
1915 fatal (_("Only -X 32_64 is supported"));
1918 case OPTION_TARGET
: /* --target */
1922 case OPTION_PLUGIN
: /* --plugin */
1923 #if BFD_SUPPORTS_PLUGINS
1924 bfd_plugin_set_plugin (optarg
);
1926 fatal (_("sorry - this program has been built without plugin support\n"));
1930 case OPTION_IFUNC_CHARS
:
1931 ifunc_type_chars
= optarg
;
1934 case 0: /* A long option that just sets a flag. */
1943 print_version ("nm");
1945 if (sort_by_size
&& undefined_only
)
1947 non_fatal (_("Using the --size-sort and --undefined-only options together"));
1948 non_fatal (_("will produce no output, since undefined symbols have no size."));
1952 /* OK, all options now parsed. If no filename specified, do a.out. */
1954 return !display_file ("a.out");
1958 if (argc
- optind
> 1)
1959 filename_per_file
= 1;
1961 /* We were given several filenames to do. */
1962 while (optind
< argc
)
1965 if (!display_file (argv
[optind
++]))
1969 END_PROGRESS (program_name
);