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 bfd_boolean 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 bfd_boolean 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
, bfd_boolean 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 bfd_boolean 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
);
637 /* Solaris 2.5 has a bug in strcoll.
638 strcoll returns invalid values when confronted with empty strings. */
644 return strcoll (xn
, yn
);
646 return strcmp (xn
, yn
);
651 non_numeric_reverse (const void *x
, const void *y
)
653 return - non_numeric_forward (x
, y
);
657 numeric_forward (const void *P_x
, const void *P_y
)
662 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
663 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
664 if (x
== NULL
|| y
== NULL
)
665 bfd_fatal (bfd_get_filename (sort_bfd
));
667 xs
= bfd_asymbol_section (x
);
668 ys
= bfd_asymbol_section (y
);
670 if (bfd_is_und_section (xs
))
672 if (! bfd_is_und_section (ys
))
675 else if (bfd_is_und_section (ys
))
677 else if (valueof (x
) != valueof (y
))
678 return valueof (x
) < valueof (y
) ? -1 : 1;
680 return non_numeric_forward (P_x
, P_y
);
684 numeric_reverse (const void *x
, const void *y
)
686 return - numeric_forward (x
, y
);
689 static int (*(sorters
[2][2])) (const void *, const void *) =
691 { non_numeric_forward
, non_numeric_reverse
},
692 { numeric_forward
, numeric_reverse
}
695 /* This sort routine is used by sort_symbols_by_size. It is similar
696 to numeric_forward, but when symbols have the same value it sorts
697 by section VMA. This simplifies the sort_symbols_by_size code
698 which handles symbols at the end of sections. Also, this routine
699 tries to sort file names before other symbols with the same value.
700 That will make the file name have a zero size, which will make
701 sort_symbols_by_size choose the non file name symbol, leading to
702 more meaningful output. For similar reasons, this code sorts
703 gnu_compiled_* and gcc2_compiled before other symbols with the same
707 size_forward1 (const void *P_x
, const void *P_y
)
715 x
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_x
, sort_x
);
716 y
= bfd_minisymbol_to_symbol (sort_bfd
, sort_dynamic
, P_y
, sort_y
);
717 if (x
== NULL
|| y
== NULL
)
718 bfd_fatal (bfd_get_filename (sort_bfd
));
720 xs
= bfd_asymbol_section (x
);
721 ys
= bfd_asymbol_section (y
);
723 if (bfd_is_und_section (xs
))
725 if (bfd_is_und_section (ys
))
728 if (valueof (x
) != valueof (y
))
729 return valueof (x
) < valueof (y
) ? -1 : 1;
731 if (xs
->vma
!= ys
->vma
)
732 return xs
->vma
< ys
->vma
? -1 : 1;
734 xn
= bfd_asymbol_name (x
);
735 yn
= bfd_asymbol_name (y
);
739 /* The symbols gnu_compiled and gcc2_compiled convey even less
740 information than the file name, so sort them out first. */
742 xf
= (strstr (xn
, "gnu_compiled") != NULL
743 || strstr (xn
, "gcc2_compiled") != NULL
);
744 yf
= (strstr (yn
, "gnu_compiled") != NULL
745 || strstr (yn
, "gcc2_compiled") != NULL
);
752 /* We use a heuristic for the file name. It may not work on non
753 Unix systems, but it doesn't really matter; the only difference
754 is precisely which symbol names get printed. */
756 #define file_symbol(s, sn, snl) \
757 (((s)->flags & BSF_FILE) != 0 \
759 && (sn)[(snl) - 2] == '.' \
760 && ((sn)[(snl) - 1] == 'o' \
761 || (sn)[(snl) - 1] == 'a')))
763 xf
= file_symbol (x
, xn
, xnl
);
764 yf
= file_symbol (y
, yn
, ynl
);
771 return non_numeric_forward (P_x
, P_y
);
774 /* This sort routine is used by sort_symbols_by_size. It is sorting
775 an array of size_sym structures into size order. */
778 size_forward2 (const void *P_x
, const void *P_y
)
780 const struct size_sym
*x
= (const struct size_sym
*) P_x
;
781 const struct size_sym
*y
= (const struct size_sym
*) P_y
;
783 if (x
->size
< y
->size
)
784 return reverse_sort
? 1 : -1;
785 else if (x
->size
> y
->size
)
786 return reverse_sort
? -1 : 1;
788 return sorters
[0][reverse_sort
] (x
->minisym
, y
->minisym
);
791 /* Sort the symbols by size. ELF provides a size but for other formats
792 we have to make a guess by assuming that the difference between the
793 address of a symbol and the address of the next higher symbol is the
797 sort_symbols_by_size (bfd
*abfd
, bfd_boolean is_dynamic
, void *minisyms
,
798 long symcount
, unsigned int size
,
799 struct size_sym
**symsizesp
)
801 struct size_sym
*symsizes
;
802 bfd_byte
*from
, *fromend
;
804 asymbol
*store_sym
, *store_next
;
806 qsort (minisyms
, symcount
, size
, size_forward1
);
808 /* We are going to return a special set of symbols and sizes to
810 symsizes
= (struct size_sym
*) xmalloc (symcount
* sizeof (struct size_sym
));
811 *symsizesp
= symsizes
;
813 /* Note that filter_symbols has already removed all absolute and
814 undefined symbols. Here we remove all symbols whose size winds
816 from
= (bfd_byte
*) minisyms
;
817 fromend
= from
+ symcount
* size
;
824 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, (const void *) from
,
827 bfd_fatal (bfd_get_filename (abfd
));
830 for (; from
< fromend
; from
+= size
)
837 if (from
+ size
< fromend
)
839 next
= bfd_minisymbol_to_symbol (abfd
,
841 (const void *) (from
+ size
),
844 bfd_fatal (bfd_get_filename (abfd
));
849 sec
= bfd_asymbol_section (sym
);
851 /* Synthetic symbols don't have a full type set of data available, thus
852 we can't rely on that information for the symbol size. Ditto for
853 bfd/section.c:global_syms like *ABS*. */
854 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0
855 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
856 sz
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
857 else if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) == 0
858 && bfd_is_com_section (sec
))
862 if (from
+ size
< fromend
863 && sec
== bfd_asymbol_section (next
))
864 sz
= valueof (next
) - valueof (sym
);
866 sz
= (bfd_section_vma (sec
)
867 + bfd_section_size (sec
)
873 symsizes
->minisym
= (const void *) from
;
881 store_sym
= store_next
;
885 symcount
= symsizes
- *symsizesp
;
887 /* We must now sort again by size. */
888 qsort ((void *) *symsizesp
, symcount
, sizeof (struct size_sym
), size_forward2
);
893 /* This function is used to get the relocs for a particular section.
894 It is called via bfd_map_over_sections. */
897 get_relocs (bfd
*abfd
, asection
*sec
, void *dataarg
)
899 struct get_relocs_info
*data
= (struct get_relocs_info
*) dataarg
;
903 if ((sec
->flags
& SEC_RELOC
) == 0)
905 *data
->relocs
= NULL
;
912 relsize
= bfd_get_reloc_upper_bound (abfd
, sec
);
914 bfd_fatal (bfd_get_filename (abfd
));
916 *data
->relocs
= (arelent
**) xmalloc (relsize
);
917 *data
->relcount
= bfd_canonicalize_reloc (abfd
, sec
, *data
->relocs
,
919 if (*data
->relcount
< 0)
920 bfd_fatal (bfd_get_filename (abfd
));
928 /* Print a single symbol. */
931 print_symbol (bfd
* abfd
,
937 struct extended_symbol_info info
;
941 format
->print_symbol_filename (archive_bfd
, abfd
);
943 bfd_get_symbol_info (abfd
, sym
, &syminfo
);
945 /* PR 22967 - Distinguish between local and global ifunc symbols. */
946 if (syminfo
.type
== 'i'
947 && sym
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
949 if (ifunc_type_chars
== NULL
|| ifunc_type_chars
[0] == 0)
950 ; /* Change nothing. */
951 else if (sym
->flags
& BSF_GLOBAL
)
952 syminfo
.type
= ifunc_type_chars
[0];
953 else if (ifunc_type_chars
[1] != 0)
954 syminfo
.type
= ifunc_type_chars
[1];
957 info
.sinfo
= &syminfo
;
959 /* Synthetic symbols do not have a full symbol type set of data available.
960 Nor do bfd/section.c:global_syms like *ABS*. */
961 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_SYNTHETIC
)) != 0)
964 info
.coffinfo
= NULL
;
968 info
.elfinfo
= elf_symbol_from (sym
);
969 info
.coffinfo
= coff_symbol_from (sym
);
972 format
->print_symbol_info (&info
, abfd
);
976 static asymbol
**syms
;
977 static long symcount
;
978 const char *filename
, *functionname
;
981 /* We need to get the canonical symbols in order to call
982 bfd_find_nearest_line. This is inefficient, but, then, you
983 don't have to use --line-numbers. */
984 if (abfd
!= lineno_cache_bfd
&& syms
!= NULL
)
993 symsize
= bfd_get_symtab_upper_bound (abfd
);
995 bfd_fatal (bfd_get_filename (abfd
));
996 syms
= (asymbol
**) xmalloc (symsize
);
997 symcount
= bfd_canonicalize_symtab (abfd
, syms
);
999 bfd_fatal (bfd_get_filename (abfd
));
1000 lineno_cache_bfd
= abfd
;
1003 if (bfd_is_und_section (bfd_asymbol_section (sym
)))
1005 static asection
**secs
;
1006 static arelent
***relocs
;
1007 static long *relcount
;
1008 static unsigned int seccount
;
1010 const char *symname
;
1012 /* For an undefined symbol, we try to find a reloc for the
1013 symbol, and print the line number of the reloc. */
1014 if (abfd
!= lineno_cache_rel_bfd
&& relocs
!= NULL
)
1016 for (i
= 0; i
< seccount
; i
++)
1017 if (relocs
[i
] != NULL
)
1029 struct get_relocs_info rinfo
;
1031 seccount
= bfd_count_sections (abfd
);
1033 secs
= (asection
**) xmalloc (seccount
* sizeof *secs
);
1034 relocs
= (arelent
***) xmalloc (seccount
* sizeof *relocs
);
1035 relcount
= (long *) xmalloc (seccount
* sizeof *relcount
);
1038 rinfo
.relocs
= relocs
;
1039 rinfo
.relcount
= relcount
;
1041 bfd_map_over_sections (abfd
, get_relocs
, (void *) &rinfo
);
1042 lineno_cache_rel_bfd
= abfd
;
1045 symname
= bfd_asymbol_name (sym
);
1046 for (i
= 0; i
< seccount
; i
++)
1050 for (j
= 0; j
< relcount
[i
]; j
++)
1055 if (r
->sym_ptr_ptr
!= NULL
1056 && (*r
->sym_ptr_ptr
)->section
== sym
->section
1057 && (*r
->sym_ptr_ptr
)->value
== sym
->value
1059 bfd_asymbol_name (*r
->sym_ptr_ptr
)) == 0
1060 && bfd_find_nearest_line (abfd
, secs
[i
], syms
,
1061 r
->address
, &filename
,
1062 &functionname
, &lineno
)
1063 && filename
!= NULL
)
1065 /* We only print the first one we find. */
1066 printf ("\t%s:%u", filename
, lineno
);
1073 else if (bfd_asymbol_section (sym
)->owner
== abfd
)
1075 if ((bfd_find_line (abfd
, syms
, sym
, &filename
, &lineno
)
1076 || bfd_find_nearest_line (abfd
, bfd_asymbol_section (sym
),
1077 syms
, sym
->value
, &filename
,
1078 &functionname
, &lineno
))
1081 printf ("\t%s:%u", filename
, lineno
);
1088 /* Print the symbols when sorting by size. */
1091 print_size_symbols (bfd
* abfd
,
1092 bfd_boolean is_dynamic
,
1093 struct size_sym
* symsizes
,
1098 struct size_sym
*from
;
1099 struct size_sym
*fromend
;
1101 store
= bfd_make_empty_symbol (abfd
);
1103 bfd_fatal (bfd_get_filename (abfd
));
1106 fromend
= from
+ symcount
;
1108 for (; from
< fromend
; from
++)
1112 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, from
->minisym
, store
);
1114 bfd_fatal (bfd_get_filename (abfd
));
1116 print_symbol (abfd
, sym
, from
->size
, archive_bfd
);
1121 /* Print the symbols of ABFD that are held in MINISYMS.
1123 If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD.
1125 SYMCOUNT is the number of symbols in MINISYMS.
1127 SIZE is the size of a symbol in MINISYMS. */
1130 print_symbols (bfd
* abfd
,
1131 bfd_boolean is_dynamic
,
1141 store
= bfd_make_empty_symbol (abfd
);
1143 bfd_fatal (bfd_get_filename (abfd
));
1145 from
= (bfd_byte
*) minisyms
;
1146 fromend
= from
+ symcount
* size
;
1148 for (; from
< fromend
; from
+= size
)
1152 sym
= bfd_minisymbol_to_symbol (abfd
, is_dynamic
, from
, store
);
1154 bfd_fatal (bfd_get_filename (abfd
));
1156 print_symbol (abfd
, sym
, (bfd_vma
) 0, archive_bfd
);
1160 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */
1163 display_rel_file (bfd
*abfd
, bfd
*archive_bfd
)
1168 struct size_sym
*symsizes
;
1169 asymbol
*synthsyms
= NULL
;
1173 if (!(bfd_get_file_flags (abfd
) & HAS_SYMS
))
1176 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
1181 symcount
= bfd_read_minisymbols (abfd
, dynamic
, &minisyms
, &size
);
1184 if (dynamic
&& bfd_get_error () == bfd_error_no_symbols
)
1187 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
1191 bfd_fatal (bfd_get_filename (abfd
));
1197 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd
));
1201 if (show_synthetic
&& size
== sizeof (asymbol
*))
1203 asymbol
**static_syms
= NULL
;
1204 asymbol
**dyn_syms
= NULL
;
1205 long static_count
= 0;
1211 dyn_count
= symcount
;
1212 dyn_syms
= (asymbol
**) minisyms
;
1216 long storage
= bfd_get_dynamic_symtab_upper_bound (abfd
);
1218 static_count
= symcount
;
1219 static_syms
= (asymbol
**) minisyms
;
1223 dyn_syms
= (asymbol
**) xmalloc (storage
);
1224 dyn_count
= bfd_canonicalize_dynamic_symtab (abfd
, dyn_syms
);
1226 bfd_fatal (bfd_get_filename (abfd
));
1230 synth_count
= bfd_get_synthetic_symtab (abfd
, static_count
, static_syms
,
1231 dyn_count
, dyn_syms
, &synthsyms
);
1232 if (synth_count
> 0)
1237 minisyms
= xrealloc (minisyms
,
1238 (symcount
+ synth_count
+ 1) * sizeof (*symp
));
1239 symp
= (asymbol
**) minisyms
+ symcount
;
1240 for (i
= 0; i
< synth_count
; i
++)
1241 *symp
++ = synthsyms
+ i
;
1243 symcount
+= synth_count
;
1245 if (!dynamic
&& dyn_syms
!= NULL
)
1249 /* lto_slim_object is set to false when a bfd is loaded with a compiler
1251 if (abfd
->lto_slim_object
)
1253 report_plugin_err
= FALSE
;
1254 non_fatal (_("%s: plugin needed to handle lto object"),
1255 bfd_get_filename (abfd
));
1258 /* Discard the symbols we don't want to print.
1259 It's OK to do this in place; we'll free the storage anyway
1260 (after printing). */
1262 symcount
= filter_symbols (abfd
, dynamic
, minisyms
, symcount
, size
);
1268 sort_dynamic
= dynamic
;
1269 sort_x
= bfd_make_empty_symbol (abfd
);
1270 sort_y
= bfd_make_empty_symbol (abfd
);
1271 if (sort_x
== NULL
|| sort_y
== NULL
)
1272 bfd_fatal (bfd_get_filename (abfd
));
1275 qsort (minisyms
, symcount
, size
,
1276 sorters
[sort_numerically
][reverse_sort
]);
1278 symcount
= sort_symbols_by_size (abfd
, dynamic
, minisyms
, symcount
,
1283 print_symbols (abfd
, dynamic
, minisyms
, symcount
, size
, archive_bfd
);
1285 print_size_symbols (abfd
, dynamic
, symsizes
, symcount
, archive_bfd
);
1293 /* Construct a formatting string for printing symbol values. */
1296 get_print_format (void)
1298 const char * padding
;
1299 if (print_format
== FORMAT_POSIX
|| print_format
== FORMAT_JUST_SYMBOLS
)
1301 /* POSIX compatible output does not have any padding. */
1304 else if (print_width
== 32)
1308 else /* print_width == 64 */
1313 const char * length
= "l";
1314 if (print_width
== 64)
1316 #if BFD_HOST_64BIT_LONG
1318 #elif BFD_HOST_64BIT_LONG_LONG
1327 const char * radix
= NULL
;
1328 switch (print_radix
)
1330 case 8: radix
= "o"; break;
1331 case 10: radix
= "d"; break;
1332 case 16: radix
= "x"; break;
1335 return concat ("%", padding
, length
, radix
, NULL
);
1339 set_print_width (bfd
*file
)
1341 print_width
= bfd_get_arch_size (file
);
1343 if (print_width
== -1)
1346 Guess the target's bitsize based on its name.
1347 We assume here than any 64-bit format will include
1348 "64" somewhere in its name. The only known exception
1349 is the MMO object file format. */
1350 if (strstr (bfd_get_target (file
), "64") != NULL
1351 || strcmp (bfd_get_target (file
), "mmo") == 0)
1356 free ((char *) print_format_string
);
1357 print_format_string
= get_print_format ();
1361 display_archive (bfd
*file
)
1364 bfd
*last_arfile
= NULL
;
1367 format
->print_archive_filename (bfd_get_filename (file
));
1370 print_symdef_entry (file
);
1376 arfile
= bfd_openr_next_archived_file (file
, arfile
);
1380 if (bfd_get_error () != bfd_error_no_more_archived_files
)
1381 bfd_fatal (bfd_get_filename (file
));
1385 if (bfd_check_format_matches (arfile
, bfd_object
, &matching
))
1387 set_print_width (arfile
);
1388 format
->print_archive_member (bfd_get_filename (file
),
1389 bfd_get_filename (arfile
));
1390 display_rel_file (arfile
, file
);
1394 bfd_nonfatal (bfd_get_filename (arfile
));
1395 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
1397 list_matching_formats (matching
);
1402 if (last_arfile
!= NULL
)
1404 bfd_close (last_arfile
);
1405 lineno_cache_bfd
= NULL
;
1406 lineno_cache_rel_bfd
= NULL
;
1407 if (arfile
== last_arfile
)
1410 last_arfile
= arfile
;
1413 if (last_arfile
!= NULL
)
1415 bfd_close (last_arfile
);
1416 lineno_cache_bfd
= NULL
;
1417 lineno_cache_rel_bfd
= NULL
;
1422 display_file (char *filename
)
1424 bfd_boolean retval
= TRUE
;
1428 if (get_file_size (filename
) < 1)
1431 file
= bfd_openr (filename
, target
? target
: plugin_target
);
1434 bfd_nonfatal (filename
);
1438 /* If printing line numbers, decompress the debug sections. */
1440 file
->flags
|= BFD_DECOMPRESS
;
1442 if (bfd_check_format (file
, bfd_archive
))
1444 display_archive (file
);
1446 else if (bfd_check_format_matches (file
, bfd_object
, &matching
))
1448 set_print_width (file
);
1449 format
->print_object_filename (filename
);
1450 display_rel_file (file
, NULL
);
1454 bfd_nonfatal (filename
);
1455 if (bfd_get_error () == bfd_error_file_ambiguously_recognized
)
1457 list_matching_formats (matching
);
1463 if (!bfd_close (file
))
1464 bfd_fatal (filename
);
1466 lineno_cache_bfd
= NULL
;
1467 lineno_cache_rel_bfd
= NULL
;
1472 /* The following 3 groups of functions are called unconditionally,
1473 once at the start of processing each file of the appropriate type.
1474 They should check `filename_per_file' and `filename_per_symbol',
1475 as appropriate for their output format, to determine whether to
1478 /* Print the name of an object file given on the command line. */
1481 print_object_filename_bsd (const char *filename
)
1483 if (filename_per_file
&& !filename_per_symbol
)
1484 printf ("\n%s:\n", filename
);
1488 print_object_filename_sysv (const char *filename
)
1491 printf (_("\n\nUndefined symbols from %s:\n\n"), filename
);
1493 printf (_("\n\nSymbols from %s:\n\n"), filename
);
1494 if (print_width
== 32)
1496 Name Value Class Type Size Line Section\n\n"));
1499 Name Value Class Type Size Line Section\n\n"));
1503 print_object_filename_posix (const char *filename
)
1505 if (filename_per_file
&& !filename_per_symbol
)
1506 printf ("%s:\n", filename
);
1510 do_not_print_object_filename (const char *filename ATTRIBUTE_UNUSED
)
1514 /* Print the name of an archive file given on the command line. */
1517 print_archive_filename_bsd (const char *filename
)
1519 if (filename_per_file
)
1520 printf ("\n%s:\n", filename
);
1524 print_archive_filename_sysv (const char *filename ATTRIBUTE_UNUSED
)
1529 print_archive_filename_posix (const char *filename ATTRIBUTE_UNUSED
)
1534 do_not_print_archive_filename (const char *filename ATTRIBUTE_UNUSED
)
1538 /* Print the name of an archive member file. */
1541 print_archive_member_bsd (const char *archive ATTRIBUTE_UNUSED
,
1542 const char *filename
)
1544 if (!filename_per_symbol
)
1545 printf ("\n%s:\n", filename
);
1549 print_archive_member_sysv (const char *archive
, const char *filename
)
1552 printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive
, filename
);
1554 printf (_("\n\nSymbols from %s[%s]:\n\n"), archive
, filename
);
1555 if (print_width
== 32)
1557 Name Value Class Type Size Line Section\n\n"));
1560 Name Value Class Type Size Line Section\n\n"));
1564 print_archive_member_posix (const char *archive
, const char *filename
)
1566 if (!filename_per_symbol
)
1567 printf ("%s[%s]:\n", archive
, filename
);
1571 do_not_print_archive_member (const char *archive ATTRIBUTE_UNUSED
,
1572 const char *filename ATTRIBUTE_UNUSED
)
1577 /* Print the name of the file (and archive, if there is one)
1578 containing a symbol. */
1581 print_symbol_filename_bsd (bfd
*archive_bfd
, bfd
*abfd
)
1583 if (filename_per_symbol
)
1586 printf ("%s:", bfd_get_filename (archive_bfd
));
1587 printf ("%s:", bfd_get_filename (abfd
));
1592 print_symbol_filename_sysv (bfd
*archive_bfd
, bfd
*abfd
)
1594 if (filename_per_symbol
)
1597 printf ("%s:", bfd_get_filename (archive_bfd
));
1598 printf ("%s:", bfd_get_filename (abfd
));
1603 print_symbol_filename_posix (bfd
*archive_bfd
, bfd
*abfd
)
1605 if (filename_per_symbol
)
1608 printf ("%s[%s]: ", bfd_get_filename (archive_bfd
),
1609 bfd_get_filename (abfd
));
1611 printf ("%s: ", bfd_get_filename (abfd
));
1616 do_not_print_symbol_filename (bfd
*archive_bfd ATTRIBUTE_UNUSED
,
1617 bfd
*abfd ATTRIBUTE_UNUSED
)
1622 /* Print a symbol value. */
1625 print_value (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma val
)
1627 switch (print_width
)
1630 printf (print_format_string
, (unsigned long) val
);
1634 #if BFD_HOST_64BIT_LONG || BFD_HOST_64BIT_LONG_LONG
1635 printf (print_format_string
, val
);
1637 /* We have a 64 bit value to print, but the host is only 32 bit. */
1638 if (print_radix
== 16)
1639 bfd_fprintf_vma (abfd
, stdout
, val
);
1645 s
= buf
+ sizeof buf
;
1649 *--s
= (val
% print_radix
) + '0';
1652 while ((buf
+ sizeof buf
- 1) - s
< 16)
1660 fatal (_("Print width has not been initialized (%d)"), print_width
);
1665 /* Print a line of information about a symbol. */
1668 print_symbol_info_bsd (struct extended_symbol_info
*info
, bfd
*abfd
)
1670 if (bfd_is_undefined_symclass (SYM_TYPE (info
)))
1672 if (print_width
== 64)
1678 /* Normally we print the value of the symbol. If we are printing the
1679 size or sorting by size then we print its size, except for the
1680 (weird) special case where both flags are defined, in which case we
1681 print both values. This conforms to documented behaviour. */
1682 if (sort_by_size
&& !print_size
)
1683 print_value (abfd
, SYM_SIZE (info
));
1685 print_value (abfd
, SYM_VALUE (info
));
1686 if (print_size
&& SYM_SIZE (info
))
1689 print_value (abfd
, SYM_SIZE (info
));
1693 printf (" %c", SYM_TYPE (info
));
1695 if (SYM_TYPE (info
) == '-')
1699 printf (other_format
, SYM_STAB_OTHER (info
));
1701 printf (desc_format
, SYM_STAB_DESC (info
));
1702 printf (" %5s", SYM_STAB_NAME (info
));
1704 print_symname (" %s", info
, NULL
, abfd
);
1708 print_symbol_info_sysv (struct extended_symbol_info
*info
, bfd
*abfd
)
1710 print_symname ("%-20s|", info
, NULL
, abfd
);
1712 if (bfd_is_undefined_symclass (SYM_TYPE (info
)))
1714 if (print_width
== 32)
1720 print_value (abfd
, SYM_VALUE (info
));
1722 printf ("| %c |", SYM_TYPE (info
));
1724 if (SYM_TYPE (info
) == '-')
1727 printf ("%18s| ", SYM_STAB_NAME (info
)); /* (C) Type. */
1728 printf (desc_format
, SYM_STAB_DESC (info
)); /* Size. */
1729 printf ("| |"); /* Line, Section. */
1733 /* Type, Size, Line, Section */
1736 get_elf_symbol_type (ELF_ST_TYPE (info
->elfinfo
->internal_elf_sym
.st_info
)));
1737 else if (info
->coffinfo
)
1739 get_coff_symbol_type (&info
->coffinfo
->native
->u
.syment
));
1743 if (SYM_SIZE (info
))
1744 print_value (abfd
, SYM_SIZE (info
));
1747 if (print_width
== 32)
1754 printf("| |%s", info
->elfinfo
->symbol
.section
->name
);
1755 else if (info
->coffinfo
)
1756 printf("| |%s", info
->coffinfo
->symbol
.section
->name
);
1763 print_symbol_info_posix (struct extended_symbol_info
*info
, bfd
*abfd
)
1765 print_symname ("%s ", info
, NULL
, abfd
);
1766 printf ("%c ", SYM_TYPE (info
));
1768 if (bfd_is_undefined_symclass (SYM_TYPE (info
)))
1772 print_value (abfd
, SYM_VALUE (info
));
1774 if (SYM_SIZE (info
))
1775 print_value (abfd
, SYM_SIZE (info
));
1780 just_print_symbol_name (struct extended_symbol_info
*info
, bfd
*abfd
)
1782 print_symname ("%s", info
, NULL
, abfd
);
1786 main (int argc
, char **argv
)
1791 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
1792 setlocale (LC_MESSAGES
, "");
1794 #if defined (HAVE_SETLOCALE)
1795 setlocale (LC_CTYPE
, "");
1796 setlocale (LC_COLLATE
, "");
1798 bindtextdomain (PACKAGE
, LOCALEDIR
);
1799 textdomain (PACKAGE
);
1801 program_name
= *argv
;
1802 xmalloc_set_program_name (program_name
);
1803 bfd_set_error_program_name (program_name
);
1804 #if BFD_SUPPORTS_PLUGINS
1805 bfd_plugin_set_program_name (program_name
);
1808 START_PROGRESS (program_name
, 0);
1810 expandargv (&argc
, &argv
);
1812 if (bfd_init () != BFD_INIT_MAGIC
)
1813 fatal (_("fatal error: libbfd ABI mismatch"));
1814 set_default_bfd_target ();
1816 while ((c
= getopt_long (argc
, argv
, "aABCDef:gHhjJlnopPrSst:uvVvX:",
1817 long_options
, (int *) 0)) != EOF
)
1822 print_debug_syms
= 1;
1826 filename_per_symbol
= 1;
1828 case 'B': /* For MIPS compatibility. */
1829 set_output_format ("bsd");
1835 enum demangling_styles style
;
1837 style
= cplus_demangle_name_to_style (optarg
);
1838 if (style
== unknown_demangling
)
1839 fatal (_("unknown demangling style `%s'"),
1842 cplus_demangle_set_style (style
);
1845 case OPTION_RECURSE_LIMIT
:
1846 demangle_flags
&= ~ DMGL_NO_RECURSE_LIMIT
;
1848 case OPTION_NO_RECURSE_LIMIT
:
1849 demangle_flags
|= DMGL_NO_RECURSE_LIMIT
;
1858 /* Ignored for HP/UX compatibility. */
1861 set_output_format (optarg
);
1875 sort_numerically
= 1;
1880 sort_numerically
= 0;
1883 case OPTION_SIZE_SORT
:
1885 sort_numerically
= 0;
1889 set_output_format ("posix");
1892 set_output_format ("just-symbols");
1904 set_print_radix (optarg
);
1913 /* Ignored for (partial) AIX compatibility. On AIX, the
1914 argument has values 32, 64, or 32_64, and specifies that
1915 only 32-bit, only 64-bit, or both kinds of objects should
1916 be examined. The default is 32. So plain AIX nm on a
1917 library archive with both kinds of objects will ignore
1918 the 64-bit ones. For GNU nm, the default is and always
1919 has been -X 32_64, and other options are not supported. */
1920 if (strcmp (optarg
, "32_64") != 0)
1921 fatal (_("Only -X 32_64 is supported"));
1924 case OPTION_TARGET
: /* --target */
1928 case OPTION_PLUGIN
: /* --plugin */
1929 #if BFD_SUPPORTS_PLUGINS
1930 bfd_plugin_set_plugin (optarg
);
1932 fatal (_("sorry - this program has been built without plugin support\n"));
1936 case OPTION_IFUNC_CHARS
:
1937 ifunc_type_chars
= optarg
;
1940 case 0: /* A long option that just sets a flag. */
1949 print_version ("nm");
1951 if (sort_by_size
&& undefined_only
)
1953 non_fatal (_("Using the --size-sort and --undefined-only options together"));
1954 non_fatal (_("will produce no output, since undefined symbols have no size."));
1958 /* OK, all options now parsed. If no filename specified, do a.out. */
1960 return !display_file ("a.out");
1964 if (argc
- optind
> 1)
1965 filename_per_file
= 1;
1967 /* We were given several filenames to do. */
1968 while (optind
< argc
)
1971 if (!display_file (argv
[optind
++]))
1975 END_PROGRESS (program_name
);