Bug 26302

Summary: nm -D -u now by default displays symbol versions, adding --with-symbol-versions duplicates them
Product: binutils Reporter: Jakub Bogusz <qboosh>
Component: binutilsAssignee: H.J. Lu <hjl.tools>
Status: RESOLVED FIXED    
Severity: normal CC: ian, marillat
Priority: P2    
Version: 2.35   
Target Milestone: 2.36   
Host: Target:
Build: Last reconfirmed: 2020-07-27 00:00:00

Description Jakub Bogusz 2020-07-26 13:54:51 UTC
`nm -D -u` behaviour changed between 2.34 and 2.35.
New version prints undefined symbol versions, adding --with-symbol-versions duplicates them. It's probably connected with PR/25708 changes.

Example (from linux kernel tools, which build gets broken after binutils upgrade to 2.35 - reported in PLD Linux, Debian and Ubuntu):

nm 2.34 (i686-linux):
$ nm -u -D plugin_function.so
         U free  
         U memset
         U realloc 
         U strcmp
         U strdup
         U tep_find_function
         U tep_get_field_val
         U tep_plugin_add_options 
         U tep_plugin_remove_options
         U tep_register_event_handler
         U tep_unregister_event_handler
         U trace_seq_printf
         U trace_seq_putc
         U warning 

$ nm -u -D --with-symbol-versions plugin_function.so
         U free@GLIBC_2.0
         U memset@GLIBC_2.0
         U realloc@GLIBC_2.0
         U strcmp@GLIBC_2.0
         U strdup@GLIBC_2.0
         U tep_find_function
         U tep_get_field_val
         U tep_plugin_add_options
         U tep_plugin_remove_options
         U tep_register_event_handler
         U tep_unregister_event_handler
         U trace_seq_printf
         U trace_seq_putc
         U warning

nm 2.35 (x86_64-linux, so symbol versions differ from i686):
$ nm -u -D plugin_function.so
                 U free@@GLIBC_2.2.5
                 U memset@@GLIBC_2.2.5
                 U realloc@@GLIBC_2.2.5
                 U strcmp@@GLIBC_2.2.5
                 U strdup@@GLIBC_2.2.5
                 U tep_find_function
                 U tep_get_field_val
                 U tep_plugin_add_options
                 U tep_plugin_remove_options
                 U tep_register_event_handler
                 U tep_unregister_event_handler
                 U trace_seq_printf
                 U trace_seq_putc
                 U warning

$ nm -u -D --with-symbol-versions plugin_function.so
                 U free@@GLIBC_2.2.5@GLIBC_2.2.5
                 U memset@@GLIBC_2.2.5@GLIBC_2.2.5
                 U realloc@@GLIBC_2.2.5@GLIBC_2.2.5
                 U strcmp@@GLIBC_2.2.5@GLIBC_2.2.5
                 U strdup@@GLIBC_2.2.5@GLIBC_2.2.5
                 U tep_find_function
                 U tep_get_field_val
                 U tep_plugin_add_options
                 U tep_plugin_remove_options
                 U tep_register_event_handler
                 U tep_unregister_event_handler
                 U trace_seq_printf
                 U trace_seq_putc
                 U warning

The same is visible on any dynamic library, e.g. libc.so.6:

$ nm -D -u /lib/libc.so.6
         U _dl_argv@@GLIBC_PRIVATE
         U _dl_exception_create@@GLIBC_PRIVATE
         U _dl_find_dso_for_object@@GLIBC_PRIVATE
[...]

$ nm -D -u /lib/libc.so.6 --with-symbol-versions
         U _dl_argv@@GLIBC_PRIVATE@GLIBC_PRIVATE
         U _dl_exception_create@@GLIBC_PRIVATE@GLIBC_PRIVATE
         U _dl_find_dso_for_object@@GLIBC_PRIVATE@GLIBC_PRIVATE
Comment 1 H.J. Lu 2020-07-27 13:45:39 UTC
A patch is posted at

https://sourceware.org/pipermail/binutils/2020-July/112556.html
Comment 2 Sourceware Commits 2020-08-10 12:20:24 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9b0ac51b22d0cf900f39e17e615bb22e32720f6e

commit 9b0ac51b22d0cf900f39e17e615bb22e32720f6e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Aug 10 05:17:28 2020 -0700

    nm: Remove --with-symbol-versions
    
    Since
    
    commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Tue Mar 24 04:23:11 2020 -0700
    
        bfd: Display symbol version for nm -D
    
    always displays symbol version for nm, remove --with-symbol-versions and
    silently accept it for backward compatibility.
    
    binutils/
    
            PR binutils/26302
            * nm.c (with_symbol_versions): Removed.
            (long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
            (long_options): Update --with-symbol-versions entry.
            (print_symbol): Remove the with_symbol_versions check.
            (main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
            compatibility.
            * doc/binutils.texi: Remove --with-symbol-versions.
    
    ld/
    
            PR binutils/26302
            * testsuite/ld-elf/pr26302.nd: New file.
            * testsuite/ld-elf/pr26302.ver: Likewise.
            * testsuite/ld-elf/pr26302a.c: Likewise.
            * testsuite/ld-elf/pr26302b.c: Likewise.
            * testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
Comment 3 Sourceware Commits 2020-12-31 23:50:14 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=794e008bac4ed9948015644bcf9b3ae178ef9a50

commit 794e008bac4ed9948015644bcf9b3ae178ef9a50
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Aug 10 05:17:28 2020 -0700

    nm: Remove --with-symbol-versions
    
    Since
    
    commit 7e6e972f74aeac0ebdbd95a7f905d871cd2581de
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Tue Mar 24 04:23:11 2020 -0700
    
        bfd: Display symbol version for nm -D
    
    always displays symbol version for nm, remove --with-symbol-versions and
    silently accept it for backward compatibility.
    
    binutils/
    
            PR binutils/26302
            * nm.c (with_symbol_versions): Removed.
            (long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
            (long_options): Update --with-symbol-versions entry.
            (print_symbol): Remove the with_symbol_versions check.
            (main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
            compatibility.
            * doc/binutils.texi: Remove --with-symbol-versions.
    
    ld/
    
            PR binutils/26302
            * testsuite/ld-elf/pr26302.nd: New file.
            * testsuite/ld-elf/pr26302.ver: Likewise.
            * testsuite/ld-elf/pr26302a.c: Likewise.
            * testsuite/ld-elf/pr26302b.c: Likewise.
            * testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
    
    (cherry picked from commit 9b0ac51b22d0cf900f39e17e615bb22e32720f6e)
Comment 4 Alan Modra 2021-01-04 00:34:28 UTC
Fixed 2.35 and for 2.36