Bug 27128 - nm -P portable output format regression
Summary: nm -P portable output format regression
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.37
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-30 05:07 UTC by Josh Triplett
Modified: 2022-06-22 06:29 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-12-30 00:00:00


Attachments
Add nm --without-symbol-versions (2.39 KB, patch)
2021-02-27 05:34 UTC, Alan Modra
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Josh Triplett 2020-12-30 05:07:07 UTC
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         
...
Comment 1 Alan Modra 2020-12-30 11:38:09 UTC
Regressed with commit 7e6e972f74
Comment 2 Sourceware Commits 2020-12-31 08:41:16 UTC
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.
Comment 3 Alan Modra 2020-12-31 08:59:11 UTC
Fixed
Comment 4 Sourceware Commits 2020-12-31 23:50:30 UTC
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)
Comment 5 Josh Triplett 2021-01-06 23:31:29 UTC
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.
Comment 6 Alan Modra 2021-02-26 12:38:04 UTC
@@ 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?
Comment 7 H.J. Lu 2021-02-26 14:08:44 UTC
(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?
Comment 8 Alan Modra 2021-02-27 05:34:04 UTC
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.
Comment 9 Alan Modra 2021-02-27 05:35:50 UTC
I meant "pr25708 and commit 7e6e972f74a"
Comment 10 Sourceware Commits 2021-03-01 04:19:41 UTC
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.
Comment 11 Alan Modra 2021-03-10 07:31:04 UTC
Fixed as best we can.