/* nm.c -- Describe symbol table of a rel file.
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001
+ 2001, 2002
Free Software Foundation, Inc.
This file is part of GNU Binutils.
#include "aout/ranlib.h"
#include "demangle.h"
#include "libiberty.h"
+#include "elf-bfd.h"
/* When sorting by size, we use this structure to hold the size and a
pointer to the minisymbol. */
static void
-print_archive_member_bsd PARAMS ((char *archive, CONST char *filename));
+print_archive_member_bsd PARAMS ((char *archive, const char *filename));
static void
-print_archive_member_sysv PARAMS ((char *archive, CONST char *filename));
+print_archive_member_sysv PARAMS ((char *archive, const char *filename));
static void
-print_archive_member_posix PARAMS ((char *archive, CONST char *filename));
+print_archive_member_posix PARAMS ((char *archive, const char *filename));
static void
void (*print_archive_filename) PARAMS ((char *filename));
/* Print the name of an archive member file. */
- void (*print_archive_member) PARAMS ((char *archive, CONST char *filename));
+ void (*print_archive_member) PARAMS ((char *archive, const char *filename));
/* Print the name of the file (and archive, if there is one)
containing a symbol. */
FILE *stream;
int status;
{
- fprintf (stream, _("Usage: %s [OPTION]... [FILE]...\n"), program_name);
- fprintf (stream, _("List symbols from FILEs (a.out by default).\n"));
- fprintf (stream, _("\n\
+ fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name);
+ fprintf (stream, _(" List symbols in [file(s)] (a.out by default).\n"));
+ fprintf (stream, _(" The options are:\n\
-a, --debug-syms Display debugger-only symbols\n\
-A, --print-file-name Print name of the input file before every symbol\n\
-B Same as --format=bsd\n\
-f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',\n\
`sysv' or `posix'. The default is `bsd'\n\
-g, --extern-only Display only external symbols\n\
- -h, --help Display this information\n\
-l, --line-numbers Use debugging information to find a filename and\n\
line number for each symbol\n\
-n, --numeric-sort Sort symbols numerically by address\n\
-t, --radix=RADIX Use RADIX for printing symbol values\n\
--target=BFDNAME Specify the target object format as BFDNAME\n\
-u, --undefined-only Display only undefined symbols\n\
- -V, --version Display this program's version number\n\
-X 32_64 (ignored)\n\
+ -h, --help Display this information\n\
+ -V, --version Display this program's version number\n\
\n"));
list_supported_targets (program_name, stream);
if (status == 0)
format = &formats[i];
}
\f
+int main PARAMS ((int, char **));
+
int
main (argc, argv)
int argc;
bfd_init ();
set_default_bfd_target ();
- while ((c = getopt_long (argc, argv, "aABCDef:glnopPrst:uvVX:",
+ while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrst:uvVvX:",
long_options, (int *) 0)) != EOF)
{
switch (c)
if (optarg != NULL)
{
enum demangling_styles style;
-
+
style = cplus_demangle_name_to_style (optarg);
- if (style == unknown_demangling)
+ if (style == unknown_demangling)
fatal (_("unknown demangling style `%s'"),
optarg);
-
+
cplus_demangle_set_style (style);
- }
+ }
break;
case 'D':
dynamic = 1;
case 'g':
external_only = 1;
break;
+ case 'H':
case 'h':
usage (stdout, 0);
case 'l':
return sorters[0][reverse_sort] (x->minisym, y->minisym);
}
-/* Sort the symbols by size. We guess the size by assuming that the
- difference between the address of a symbol and the address of the
- next higher symbol is the size. FIXME: ELF actually stores a size
- with each symbol. We should use it. */
+/* Sort the symbols by size. ELF provides a size but for other formats
+ we have to make a guess by assuming that the difference between the
+ address of a symbol and the address of the next higher symbol is the
+ size. */
static long
sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
sec = bfd_get_section (sym);
- if (bfd_is_com_section (sec))
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ sz = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
+ else if (bfd_is_com_section (sec))
sz = sym->value;
else
{
asymbol *sym;
PROGRESS (1);
-
+
sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from, store);
if (sym == NULL)
bfd_fatal (bfd_get_filename (abfd));
/* Print the symbols when sorting by size. */
-static void
+static void
print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd)
bfd *abfd;
boolean dynamic;
bfd_asymbol_name (*r->sym_ptr_ptr)) == 0
&& bfd_find_nearest_line (abfd, secs[i], syms,
r->address, &filename,
- &functionname, &lineno))
+ &functionname, &lineno)
+ && filename != NULL)
{
/* We only print the first one we find. */
printf ("\t%s:%u", filename, lineno);
static void
print_archive_member_bsd (archive, filename)
char *archive ATTRIBUTE_UNUSED;
- CONST char *filename;
+ const char *filename;
{
if (!filename_per_symbol)
printf ("\n%s:\n", filename);
static void
print_archive_member_sysv (archive, filename)
char *archive;
- CONST char *filename;
+ const char *filename;
{
if (undefined_only)
printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename);
static void
print_archive_member_posix (archive, filename)
char *archive;
- CONST char *filename;
+ const char *filename;
{
if (!filename_per_symbol)
printf ("%s[%s]:\n", archive, filename);
static void
print_value (abfd, val)
- bfd *abfd;
+ bfd *abfd ATTRIBUTE_UNUSED;
bfd_vma val;
{
#if ! defined (BFD64) || BFD_HOST_64BIT_LONG