Bug 23409 - Shared libraries created with duplicate _end, _edata and __bss_start symbols
Summary: Shared libraries created with duplicate _end, _edata and __bss_start symbols
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: 2.32
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-13 02:34 UTC by Alan Modra
Modified: 2018-07-16 13:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2018-07-13 02:34:11 UTC
cat > end1.ver << EOF
VER1 {
  global: *;
};
EOF
cat > end2.ver << EOF
VER2 {
  global: *;
};
EOF
as -o dummy.o < /dev/null
ld.gold -shared -o lib2.so dummy.o --version-script end2.ver
ld.gold -shared -o lib1.so dummy.o lib2.so --version-script end1.ver

readelf --dyn-syms lib2.so 

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

readelf --dyn-syms lib1.so

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

Why are both _end@VER1 and _end@@VER1 present in lib1.so?

See https://bugzilla.redhat.com/show_bug.cgi?id=1600035
Comment 1 cvs-commit@gcc.gnu.org 2018-07-14 19:32:21 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

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

commit 1b115e8e0e051d65d0747f0a8a84eb6453866729
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Sat Jul 14 12:29:03 2018 -0700

    Fix problem causing duplicated linker-generated symbols with versions.
    
    When generating _end, _edata, etc. symbols, and a version script provides
    a version name, and we are linking against another shared library that
    provides those symbols with a different version, gold ends up trying to
    resolve the other shared library's symbols to the new definitions, resulting
    in two copies of each symbol, one as default, and one as non-default.
    This patch tests for that condition, and ignores the symbols provided
    by the other shared library.
    
    gold/
    	PR gold/23409
    	* symtab.cc (Symbol_table::define_special_symbol): Add check for
    	version name on existing symbol.
    	* testsuite/Makefile.am (ver_test_pr23409): New test case.
    	* testsuite/Makefile.in: Regenerate.
    	* testsuite/ver_test_pr23409.sh: New test script.
    	* testsuite/ver_test_pr23409_1.script: New version script.
    	* testsuite/ver_test_pr23409_2.script: New version script.
Comment 2 Cary Coutant 2018-07-14 19:34:44 UTC
Fixed on master.
Comment 3 cvs-commit@gcc.gnu.org 2018-07-16 13:31:12 UTC
The binutils-2_31-branch branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit 0694d6e5fb2c14934822e68a9a20b43317b0c2a8
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Jul 16 14:29:26 2018 +0100

    Import patch from mainline to fix gold's handling of already versioned symbols.
    
    gold	PR gold/23409
    	* symtab.cc (Symbol_table::define_special_symbol): Add check for
    	version name on existing symbol.
    	* testsuite/Makefile.am (ver_test_pr23409): New test case.
    	* testsuite/Makefile.in: Regenerate.
    	* testsuite/ver_test_pr23409.sh: New test script.
    	* testsuite/ver_test_pr23409_1.script: New version script.
    	* testsuite/ver_test_pr23409_2.script: New version script.