This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gold commit] PR 23409: 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.

-cary


2018-07-14  Cary Coutant  <ccoutant@gmail.com>

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.


diff --git a/gold/symtab.cc b/gold/symtab.cc
index c43d127507..aa7644156f 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -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;
 	    }
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 5f7d981e2e..e15788e562 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -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
diff --git a/gold/testsuite/ver_test_pr23409.sh b/gold/testsuite/ver_test_pr23409.sh
new file mode 100755
index 0000000000..ed1ef65506
--- /dev/null
+++ b/gold/testsuite/ver_test_pr23409.sh
@@ -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
diff --git a/gold/testsuite/ver_test_pr23409_1.script b/gold/testsuite/ver_test_pr23409_1.script
new file mode 100644
index 0000000000..69694541c0
--- /dev/null
+++ b/gold/testsuite/ver_test_pr23409_1.script
@@ -0,0 +1,3 @@
+VER1 {
+  global: *;
+};
diff --git a/gold/testsuite/ver_test_pr23409_2.script b/gold/testsuite/ver_test_pr23409_2.script
new file mode 100644
index 0000000000..fa45184546
--- /dev/null
+++ b/gold/testsuite/ver_test_pr23409_2.script
@@ -0,0 +1,3 @@
+VER2 {
+  global: *;
+};


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]