Bug 28158 - nm --dynamic and readelf --dyn-syms vs. copy reloc symbols
Summary: nm --dynamic and readelf --dyn-syms vs. copy reloc symbols
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: 2.38
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-01 02:12 UTC by Alan Modra
Modified: 2021-08-05 11:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2021-08-01 02:12:16 UTC
The following testcase gives readelf --dyn-syms output on x86_64-linux of

Symbol table '.dynsym' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000403000     8 NOTYPE  GLOBAL DEFAULT   13 foo@VER (2)

vs. nm --dynamic output of

0000000000403000 B foo@@VER

Notice the disagreement in number of '@'s shown.

cat > prxxxxxa.s <<\EOF
 .text
 .dc.a foo
EOF
cat > prxxxxxb.s <<\EOF
 .data
 .globl foo
foo: .dc.a foo
 .size foo, .-foo
EOF
cat > prxxxxx.ver <<\EOF
VER { global: foo; local: *; };
EOF
gas/as-new -o prxxxxxa.o prxxxxxa.s
gas/as-new -o prxxxxxb.o prxxxxxb.s
ld/ld-new -shared -o prxxxxx.so prxxxxxb.o --version-script prxxxxx.ver 
ld/ld-new -o prxxxxx prxxxxxa.o prxxxxx.so
binutils/readelf --dyn-syms prxxxxx
binutils/nm-new --dynamic prxxxxx
Comment 1 H.J. Lu 2021-08-01 13:56:08 UTC
The difference comes from

      if (ivna.vna_other == vers_data)
        {
          *sym_info = symbol_undefined;
          *vna_other = ivna.vna_other;
          return (ivna.vna_name < strtab_size
                  ? strtab + ivna.vna_name : _("<corrupt>"));
        }

in get_symbol_version_string since the version VER is undefined. I can see
the benefit of readelf behavior.  foo in executable can't be used to resolve
any references to foo.
Comment 2 H.J. Lu 2021-08-01 14:32:05 UTC
A patch is posted at

https://sourceware.org/pipermail/binutils/2021-August/117561.html
Comment 3 Sourceware Commits 2021-08-04 12:13:39 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=f897689c880ed1049b708e6c1f9745c8604808e3

commit f897689c880ed1049b708e6c1f9745c8604808e3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Aug 1 07:26:20 2021 -0700

    elf: Treat undefined version as hidden
    
    Since undefined version can't be used to resolve any references without
    the original definition, treat it as hidden.
    
    bfd/
    
            PR binutils/28158
            * elf.c (_bfd_elf_get_symbol_version_string): Treat undefined
            version as hidden.
    
    ld/
    
            PR binutils/28158
            * testsuite/ld-elf/linux-x86.exp: Run PR binutils/28158 tests.
            * testsuite/ld-elf/pr28158-1.c: New file.
            * testsuite/ld-elf/pr28158-2.S: Likewise.
            * testsuite/ld-elf/pr28158.nd: Likewise.
            * testsuite/ld-elf/pr28158.rd: Likewise.
            * testsuite/ld-elf/pr28158.t: Likewise.
            * testsuite/ld-elfvers/vers2.dsym: Updated.
            * testsuite/ld-elfvers/vers3.dsym: Likewise.
            * testsuite/ld-elfvers/vers6.dsym: Likewise.
            * testsuite/ld-elfvers/vers19.dsym: Likewise.
            * testsuite/ld-elfvers/vers22.dsym: Likewise.
            * testsuite/ld-elfvers/vers23.dsym: Likewise.
            * testsuite/ld-elfvers/vers23d.dsym: Likewise.
            * testsuite/ld-elfvers/vers27d4.dsym: Likewise.
            * testsuite/ld-elfvers/vers28c.dsym: Likewise.
Comment 4 H.J. Lu 2021-08-04 12:49:30 UTC
Fixed for 2.38.
Comment 5 Sourceware Commits 2021-08-05 11:22:04 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 5570ab7f44dffa808ee6d90c9a8dbf50ae80621b
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Aug 5 15:29:52 2021 +0930

    Re: elf: Treat undefined version as hidden
    
    Fix fallout in cris testsuite
    
            PR binutils/28158
            * ld-cris/libdso-1c.d: Update for version display change.
            * ld-cris/libdso-15b.d: Likewise.