aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@gmail.com>2018-06-20 01:24:11 -0700
committerCary Coutant <ccoutant@gmail.com>2018-06-20 01:25:04 -0700
commitebb1332297da904a4adab0d3696a5512604f5edd (patch)
treedb27440b898ad42f3200a5024e014cc40c7cb08b
parent160d1b3d74593bf42155da24569f54a6e7140f65 (diff)
downloadgdb-ebb1332297da904a4adab0d3696a5512604f5edd.zip
gdb-ebb1332297da904a4adab0d3696a5512604f5edd.tar.gz
gdb-ebb1332297da904a4adab0d3696a5512604f5edd.tar.bz2
Fix problem where gold does not create base version for executables.
gold/ PR gold/23268 * dynobj.cc (Versions::Versions): Change init for needs_base_version_. (Versions::record_version): Add verdefs for both shared objects and executables. (Versions::add_def): Likewise for base version. (Versions::add_need): Don't add base version for executables. (Versions::version_index): Look up version for both shared objects and executables. * testsuite/Makefile.am (ver_test_14): New test case. * testsuite/Makefile.in: Regenerate. * testsuite/ver_test_14.script: New version script. * testsuite/ver_test_14.sh: New test script.
-rw-r--r--gold/ChangeLog15
-rw-r--r--gold/dynobj.cc24
-rw-r--r--gold/testsuite/Makefile.am7
-rw-r--r--gold/testsuite/Makefile.in16
-rw-r--r--gold/testsuite/ver_test_14.script6
-rwxr-xr-xgold/testsuite/ver_test_14.sh43
6 files changed, 93 insertions, 18 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 71df0ef..626bcdb 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,18 @@
+2018-06-20 Cary Coutant <ccoutant@gmail.com>
+
+ PR gold/23268
+ * dynobj.cc (Versions::Versions): Change init for needs_base_version_.
+ (Versions::record_version): Add verdefs for both shared objects and
+ executables.
+ (Versions::add_def): Likewise for base version.
+ (Versions::add_need): Don't add base version for executables.
+ (Versions::version_index): Look up version for both shared objects and
+ executables.
+ * testsuite/Makefile.am (ver_test_14): New test case.
+ * testsuite/Makefile.in: Regenerate.
+ * testsuite/ver_test_14.script: New version script.
+ * testsuite/ver_test_14.sh: New test script.
+
2018-06-19 Joshua Watt <jpewhacker@gmail.com>
Cary Coutant <ccoutant@gmail.com>
diff --git a/gold/dynobj.cc b/gold/dynobj.cc
index 7012802..75e7e75 100644
--- a/gold/dynobj.cc
+++ b/gold/dynobj.cc
@@ -1439,7 +1439,7 @@ Versions::Versions(const Version_script_info& version_script,
Stringpool* dynpool)
: defs_(), needs_(), version_table_(),
is_finalized_(false), version_script_(version_script),
- needs_base_version_(parameters->options().shared())
+ needs_base_version_(true)
{
if (!this->version_script_.empty())
{
@@ -1536,8 +1536,7 @@ Versions::record_version(const Symbol_table* symtab,
if (!sym->is_from_dynobj() && !sym->is_copied_from_dynobj())
{
- if (parameters->options().shared())
- this->add_def(dynpool, sym, version, version_key);
+ this->add_def(dynpool, sym, version, version_key);
}
else
{
@@ -1574,18 +1573,13 @@ Versions::add_def(Stringpool* dynpool, const Symbol* sym, const char* version,
// find a definition of a symbol with a version which is not
// in the version script.
if (parameters->options().shared())
- {
- gold_error(_("symbol %s has undefined version %s"),
- sym->demangled_name().c_str(), version);
- if (this->needs_base_version_)
- this->define_base_version(dynpool);
- }
- else
- // We only insert a base version for shared library.
- gold_assert(!this->needs_base_version_);
-
+ gold_error(_("symbol %s has undefined version %s"),
+ sym->demangled_name().c_str(), version);
+
// When creating a regular executable, automatically define
// a new version.
+ if (this->needs_base_version_)
+ this->define_base_version(dynpool);
Verdef* vd = new Verdef(version, std::vector<std::string>(),
false, false, false, false);
this->defs_.push_back(vd);
@@ -1631,7 +1625,7 @@ Versions::add_need(Stringpool* dynpool, const char* filename, const char* name,
if (vn == NULL)
{
// Create base version definition lazily for shared library.
- if (this->needs_base_version_)
+ if (parameters->options().shared() && this->needs_base_version_)
this->define_base_version(dynpool);
// We have a new filename.
@@ -1715,8 +1709,6 @@ Versions::version_index(const Symbol_table* symtab, const Stringpool* dynpool,
Key k;
if (!sym->is_from_dynobj() && !sym->is_copied_from_dynobj())
{
- if (!parameters->options().shared())
- return elfcpp::VER_NDX_GLOBAL;
k = Key(version_key, 0);
}
else
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index e019bfa..b88b02f 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1873,6 +1873,13 @@ ver_test_13.so: gcctestdir/ld ver_test_13.o ver_test_13.script
ver_test_13.o: ver_test_13.c
$(COMPILE) -c -fpic -o $@ $<
+check_SCRIPTS += ver_test_14.sh
+check_DATA += ver_test_14.syms
+ver_test_14.syms: ver_test_14
+ $(TEST_OBJDUMP) -T $< | $(TEST_CXXFILT) >$@
+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_PROGRAMS += protected_1
protected_1_SOURCES = \
protected_main_1.cc protected_main_2.cc protected_main_3.cc
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 79cf6c7..e1b1762 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -479,7 +479,7 @@ 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@ relro_test.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.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 \
@@ -533,7 +533,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_7.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_8_2.so.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_13.syms protected_3.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_13.syms \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.syms protected_3.err \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \
@@ -5794,6 +5795,13 @@ ver_test_13.sh.log: ver_test_13.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_14.sh.log: ver_test_14.sh
+ @p='ver_test_14.sh'; \
+ b='ver_test_14.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)
relro_test.sh.log: relro_test.sh
@p='relro_test.sh'; \
b='relro_test.sh'; \
@@ -8700,6 +8708,10 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -shared -Wl,--version-script,$(srcdir)/ver_test_13.script ver_test_13.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_13.o: ver_test_13.c
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -fpic -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_14.syms: ver_test_14
+@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@protected_1.so: gcctestdir/ld protected_1_pic.o protected_2_pic.o protected_3_pic.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared protected_1_pic.o protected_2_pic.o protected_3_pic.o
diff --git a/gold/testsuite/ver_test_14.script b/gold/testsuite/ver_test_14.script
new file mode 100644
index 0000000..2400583
--- /dev/null
+++ b/gold/testsuite/ver_test_14.script
@@ -0,0 +1,6 @@
+V1 {
+global:
+ extern "C++" {
+ "t2()"; "t3()"; "t4()";
+ };
+};
diff --git a/gold/testsuite/ver_test_14.sh b/gold/testsuite/ver_test_14.sh
new file mode 100755
index 0000000..73a0e08
--- /dev/null
+++ b/gold/testsuite/ver_test_14.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# ver_test_14.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.
+
+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 ver_test_14.syms "V1 *t2()$"
+check ver_test_14.syms "V1 *t3()$"
+check ver_test_14.syms "V1 *t4()$"
+check ver_test_14.syms "Base *t4_2a$"
+
+exit 0