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.
This commit is contained in:
Cary Coutant 2018-07-14 12:29:03 -07:00
parent 6cb624f8a0
commit 1b115e8e0e
7 changed files with 112 additions and 4 deletions

View File

@ -1,3 +1,14 @@
2018-07-14 Cary Coutant <ccoutant@gmail.com>
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.
2018-07-11 Franz Sirl <franz.sirl-kernel@lauterbach.com>
* main.cc (main): Print m.arena as long long.

View File

@ -1898,10 +1898,13 @@ Symbol_table::define_special_symbol(const char** pname, const char** pversion,
add_to_table = true;
add_loc = ins.first;
if (is_default_version && !insdefault.second)
if (is_default_version
&& !insdefault.second
&& insdefault.first->second->version() == NULL)
{
// We are adding NAME/VERSION, and it is the default
// version. We already have an entry for NAME/NULL.
// version. We already have an entry for NAME/NULL
// that does not already have a version.
oldsym = insdefault.first->second;
*resolve_oldsym = true;
}

View File

@ -1880,6 +1880,15 @@ ver_test_14.syms: ver_test_14
ver_test_14: gcctestdir/ld ver_test_main.o ver_test_1.so ver_test_2.so ver_test_4.so ver_test_14.script
$(CXXLINK) -Bgcctestdir/ -Wl,--version-script,$(srcdir)/ver_test_14.script -Wl,-E -Wl,-R,. ver_test_main.o ver_test_1.so ver_test_2.so ver_test_4.so
check_SCRIPTS += ver_test_pr23409.sh
check_DATA += ver_test_pr23409.syms
ver_test_pr23409.syms: ver_test_pr23409_1.so
$(TEST_READELF) --dyn-syms -W $< >$@
ver_test_pr23409_1.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_1.script ver_test_pr23409_2.so
gcctestdir/ld -shared -o $@ ver_test_1.o ver_test_pr23409_2.so --version-script $(srcdir)/ver_test_pr23409_1.script
ver_test_pr23409_2.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_2.script
gcctestdir/ld -shared -o $@ ver_test_1.o --version-script $(srcdir)/ver_test_pr23409_2.script
check_SCRIPTS += weak_as_needed.sh
check_DATA += weak_as_needed.stdout
weak_as_needed.stdout: weak_as_needed_a.so

View File

@ -479,8 +479,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_4.sh ver_test_5.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_7.sh ver_test_8.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.sh ver_test_13.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.sh weak_as_needed.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr23409.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_as_needed.sh relro_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.sh \
@ -536,6 +537,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_13.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr23409.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_as_needed.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_3.err \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test.stdout \
@ -5807,6 +5809,13 @@ ver_test_14.sh.log: ver_test_14.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
ver_test_pr23409.sh.log: ver_test_pr23409.sh
@p='ver_test_pr23409.sh'; \
b='ver_test_pr23409.sh'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
weak_as_needed.sh.log: weak_as_needed.sh
@p='weak_as_needed.sh'; \
b='weak_as_needed.sh'; \
@ -8731,6 +8740,12 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -T $< | $(TEST_CXXFILT) >$@
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_14: gcctestdir/ld ver_test_main.o ver_test_1.so ver_test_2.so ver_test_4.so ver_test_14.script
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--version-script,$(srcdir)/ver_test_14.script -Wl,-E -Wl,-R,. ver_test_main.o ver_test_1.so ver_test_2.so ver_test_4.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr23409.syms: ver_test_pr23409_1.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) --dyn-syms -W $< >$@
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr23409_1.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_1.script ver_test_pr23409_2.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ ver_test_1.o ver_test_pr23409_2.so --version-script $(srcdir)/ver_test_pr23409_1.script
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr23409_2.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_2.script
@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ ver_test_1.o --version-script $(srcdir)/ver_test_pr23409_2.script
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_as_needed.stdout: weak_as_needed_a.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -dW --dyn-syms $< >$@
@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_as_needed_a.so: gcctestdir/ld weak_as_needed_a.o weak_as_needed_b.so weak_as_needed_c.so

View File

@ -0,0 +1,64 @@
#!/bin/sh
# ver_test_pr23409.sh -- a test case for version scripts
# Copyright (C) 2018 Free Software Foundation, Inc.
# Written by Cary Coutant <ccoutant@gmail.com>.
# This file is part of gold.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
# This test verifies that linker-generated symbols (e.g., _end)
# get correct version information even in the presence of
# a shared library that provides those symbols with different
# versions.
check()
{
if ! grep -q "$2" "$1"
then
echo "Did not find expected symbol in $1:"
echo " $2"
echo ""
echo "Actual output below:"
cat "$1"
exit 1
fi
}
check_missing()
{
if grep -q "$2" "$1"
then
echo "Found unexpected symbol in $1:"
echo " $2"
echo ""
echo "Actual output below:"
cat "$1"
exit 1
fi
}
check ver_test_pr23409.syms "_end@@VER1$"
check ver_test_pr23409.syms "_edata@@VER1$"
check ver_test_pr23409.syms "__bss_start@@VER1$"
check_missing ver_test_pr23409.syms "_end@VER"
check_missing ver_test_pr23409.syms "_edata@VER"
check_missing ver_test_pr23409.syms "__bss_start@VER"
exit 0

View File

@ -0,0 +1,3 @@
VER1 {
global: *;
};

View File

@ -0,0 +1,3 @@
VER2 {
global: *;
};