Bug 26979 - Visibility of undefined foo@v1 should constrain defined foo@@v1
Summary: Visibility of undefined foo@v1 should constrain defined foo@@v1
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.36
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-30 01:02 UTC by Fangrui Song
Modified: 2020-12-01 01:01 UTC (History)
0 users

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-11-30 01:02:18 UTC
cat > ./def1.s <<eof
.globl foo
.symver foo, foo@@@v1
foo:
eof
cat > ./ref1.s <<eof
.protected foo_v1
.symver foo_v1, foo@v1
call foo_v1
eof
cat > ./ver <<eof
v1 {};
eof

gcc -c *.s

% ld.bfd -shared --version-script=ver ref1.o def1.o

Symbol table '.dynsym' contains 3 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS v1
     2: 0000000000001025     0 NOTYPE  GLOBAL DEFAULT    9 foo@@v1
% gold -shared --version-script=ver ref1.o def1.o

Symbol table '.dynsym' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000002000     0 NOTYPE  GLOBAL DEFAULT    8 _end
     2: 0000000000002000     0 NOTYPE  GLOBAL DEFAULT    8 _edata
     3: 00000000000002bd     0 NOTYPE  GLOBAL PROTECTED    7 foo@@v1
     4: 0000000000002000     0 NOTYPE  GLOBAL DEFAULT    8 __bss_start
     5: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS v1


The gold behavior is more sensible: the visibility of the output foo@@v1 is changed to STV_PROTECTED. Note, if def1.s defines the non-default version foo@v1 instead, both GNU ld and gold produce a protected foo@v1.
Comment 1 Sourceware Commits 2020-12-01 01:00:12 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 5160d0f323d47031cb73c39a4dbd31d8976b4c8e
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Nov 30 19:19:00 2020 +1030

    PR26979, Visibility of undefined foo@v1 should constrain foo@@v1
    
    Also, undefined foo should constrain the visibility of foo@@v1 just as
    it does for a later plain foo definition.
    
    bfd/
            PR 26979
            * elf-bfd.h (elf_backend_merge_symbol_attribute): Update prototype.
            * elf32-m68hc1x.h (elf32_m68hc11_merge_symbol_attribute): Likewise.
            * elfxx-mips.h (_bfd_mips_elf_merge_symbol_attribute): Likewise.
            * elfxx-x86.h (_bfd_x86_elf_merge_symbol_attribute): Likewise.
            * elf32-m68hc1x.c (elf32_m68hc11_merge_symbol_attribute): Replace
            isym parameter with st_other.  Adjust code.
            * elf64-alpha.c (elf64_alpha_merge_symbol_attribute): Likewise.
            * elf64-ppc.c (ppc64_elf_merge_symbol_attribute): Likewise.
            * elfnn-aarch64.c (elfNN_aarch64_merge_symbol_attribute): Likewise.
            * elfxx-mips.c (_bfd_mips_elf_merge_symbol_attribute): Likewise.
            * elfxx-x86.c (_bfd_x86_elf_merge_symbol_attribute): Likewise.
            * elflink.c (elf_merge_st_other): Likewise.
            (_bfd_elf_merge_symbol, elf_link_add_object_symbols): Adjust to suit.
            (_bfd_elf_copy_link_hash_symbol_type): Likewise.
            (_bfd_elf_add_default_symbol): Merge st_other from undecorated
            symbol and @VER symbol to @@VER symbol.
    ld/
            * testsuite/ld-elf/pr26979a.s,
            * testsuite/ld-elf/pr26979b.s,
            * testsuite/ld-elf/pr26979c.s,
            * testsuite/ld-elf/pr26979.ver,
            * testsuite/ld-elf/pr26979a.d,
            * testsuite/ld-elf/pr26979b.d: New tests.
Comment 2 Alan Modra 2020-12-01 01:01:35 UTC
Fixed for 2.36.