diff options
author | Nick Clifton <nickc@redhat.com> | 2016-11-11 11:49:45 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2016-11-11 11:49:45 +0000 |
commit | df2c87b5803750d21f03b7d36f8d1abace3e1e14 (patch) | |
tree | f0518bd37e6acf61c8bb6a3d29c209e94664dcbe | |
parent | 74f5402d08b857d60499b27851c204954ce6c42c (diff) | |
download | fsf-binutils-gdb-df2c87b5803750d21f03b7d36f8d1abace3e1e14.zip fsf-binutils-gdb-df2c87b5803750d21f03b7d36f8d1abace3e1e14.tar.gz fsf-binutils-gdb-df2c87b5803750d21f03b7d36f8d1abace3e1e14.tar.bz2 |
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.
-rw-r--r-- | binutils/ChangeLog | 15 | ||||
-rw-r--r-- | binutils/NEWS | 4 | ||||
-rw-r--r-- | binutils/doc/binutils.texi | 24 | ||||
-rw-r--r-- | binutils/nm.c | 18 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/nm-ver.s | 9 | ||||
-rw-r--r-- | binutils/testsuite/binutils-all/nm.exp | 31 |
6 files changed, 99 insertions, 2 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index d586e03..4c4bb6b 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -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 diff --git a/binutils/NEWS b/binutils/NEWS index 9ec9724..5d0bc89 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -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. diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 5174625..6db3b6d 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -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 diff --git a/binutils/nm.c b/binutils/nm.c index 6d88748..d537441 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -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; diff --git a/binutils/testsuite/binutils-all/nm-ver.s b/binutils/testsuite/binutils-all/nm-ver.s new file mode 100644 index 0000000..e68c45a --- /dev/null +++ b/binutils/testsuite/binutils-all/nm-ver.s @@ -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 diff --git a/binutils/testsuite/binutils-all/nm.exp b/binutils/testsuite/binutils-all/nm.exp index 69944eb..8375893 100644 --- a/binutils/testsuite/binutils-all/nm.exp +++ b/binutils/testsuite/binutils-all/nm.exp @@ -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. |