The nm -P/--portability option no longer outputs valid portable-format output, when dealing with libraries with symbol versions. The column that should contain the symbol type now contains a concatenation of the symbol version and the symbol type. This seems to have happened some time between 2.31.1 and 2.35.1. (Originally reported at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=978599 .) nm -DP /bin/ls from binutils 2.31.1: _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w __assert_fail U __ctype_b_loc U __ctype_get_mb_cur_max U __ctype_tolower_loc U __ctype_toupper_loc U __cxa_atexit U __cxa_finalize w __errno_location U ... nm -DP /bin/ls from binutils 2.35.1: _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w __assert_fail @@GLIBC_2.2.5U __ctype_b_loc @@GLIBC_2.3U __ctype_get_mb_cur_max @@GLIBC_2.2.5U __ctype_tolower_loc @@GLIBC_2.3U __ctype_toupper_loc @@GLIBC_2.3U __cxa_atexit @@GLIBC_2.2.5U __cxa_finalize @@GLIBC_2.2.5w __errno_location @@GLIBC_2.2.5U ... nm -DP /bin/ls from current HEAD as of 20201218 (snapshot from Debian experimental): _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w __assert_fail @GLIBC_2.2.5U __ctype_b_loc @GLIBC_2.3U __ctype_get_mb_cur_max @GLIBC_2.2.5U __ctype_tolower_loc @GLIBC_2.3U __ctype_toupper_loc @GLIBC_2.3U __cxa_atexit @GLIBC_2.2.5U __cxa_finalize @GLIBC_2.2.5w __errno_location @GLIBC_2.2.5U ...
Regressed with commit 7e6e972f74
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cab3f4da68672647cde72bc0c06ec08977819817 commit cab3f4da68672647cde72bc0c06ec08977819817 Author: Alan Modra <amodra@gmail.com> Date: Wed Dec 30 22:00:57 2020 +1030 PR27128, nm -P portable output format regression binutils/ PR 27128 * nm.c (print_symname): Append version string to symbol name before printing the lot under control of "form". Append version to demangled names too. ld/ PR 27128 * testsuite/ld-elf/pr27128.s: New file. * testsuite/ld-elf/pr27128.t: Likewise. * testsuite/ld-elf/pr27128a.d: Likewise. * testsuite/ld-elf/pr27128b.d: Likewise. * testsuite/ld-elf/pr27128c.d: Likewise. * testsuite/ld-elf/pr27128d.d: Likewise. * testsuite/ld-elf/pr27128e.d: Likewise.
Fixed
The binutils-2_35-branch branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5ca7ac981b734591b1ca0acc36c2b2081e64d06c commit 5ca7ac981b734591b1ca0acc36c2b2081e64d06c Author: Alan Modra <amodra@gmail.com> Date: Wed Dec 30 22:00:57 2020 +1030 PR27128, nm -P portable output format regression binutils/ PR 27128 * nm.c (print_symname): Append version string to symbol name before printing the lot under control of "form". Append version to demangled names too. ld/ PR 27128 * testsuite/ld-elf/pr27128.s: New file. * testsuite/ld-elf/pr27128.t: Likewise. * testsuite/ld-elf/pr27128a.d: Likewise. * testsuite/ld-elf/pr27128b.d: Likewise. * testsuite/ld-elf/pr27128c.d: Likewise. * testsuite/ld-elf/pr27128d.d: Likewise. * testsuite/ld-elf/pr27128e.d: Likewise. (cherry picked from commit cab3f4da68672647cde72bc0c06ec08977819817)
This fix made the output much better, but there's still an issue with it. Example: $ nm -DP /usr/lib/x86_64-linux-gnu/libavutil.so.56 | grep av_calloc av_calloc@@LIBAVUTIL_56 T 3cf90 79 $ nm -DP /usr/bin/ffmpeg | grep av_calloc av_calloc@LIBAVUTIL_56 U The defined symbol has an @@, while the undefined symbol has an @, which prevents tools from matching up the two.
@@ and @ have different meanings in symbol definitions. sym@@ver specifies a definition of sym that satifies references to plain sym as well as sym@ver. sym@ver2 in a definition only satifies references to sym@ver2. If the tools of which you speak really need to match up symbol definitions to references then they would not have worked properly when multiple versions of a given symbol existed, prior to nm reporting versions. So I think your tools need updating, unless they are only expected to work in simple use cases. That said, pr25708 also had a request for a way to turn off reporting versions, and at one stage nm had an option to conditionally display version info. H.J., why was the version info made unconditional?
(In reply to Alan Modra from comment #6) > > That said, pr25708 also had a request for a way to turn off reporting > versions, and at one stage nm had an option to conditionally display version > info. H.J., why was the version info made unconditional? What was the option name not to display symbol version?
Created attachment 13268 [details] Add nm --without-symbol-versions There wasn't one to turn off symbol versions. After df2c87b58037 for pr20751 symbol versions for dynamic symbols were displayed by specifying the option --with-symbol-versions. In pr27128 and commit 7e6e972f74a you apparently decided that nm -D ought to display symbol versions by default. I agree. That makes more sense, because by default symbol versions are displayed in relocatable object files. Hmm, and by the look of pr26302 you did not notice nm already had an option to display symbol versions.
I meant "pr25708 and commit 7e6e972f74a"
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6a1224ec762f7dd59d7abd2e5dc3be26bb157cd1 commit 6a1224ec762f7dd59d7abd2e5dc3be26bb157cd1 Author: Alan Modra <amodra@gmail.com> Date: Sat Feb 27 15:39:05 2021 +1030 PR27128, nm -P portable output format regression Add nm --without-symbol-versions. binutils/ PR 27128 * doc/binutils.texi: Add nm --with-symbol-versions and --without-symbol-versions documentation. * nm.c (with_symbol_versions): New variable. (enum long_option_values): Delete OPTION_WITH_SYMBOL_VERSIONS. (long_options): Make --with-symbol-versions entry twiddle the flag. Add --without-symbol-versions. (print_symname): Strip version when !with_symbol_versions. Add dynamic version info under control of with_symbol_versions. (main): Remove OPTION_WITH_SYMBOL_VERSIONS case. ld/ * testsuite/ld-elf/pr25708.d: Add --with-symbol-versions to nm. * testsuite/ld-elf/pr27128a.d: Likewise. * testsuite/ld-elf/pr27128b.d: Likewise. * testsuite/ld-elf/pr27128c.d: Likewise. * testsuite/ld-elf/pr27128d.d: Likewise. * testsuite/ld-elf/pr27128e.d: Likewise.
Fixed as best we can.