Add the ability for nm to display symbol version information.

PR binutils/20751
	* nm.c (with_symbol_versions): New local variable.
	(long_options): Add --with-symbol-versions.
	(usage): Mention --with-symbol-versions.
	(print_symbol): If with_symbol_versions is set then display the
	version information associated with the symbol.
	* NEWS: Mention the new feature.
	* doc/binutils.texi (nm): Document the new option.
	(objdump): Describe how symbol version information is displayed
	for dynamic symbol dumps.
	(readelf): Describe how symbol version information is displayed.
	* testsuite/binutils-all/nm.exp: Add a test of the new feature.
This commit is contained in:
Nick Clifton 2016-11-11 11:49:45 +00:00
parent 74f5402d08
commit df2c87b580
6 changed files with 99 additions and 2 deletions

View File

@ -1,3 +1,18 @@
2016-11-11 Nick Clifton <nickc@redhat.com>
PR binutils/20751
* nm.c (with_symbol_versions): New local variable.
(long_options): Add --with-symbol-versions.
(usage): Mention --with-symbol-versions.
(print_symbol): If with_symbol_versions is set then display the
version information associated with the symbol.
* NEWS: Mention the new feature.
* doc/binutils.texi (nm): Document the new option.
(objdump): Describe how symbol version information is displayed
for dynamic symbol dumps.
(readelf): Describe how symbol version information is displayed.
* testsuite/binutils-all/nm.exp: Add a test of the new feature.
2016-11-08 Nick Clifton <nickc@redhat.com>
PR binutils/20794

View File

@ -1,5 +1,9 @@
-*- text -*-
* The nm program has a new command lien option (--with-version-strings)
which will display a symbol's version information, if any, after the
symbol's name.
* The ARC port of objdump now accepts a -M option to specify the extra
instruction class(es) that should be disassembled.

View File

@ -743,7 +743,7 @@ nm [@option{-A}|@option{-o}|@option{--print-file-name}] [@option{-a}|@option{--d
[@option{-u}|@option{--undefined-only}] [@option{-V}|@option{--version}]
[@option{-X 32_64}] [@option{--defined-only}] [@option{--no-demangle}]
[@option{--plugin} @var{name}] [@option{--size-sort}] [@option{--special-syms}]
[@option{--synthetic}] [@option{--target=}@var{bfdname}]
[@option{--synthetic}] [@option{--with-symbol-versions}] [@option{--target=}@var{bfdname}]
[@var{objfile}@dots{}]
@c man end
@end smallexample
@ -1031,6 +1031,14 @@ Include synthetic symbols in the output. These are special symbols
created by the linker for various purposes. They are not shown by
default since they are not part of the binary's original source code.
@item --with-symbol-versions
Enables the display of symbol version information if any exists. The
version string is displayed as a suffix to the symbol name, preceeded by
an @@ character. For example @samp{foo@@VER_1}. If the version is
the default version to be used when resolving unversioned references
to the symbol then it is displayed as a suffix preceeded by two @@
characters. For example @samp{foo@@@@VER_2}.
@item --target=@var{bfdname}
@cindex object code format
Specify an object code format other than your system's default format.
@ -2618,6 +2626,10 @@ 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 @option{-D} (@option{--dynamic}) option.
The output format is similar to that produced by the @option{--syms}
option, except that an extra field is inserted before the symbol's
name, giving the version information associated with the symbol.
@item --special-syms
When displaying symbols include those which the target considers to be
special in some way and which would not normally be of interest to the
@ -4591,11 +4603,19 @@ Displays the detailed section information. Implies @option{-S}.
@itemx --syms
@cindex ELF symbol table information
Displays the entries in symbol table section of the file, if it has one.
If a symbol has version information associated with it then this is
displayed as well. The version string is displayed as a suffix to the
symbol name, preceeded by an @@ character. For example
@samp{foo@@VER_1}. If the version is the default version to be used
when resolving unversioned references to the symbol then it is
displayed as a suffix preceeded by two @@ characters. For example
@samp{foo@@@@VER_2}.
@item --dyn-syms
@cindex ELF dynamic symbol table information
Displays the entries in dynamic symbol table section of the file, if it
has one.
has one. The output format is the same as the format used by the
@option{--syms} option.
@item -e
@itemx --headers

View File

@ -161,6 +161,7 @@ static int show_stats = 0; /* Show statistics. */
static int show_synthetic = 0; /* Display synthesized symbols too. */
static int line_numbers = 0; /* Print line numbers for symbols. */
static int allow_special_symbols = 0; /* Allow special symbols. */
static int with_symbol_versions = 0; /* Include symbol version information in the output. */
/* When to print the names of files. Not mutually exclusive in SYSV format. */
static int filename_per_file = 0; /* Once per file, on its own line. */
@ -226,6 +227,7 @@ static struct option long_options[] =
{"defined-only", no_argument, &defined_only, 1},
{"undefined-only", no_argument, &undefined_only, 1},
{"version", no_argument, &show_version, 1},
{"with-symbol-versions", no_argument, &with_symbol_versions, 1},
{0, no_argument, 0, 0}
};
@ -271,6 +273,7 @@ usage (FILE *stream, int status)
-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\
--with-symbol-versions Display version strings after symbol names\n\
-X 32_64 (ignored)\n\
@FILE Read options from FILE\n\
-h, --help Display this information\n\
@ -879,6 +882,21 @@ print_symbol (bfd * abfd,
format->print_symbol_info (&info, abfd);
if (with_symbol_versions)
{
const char * version_string = NULL;
bfd_boolean hidden = FALSE;
if ((sym->flags & BSF_SYNTHETIC) == 0)
version_string = bfd_get_symbol_version_string (abfd, sym, &hidden);
if (bfd_is_und_section (bfd_get_section (sym)))
hidden = TRUE;
if (version_string && *version_string != '\0')
printf (hidden ? "@%s" : "@@%s", version_string);
}
if (line_numbers)
{
static asymbol **syms;

View File

@ -0,0 +1,9 @@
.symver foo_old,foo@VER_1
.hidden foo_old
foo_old:
.dc.b 0
.symver foo_new,foo@@VER_2
.global foo_new
foo_new:
.dc.b 0

View File

@ -207,4 +207,35 @@ if [regexp $want $got] then {
fail "nm --size-sort"
}
if [is_elf_format] {
# PR binutils/20751
# Test nm --with-symbol-versions
if {![binutils_assemble $srcdir/$subdir/nm-ver.s tmpdir/nm-ver.o]} then {
fail "nm --with-symbol-versions (assembling)"
} else {
if [is_remote host] {
set tmpfile [remote_download host tmpdir/nm-ver.o]
} else {
set tmpfile tmpdir/nm-ver.o
}
set got [binutils_run $NM "$NMFLAGS --with-symbol-versions --format sysv $tmpfile"]
if {! [regexp "foo@VER_1" $got]} then {
fail "nm --with-symbol-versions (grep for @VER_1)"
} else {
if {! [regexp "foo@VER_1" $got]} then {
fail "nm --with-symbol-versions (grep for @@VER_2)"
} else {
pass "nm --with-symbol-versions"
}
}
if { $verbose < 1 } {
remote_file host delete "tmpdir/nm-ver.o"
}
}
}
# There are certainly other tests that could be run.