1 From 1b115e8e0e051d65d0747f0a8a84eb6453866729 Mon Sep 17 00:00:00 2001
2 From: Cary Coutant <ccoutant@gmail.com>
3 Date: Sat, 14 Jul 2018 12:29:03 -0700
4 Subject: [PATCH 1/1] Fix problem causing duplicated linker-generated symbols
7 When generating _end, _edata, etc. symbols, and a version script provides
8 a version name, and we are linking against another shared library that
9 provides those symbols with a different version, gold ends up trying to
10 resolve the other shared library's symbols to the new definitions, resulting
11 in two copies of each symbol, one as default, and one as non-default.
12 This patch tests for that condition, and ignores the symbols provided
13 by the other shared library.
17 * symtab.cc (Symbol_table::define_special_symbol): Add check for
18 version name on existing symbol.
19 * testsuite/Makefile.am (ver_test_pr23409): New test case.
20 * testsuite/Makefile.in: Regenerate.
21 * testsuite/ver_test_pr23409.sh: New test script.
22 * testsuite/ver_test_pr23409_1.script: New version script.
23 * testsuite/ver_test_pr23409_2.script: New version script.
25 gold/ChangeLog | 11 ++++++
26 gold/symtab.cc | 7 +++-
27 gold/testsuite/Makefile.am | 9 +++++
28 gold/testsuite/Makefile.in | 19 +++++++++-
29 gold/testsuite/ver_test_pr23409.sh | 64 ++++++++++++++++++++++++++++++++
30 gold/testsuite/ver_test_pr23409_1.script | 3 ++
31 gold/testsuite/ver_test_pr23409_2.script | 3 ++
32 7 files changed, 112 insertions(+), 4 deletions(-)
33 create mode 100755 gold/testsuite/ver_test_pr23409.sh
34 create mode 100644 gold/testsuite/ver_test_pr23409_1.script
35 create mode 100644 gold/testsuite/ver_test_pr23409_2.script
37 diff --git a/gold/symtab.cc b/gold/symtab.cc
38 index c43d127..aa76441 100644
41 @@ -1898,10 +1898,13 @@ Symbol_table::define_special_symbol(const char** pname, const char** pversion,
45 - if (is_default_version && !insdefault.second)
46 + if (is_default_version
47 + && !insdefault.second
48 + && insdefault.first->second->version() == NULL)
50 // We are adding NAME/VERSION, and it is the default
51 - // version. We already have an entry for NAME/NULL.
52 + // version. We already have an entry for NAME/NULL
53 + // that does not already have a version.
54 oldsym = insdefault.first->second;
55 *resolve_oldsym = true;
57 diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
58 index 5f7d981..e15788e 100644
59 --- a/gold/testsuite/Makefile.am
60 +++ b/gold/testsuite/Makefile.am
61 @@ -1880,6 +1880,15 @@ ver_test_14.syms: ver_test_14
62 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
63 $(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
65 +check_SCRIPTS += ver_test_pr23409.sh
66 +check_DATA += ver_test_pr23409.syms
67 +ver_test_pr23409.syms: ver_test_pr23409_1.so
68 + $(TEST_READELF) --dyn-syms -W $< >$@
69 +ver_test_pr23409_1.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_1.script ver_test_pr23409_2.so
70 + gcctestdir/ld -shared -o $@ ver_test_1.o ver_test_pr23409_2.so --version-script $(srcdir)/ver_test_pr23409_1.script
71 +ver_test_pr23409_2.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_2.script
72 + gcctestdir/ld -shared -o $@ ver_test_1.o --version-script $(srcdir)/ver_test_pr23409_2.script
74 check_SCRIPTS += weak_as_needed.sh
75 check_DATA += weak_as_needed.stdout
76 weak_as_needed.stdout: weak_as_needed_a.so
77 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
78 index b4729bc..7305d32 100644
79 --- a/gold/testsuite/Makefile.in
80 +++ b/gold/testsuite/Makefile.in
81 @@ -479,8 +479,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
82 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_4.sh ver_test_5.sh \
83 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_7.sh ver_test_8.sh \
84 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.sh ver_test_13.sh \
85 -@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.sh weak_as_needed.sh \
86 -@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test.sh \
87 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.sh \
88 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr23409.sh \
89 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_as_needed.sh relro_test.sh \
90 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.sh \
91 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.sh \
92 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.sh \
93 @@ -536,6 +537,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
94 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms \
95 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_13.syms \
96 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.syms \
97 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr23409.syms \
98 @GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_as_needed.stdout \
99 @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_3.err \
100 @GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test.stdout \
101 @@ -5807,6 +5809,13 @@ ver_test_14.sh.log: ver_test_14.sh
102 --log-file $$b.log --trs-file $$b.trs \
103 $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
104 "$$tst" $(AM_TESTS_FD_REDIRECT)
105 +ver_test_pr23409.sh.log: ver_test_pr23409.sh
106 + @p='ver_test_pr23409.sh'; \
107 + b='ver_test_pr23409.sh'; \
108 + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
109 + --log-file $$b.log --trs-file $$b.trs \
110 + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
111 + "$$tst" $(AM_TESTS_FD_REDIRECT)
112 weak_as_needed.sh.log: weak_as_needed.sh
113 @p='weak_as_needed.sh'; \
114 b='weak_as_needed.sh'; \
115 @@ -8731,6 +8740,12 @@ uninstall-am:
116 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -T $< | $(TEST_CXXFILT) >$@
117 @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
118 @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
119 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr23409.syms: ver_test_pr23409_1.so
120 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) --dyn-syms -W $< >$@
121 +@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
122 +@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
123 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr23409_2.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_2.script
124 +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ ver_test_1.o --version-script $(srcdir)/ver_test_pr23409_2.script
125 @GCC_TRUE@@NATIVE_LINKER_TRUE@weak_as_needed.stdout: weak_as_needed_a.so
126 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -dW --dyn-syms $< >$@
127 @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
128 diff --git a/gold/testsuite/ver_test_pr23409.sh b/gold/testsuite/ver_test_pr23409.sh
130 index 0000000..ed1ef65
132 +++ b/gold/testsuite/ver_test_pr23409.sh
136 +# ver_test_pr23409.sh -- a test case for version scripts
138 +# Copyright (C) 2018 Free Software Foundation, Inc.
139 +# Written by Cary Coutant <ccoutant@gmail.com>.
141 +# This file is part of gold.
143 +# This program is free software; you can redistribute it and/or modify
144 +# it under the terms of the GNU General Public License as published by
145 +# the Free Software Foundation; either version 3 of the License, or
146 +# (at your option) any later version.
148 +# This program is distributed in the hope that it will be useful,
149 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
150 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151 +# GNU General Public License for more details.
153 +# You should have received a copy of the GNU General Public License
154 +# along with this program; if not, write to the Free Software
155 +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
156 +# MA 02110-1301, USA.
158 +# This test verifies that linker-generated symbols (e.g., _end)
159 +# get correct version information even in the presence of
160 +# a shared library that provides those symbols with different
165 + if ! grep -q "$2" "$1"
167 + echo "Did not find expected symbol in $1:"
170 + echo "Actual output below:"
178 + if grep -q "$2" "$1"
180 + echo "Found unexpected symbol in $1:"
183 + echo "Actual output below:"
189 +check ver_test_pr23409.syms "_end@@VER1$"
190 +check ver_test_pr23409.syms "_edata@@VER1$"
191 +check ver_test_pr23409.syms "__bss_start@@VER1$"
193 +check_missing ver_test_pr23409.syms "_end@VER"
194 +check_missing ver_test_pr23409.syms "_edata@VER"
195 +check_missing ver_test_pr23409.syms "__bss_start@VER"
198 diff --git a/gold/testsuite/ver_test_pr23409_1.script b/gold/testsuite/ver_test_pr23409_1.script
200 index 0000000..6969454
202 +++ b/gold/testsuite/ver_test_pr23409_1.script
207 diff --git a/gold/testsuite/ver_test_pr23409_2.script b/gold/testsuite/ver_test_pr23409_2.script
209 index 0000000..fa45184
211 +++ b/gold/testsuite/ver_test_pr23409_2.script