Added -D (--dynamic) option to nm and -T (--dynamic-syms) and -R

(--dynamic-reloc) arguments to objdump.
	* nm.c (dynamic): New static variable.
	(long_options): Added "dynamic".
	(usage): Mention -D and --dynamic.
	(main): Add D to getopt string.  Handle -D by setting dynamic.
	(display_rel_file): If dynamic is non-zero, read dynamic symbols
	rather than normal symbols.
	* nm.1: Updated for -D (--dynamic) option.
	* objdump.c (dump_dynamic_symtab): New global variable.
	(dump_dynamic_reloc_info): New global variable.
	(dynsyms, dynsymcount): New global variables.
	(usage): Mention -R, -T, --dynamic-syms and --dynamic-reloc.
	(long_options): Added "dynamic-reloc" and "dynamic-syms".
	(slurp_symtab): If no symbols, return rather than exit.
	(slurp_dynamic_symtab): New function.
	(display_bfd): Handle dump_dynamic_symtab and
	dump_dynamic_reloc_info.
	(dump_symbols): Take new dynamic argument, indicating whether to
	display dynamic symbols.
	(dump_relocs): Move most printing into dump_reloc_set.
	(dump_dynamic_relocs): New function.
	(dump_reloc_set): New function, extracted from dump_relocs.
	(main): Add R and T to getopt string.  Handle -T by setting
	dump_dynamic_symtab and -R by setting dump_dynamic_reloc_info.
	* objdump.1: Updated for -R (--dynamic-reloc) and -T
	(--dynamic-syms) options.
	* binutils.texi: Updated for new nm and objdump options.
This commit is contained in:
Ian Lance Taylor 1994-04-07 02:04:34 +00:00
parent dfc1c00613
commit de3b08ac2e
5 changed files with 278 additions and 72 deletions

View File

@ -1,3 +1,34 @@
Wed Apr 6 21:54:49 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
Added -D (--dynamic) option to nm and -T (--dynamic-syms) and -R
(--dynamic-reloc) arguments to objdump.
* nm.c (dynamic): New static variable.
(long_options): Added "dynamic".
(usage): Mention -D and --dynamic.
(main): Add D to getopt string. Handle -D by setting dynamic.
(display_rel_file): If dynamic is non-zero, read dynamic symbols
rather than normal symbols.
* nm.1: Updated for -D (--dynamic) option.
* objdump.c (dump_dynamic_symtab): New global variable.
(dump_dynamic_reloc_info): New global variable.
(dynsyms, dynsymcount): New global variables.
(usage): Mention -R, -T, --dynamic-syms and --dynamic-reloc.
(long_options): Added "dynamic-reloc" and "dynamic-syms".
(slurp_symtab): If no symbols, return rather than exit.
(slurp_dynamic_symtab): New function.
(display_bfd): Handle dump_dynamic_symtab and
dump_dynamic_reloc_info.
(dump_symbols): Take new dynamic argument, indicating whether to
display dynamic symbols.
(dump_relocs): Move most printing into dump_reloc_set.
(dump_dynamic_relocs): New function.
(dump_reloc_set): New function, extracted from dump_relocs.
(main): Add R and T to getopt string. Handle -T by setting
dump_dynamic_symtab and -R by setting dump_dynamic_reloc_info.
* objdump.1: Updated for -R (--dynamic-reloc) and -T
(--dynamic-syms) options.
* binutils.texi: Updated for new nm and objdump options.
Wed Mar 30 15:52:40 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com) Wed Mar 30 15:52:40 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
Update for recent BFD changes to symbol and reloc reading. Rename Update for recent BFD changes to symbol and reloc reading. Rename

View File

@ -566,7 +566,7 @@ The GNU linker @code{ld} is now described in a separate manual.
@smallexample @smallexample
nm [ -a | --debug-syms ] [ -g | --extern-only ] nm [ -a | --debug-syms ] [ -g | --extern-only ]
[ -B ] [ -C | --demangle ] [ -B ] [ -C | --demangle ] [ -D | --dynamic ]
[ -s | --print-armap ] [ -A | -o | --print-file-name ] [ -s | --print-armap ] [ -A | -o | --print-file-name ]
[ -n | -v | --numeric-sort ] [ -p | --no-sort ] [ -n | -v | --numeric-sort ] [ -p | --no-sort ]
[ -r | --reverse-sort ] [ -u | --undefined-only ] [ -r | --reverse-sort ] [ -u | --undefined-only ]
@ -653,6 +653,13 @@ Besides removing any initial underscore prepended by the system, this
makes C++ function names readable. @xref{c++filt}, for more information makes C++ function names readable. @xref{c++filt}, for more information
on demangling. on demangling.
@item -D
@itemx --dynamic
@cindex dynamic symbols
Display the dynamic symbols rather than the normal symbols. This is
only meaningful for dynamic objects, such as certain types of shared
libraries.
@item -f @var{format} @item -f @var{format}
@itemx --format=@var{format} @itemx --format=@var{format}
@cindex @code{nm} format @cindex @code{nm} format
@ -832,9 +839,9 @@ objdump [ -a | --archive-headers ]
[ -j @var{section} | --section=@var{section} ] [ -j @var{section} | --section=@var{section} ]
[ -l | --line-numbers ] [ -l | --line-numbers ]
[ -m @var{machine} | --architecture=@var{machine} ] [ -r | --reloc ] [ -m @var{machine} | --architecture=@var{machine} ] [ -r | --reloc ]
[ -s | --full-contents ] [ --stabs ] [ -t | --syms ] [ -R | --dynamic-reloc ] [ -s | --full-contents ] [ --stabs ]
[ -x | --all-headers ] [ --version ] [ --help ] [ -t | --syms ] [ -T | --dynamic-syms ] [ -x | --all-headers ]
@var{objfile}@dots{} [ --version ] [ --help ] @var{objfile}@dots{}
@end smallexample @end smallexample
@code{objdump} displays information about one or more object files. @code{objdump} displays information about one or more object files.
@ -940,6 +947,13 @@ option.
@cindex relocation entries, in object file @cindex relocation entries, in object file
Print the relocation entries of the file. Print the relocation entries of the file.
@item -R
@itemx --dynamic-reloc
@cindex dynamic relocation entries, in object file
Print the dynamic relocation entries of the file. This is only
meaningful for dynamic objects, such as certain types of shared
libraries.
@item -s @item -s
@itemx --full-contents @itemx --full-contents
@cindex sections, full contents @cindex sections, full contents
@ -965,6 +979,14 @@ output.
Print the symbol table entries of the file. Print the symbol table entries of the file.
This is similar to the information provided by the @samp{nm} program. This is similar to the information provided by the @samp{nm} program.
@item -T
@itemx --dynamic-syms
@cindex dynamic symbol table entries, printing
Print the dynamic symbol table entries of the file. This is only
meaningful for dynamic objects, such as certain types of shared
libraries. This is similar to the information provided by the @samp{nm}
program when given the @samp{-D} (@samp{--dynamic}) option.
@item --version @item --version
Print the version number of @code{objdump} and exit. Print the version number of @code{objdump} and exit.

View File

@ -19,6 +19,7 @@ nm \- list symbols from object files.
.RB "[\|" \-g | \-\-extern\-only "\|]" .RB "[\|" \-g | \-\-extern\-only "\|]"
.RB "[\|" \-B "\|]" .RB "[\|" \-B "\|]"
.RB "[\|" \-C | \-\-demangle "\|]" .RB "[\|" \-C | \-\-demangle "\|]"
.RB "[\|" \-D | \-\-dynamic "\|]"
.RB "[\|" \-s | \-\-print\-armap "\|]" .RB "[\|" \-s | \-\-print\-armap "\|]"
.RB "[\|" \-o | \-\-print\-file\-name "\|]" .RB "[\|" \-o | \-\-print\-file\-name "\|]"
.RB "[\|" \-n | \-\-numeric\-sort "\|]" .RB "[\|" \-n | \-\-numeric\-sort "\|]"
@ -81,6 +82,14 @@ Decode (\fIdemangle\fP) low-level symbol names into user-level names.
Besides removing any initial underscore prepended by the system, this Besides removing any initial underscore prepended by the system, this
makes C++ function names readable. makes C++ function names readable.
.TP
.B \-D
.TP
.B \-\-dynamic
Display the dynamic symbols rather than the normal symbols. This is
only meaningful for dynamic objects, such as certain types of shared
libraries.
.TP .TP
.B "\-f \fIformat" .B "\-f \fIformat"
Use the output format \fIformat\fP, which can be ``bsd'', Use the output format \fIformat\fP, which can be ``bsd'',

View File

@ -38,9 +38,11 @@ objdump \- display information from object files.
.I machine\c .I machine\c
\&\|] \&\|]
.RB "[\|" \-r | \-\-reloc "\|]" .RB "[\|" \-r | \-\-reloc "\|]"
.RB "[\|" \-R | \-\-dynamic\-reloc "\|]"
.RB "[\|" \-s | \-\-full\-contents "\|]" .RB "[\|" \-s | \-\-full\-contents "\|]"
.RB "[\|" \-\-stabs "\|]" .RB "[\|" \-\-stabs "\|]"
.RB "[\|" \-t | \-\-syms "\|]" .RB "[\|" \-t | \-\-syms "\|]"
.RB "[\|" \-T | \-\-dynamic\-syms "\|]"
.RB "[\|" \-x | \-\-all\-headers "\|]" .RB "[\|" \-x | \-\-all\-headers "\|]"
.RB "[\|" \-\-version "\|]" .RB "[\|" \-\-version "\|]"
.RB "[\|" \-\-help "\|]" .RB "[\|" \-\-help "\|]"
@ -199,6 +201,14 @@ option.
.B \-\-reloc .B \-\-reloc
Print the relocation entries of the file. Print the relocation entries of the file.
.TP
.B \-R
.TP
.B \-\-dynamic\-reloc
Print the dynamic relocation entries of the file. This is only
meaningful for dynamic objects, such as certain types of shared
libraries.
.TP .TP
.B \-s .B \-s
.TP .TP
@ -223,6 +233,19 @@ This is similar to the information provided by the `\|\c
.B nm\c .B nm\c
\|' program. \|' program.
.TP
.B \-T
.TP
.B \-\-dynamic\-syms
Dynamic Symbol Table. Print the dynamic symbol table entries of the
file. This is only meaningful for dynamic objects, such as certain
types of shared libraries. This is similar to the information
provided by the `\|\c
.B nm\c
\|' program when given the
.B \-D (\-\-dynamic)
option.
.TP .TP
.B \-\-version .B \-\-version
Print the version number of Print the version number of

View File

@ -44,7 +44,9 @@ int dump_section_contents; /* -s */
int dump_section_headers; /* -h */ int dump_section_headers; /* -h */
boolean dump_file_header; /* -f */ boolean dump_file_header; /* -f */
int dump_symtab; /* -t */ int dump_symtab; /* -t */
int dump_dynamic_symtab; /* -T */
int dump_reloc_info; /* -r */ int dump_reloc_info; /* -r */
int dump_dynamic_reloc_info; /* -R */
int dump_ar_hdrs; /* -a */ int dump_ar_hdrs; /* -a */
int with_line_numbers; /* -l */ int with_line_numbers; /* -l */
int dump_stab_section_info; /* --stabs */ int dump_stab_section_info; /* --stabs */
@ -67,6 +69,12 @@ asymbol **syms;
/* Number of symbols in `syms'. */ /* Number of symbols in `syms'. */
long symcount = 0; long symcount = 0;
/* The dynamic symbol table. */
asymbol **dynsyms;
/* Number of symbols in `dynsyms'. */
long dynsymcount = 0;
/* Forward declarations. */ /* Forward declarations. */
static void static void
@ -79,7 +87,13 @@ static void
dump_relocs PARAMS ((bfd *abfd)); dump_relocs PARAMS ((bfd *abfd));
static void static void
dump_symbols PARAMS ((bfd *abfd)); dump_dynamic_relocs PARAMS ((bfd * abfd));
static void
dump_reloc_set PARAMS ((bfd *, arelent **, long));
static void
dump_symbols PARAMS ((bfd *abfd, boolean dynamic));
static void static void
display_bfd PARAMS ((bfd *abfd)); display_bfd PARAMS ((bfd *abfd));
@ -93,11 +107,12 @@ usage (stream, status)
int status; int status;
{ {
fprintf (stream, "\ fprintf (stream, "\
Usage: %s [-ahifdrtxsl] [-b bfdname] [-m machine] [-j section-name]\n\ Usage: %s [-ahifdrRtTxsl] [-b bfdname] [-m machine] [-j section-name]\n\
[--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\ [--archive-headers] [--target=bfdname] [--disassemble] [--file-headers]\n\
[--section-headers] [--headers] [--info] [--section=section-name]\n\ [--section-headers] [--headers] [--info] [--section=section-name]\n\
[--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\ [--line-numbers] [--architecture=machine] [--reloc] [--full-contents]\n\
[--stabs] [--syms] [--all-headers] [--version] [--help] objfile...\n\ [--stabs] [--syms] [--all-headers] [--dynamic-syms] [--dynamic-reloc]\n\
[--version] [--help] objfile...\n\
at least one option besides -l (--line-numbers) must be given\n", at least one option besides -l (--line-numbers) must be given\n",
program_name); program_name);
exit (status); exit (status);
@ -109,6 +124,8 @@ static struct option long_options[]=
{"architecture", required_argument, NULL, 'm'}, {"architecture", required_argument, NULL, 'm'},
{"archive-headers", no_argument, NULL, 'a'}, {"archive-headers", no_argument, NULL, 'a'},
{"disassemble", no_argument, NULL, 'd'}, {"disassemble", no_argument, NULL, 'd'},
{"dynamic-reloc", no_argument, NULL, 'R'},
{"dynamic-syms", no_argument, NULL, 'T'},
{"file-headers", no_argument, NULL, 'f'}, {"file-headers", no_argument, NULL, 'f'},
{"full-contents", no_argument, NULL, 's'}, {"full-contents", no_argument, NULL, 's'},
{"headers", no_argument, NULL, 'h'}, {"headers", no_argument, NULL, 'h'},
@ -196,11 +213,41 @@ slurp_symtab (abfd)
if (symcount < 0) if (symcount < 0)
bfd_fatal (bfd_get_filename (abfd)); bfd_fatal (bfd_get_filename (abfd));
if (symcount == 0) if (symcount == 0)
fprintf (stderr, "%s: %s: No symbols\n",
program_name, bfd_get_filename (abfd));
return sy;
}
/* Read in the dynamic symbols. */
static asymbol **
slurp_dynamic_symtab (abfd)
bfd *abfd;
{
asymbol **sy = (asymbol **) NULL;
long storage;
if (!(bfd_get_file_flags (abfd) & DYNAMIC))
{ {
fprintf (stderr, "%s: %s: Invalid symbol table\n", fprintf (stderr, "%s: %s: not a dynamic object\n",
program_name, bfd_get_filename (abfd)); program_name, bfd_get_filename (abfd));
exit (1); return NULL;
} }
storage = bfd_get_dynamic_symtab_upper_bound (abfd);
if (storage < 0)
bfd_fatal (bfd_get_filename (abfd));
if (storage)
{
sy = (asymbol **) xmalloc (storage);
}
dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
if (dynsymcount < 0)
bfd_fatal (bfd_get_filename (abfd));
if (dynsymcount == 0)
fprintf (stderr, "%s: %s: No dynamic symbols\n",
program_name, bfd_get_filename (abfd));
return sy; return sy;
} }
@ -938,12 +985,20 @@ display_bfd (abfd)
{ {
syms = slurp_symtab (abfd); syms = slurp_symtab (abfd);
} }
if (dump_dynamic_symtab || dump_dynamic_reloc_info)
{
dynsyms = slurp_dynamic_symtab (abfd);
}
if (dump_symtab) if (dump_symtab)
dump_symbols (abfd); dump_symbols (abfd, false);
if (dump_dynamic_symtab)
dump_symbols (abfd, true);
if (dump_stab_section_info) if (dump_stab_section_info)
dump_stabs (abfd); dump_stabs (abfd);
if (dump_reloc_info) if (dump_reloc_info)
dump_relocs (abfd); dump_relocs (abfd);
if (dump_dynamic_reloc_info)
dump_dynamic_relocs (abfd);
if (dump_section_contents) if (dump_section_contents)
dump_data (abfd); dump_data (abfd);
/* Note that disassemble_data re-orders the syms table, but that is /* Note that disassemble_data re-orders the syms table, but that is
@ -1065,17 +1120,33 @@ dump_data (abfd)
/* Should perhaps share code and display with nm? */ /* Should perhaps share code and display with nm? */
static void static void
dump_symbols (abfd) dump_symbols (abfd, dynamic)
bfd *abfd; bfd *abfd;
boolean dynamic;
{ {
asymbol **current;
long max;
long count; long count;
asymbol **current = syms;
printf ("SYMBOL TABLE:\n"); if (dynamic)
for (count = 0; count < symcount; count++)
{ {
current = dynsyms;
max = dynsymcount;
if (max == 0)
return;
printf ("DYNAMIC SYMBOL TABLE:\n");
}
else
{
current = syms;
max = symcount;
if (max == 0)
return;
printf ("SYMBOL TABLE:\n");
}
for (count = 0; count < max; count++)
{
if (*current) if (*current)
{ {
bfd *cur_bfd = bfd_asymbol_bfd(*current); bfd *cur_bfd = bfd_asymbol_bfd(*current);
@ -1086,7 +1157,6 @@ dump_symbols (abfd)
*current, bfd_print_symbol_all); *current, bfd_print_symbol_all);
printf ("\n"); printf ("\n");
} }
} }
current++; current++;
} }
@ -1133,8 +1203,6 @@ dump_relocs (abfd)
} }
else else
{ {
arelent **p;
relpp = (arelent **) xmalloc (relsize); relpp = (arelent **) xmalloc (relsize);
/* Note that this must be done *before* we sort the syms table. */ /* Note that this must be done *before* we sort the syms table. */
relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms); relcount = bfd_canonicalize_reloc (abfd, a, relpp, syms);
@ -1147,63 +1215,110 @@ dump_relocs (abfd)
else else
{ {
printf ("\n"); printf ("\n");
/* Get column headers lined up reasonably. */ dump_reloc_set (abfd, relpp, relcount);
{
static int width;
if (width == 0)
{
char buf[30];
sprintf_vma (buf, (bfd_vma) -1);
width = strlen (buf) - 7;
}
printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
}
for (p = relpp; relcount && *p != (arelent *) NULL; p++,
relcount--)
{
arelent *q = *p;
CONST char *sym_name;
CONST char *section_name;
if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
{
sym_name = (*(q->sym_ptr_ptr))->name;
section_name = (*(q->sym_ptr_ptr))->section->name;
}
else
{
sym_name = NULL;
section_name = NULL;
}
if (sym_name)
{
printf_vma (q->address);
printf (" %-16s %s",
q->howto->name,
sym_name);
}
else
{
if (section_name == (CONST char *) NULL)
section_name = "*unknown*";
printf_vma (q->address);
printf (" %-16s [%s]",
q->howto->name,
section_name);
}
if (q->addend)
{
printf ("+0x");
printf_vma (q->addend);
}
printf ("\n");
}
printf ("\n\n"); printf ("\n\n");
free (relpp);
} }
free (relpp);
} }
}
}
static void
dump_dynamic_relocs (abfd)
bfd *abfd;
{
long relsize;
arelent **relpp;
long relcount;
printf ("DYNAMIC RELOCATION RECORDS");
relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
if (relsize < 0)
bfd_fatal (bfd_get_filename (abfd));
if (relsize == 0)
{
printf (" (none)\n\n");
}
else
{
relpp = (arelent **) xmalloc (relsize);
relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms);
if (relcount < 0)
bfd_fatal (bfd_get_filename (abfd));
else if (relcount == 0)
{
printf (" (none)\n\n");
}
else
{
printf ("\n");
dump_reloc_set (abfd, relpp, relcount);
printf ("\n\n");
}
free (relpp);
}
}
static void
dump_reloc_set (abfd, relpp, relcount)
bfd *abfd;
arelent **relpp;
long relcount;
{
arelent **p;
/* Get column headers lined up reasonably. */
{
static int width;
if (width == 0)
{
char buf[30];
sprintf_vma (buf, (bfd_vma) -1);
width = strlen (buf) - 7;
}
printf ("OFFSET %*s TYPE %*s VALUE \n", width, "", 12, "");
}
for (p = relpp; relcount && *p != (arelent *) NULL; p++, relcount--)
{
arelent *q = *p;
CONST char *sym_name;
CONST char *section_name;
if (q->sym_ptr_ptr && *q->sym_ptr_ptr)
{
sym_name = (*(q->sym_ptr_ptr))->name;
section_name = (*(q->sym_ptr_ptr))->section->name;
}
else
{
sym_name = NULL;
section_name = NULL;
}
if (sym_name)
{
printf_vma (q->address);
printf (" %-16s %s",
q->howto->name,
sym_name);
}
else
{
if (section_name == (CONST char *) NULL)
section_name = "*unknown*";
printf_vma (q->address);
printf (" %-16s [%s]",
q->howto->name,
section_name);
}
if (q->addend)
{
printf ("+0x");
printf_vma (q->addend);
}
printf ("\n");
} }
} }
@ -1352,7 +1467,7 @@ main (argc, argv)
bfd_init (); bfd_init ();
while ((c = getopt_long (argc, argv, "ib:m:Vdlfahrtxsj:", long_options, while ((c = getopt_long (argc, argv, "ib:m:VdlfahrRtTxsj:", long_options,
(int *) 0)) (int *) 0))
!= EOF) != EOF)
{ {
@ -1389,6 +1504,9 @@ main (argc, argv)
case 't': case 't':
dump_symtab = 1; dump_symtab = 1;
break; break;
case 'T':
dump_dynamic_symtab = 1;
break;
case 'd': case 'd':
disassemble = true; disassemble = true;
break; break;
@ -1398,6 +1516,9 @@ main (argc, argv)
case 'r': case 'r':
dump_reloc_info = 1; dump_reloc_info = 1;
break; break;
case 'R':
dump_dynamic_reloc_info = 1;
break;
case 'a': case 'a':
dump_ar_hdrs = 1; dump_ar_hdrs = 1;
break; break;