diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2024-05-31 21:30:34 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2024-06-08 23:54:39 -0700 |
commit | 89d801850ac03d0531f7eef3d6978bec17a30a2d (patch) | |
tree | 7c8719feee02ca0df80571a765d46ce05394bd71 /gold/testsuite | |
parent | 2b05f934486de42f8200bf11cece21ae3bc284e6 (diff) | |
download | binutils-89d801850ac03d0531f7eef3d6978bec17a30a2d.zip binutils-89d801850ac03d0531f7eef3d6978bec17a30a2d.tar.gz binutils-89d801850ac03d0531f7eef3d6978bec17a30a2d.tar.bz2 |
gold: Properly remove the versioned symbol
When the versioned symbol foo is removed from the shared library, the
".symver foo,foo@VER" directive provides binary compatibility for foo@VER.
In this case, the unversioned symbol foo should be hidden and shouldn't
generate a multiple definition error.
PR gold/31830
* resolve.cc (Symbol_table::resolve): Move symbol version handling
to ...
* symtab.cc (Symbol_table::add_from_object): Here. If the hidden
version from .symver is the same as the default version from the
unversioned symbol, don't make the unversioned symbol the default
versioned
symbol.
* testsuite/Makefile.am (check_SCRIPTS): Add ver_test_pr31830.sh.
(check_DATA): ver_test_pr31830_a.syms and ver_test_pr31830_b.syms.
(ver_test_pr31830_a.syms): New.
(ver_test_pr31830_b.syms): Likewise.
(ver_test_pr31830_a.so): Likewise.
(ver_test_pr31830_b.so): Likewise.
* testsuite/Makefile.in: Regenerated.
* testsuite/ver_test_pr31830.script: New file.
* testsuite/ver_test_pr31830.sh: Likewise.
* testsuite/ver_test_pr31830_a.c: Likewise.
* testsuite/ver_test_pr31830_b.c: Likewise.
* testsuite/ver_test_pr31830_lto.c: Likewise.
* testsuite/ver_test_pr31830_lto.sh: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 22 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 36 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr31830.script | 6 | ||||
-rwxr-xr-x | gold/testsuite/ver_test_pr31830.sh | 61 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr31830_a.c | 2 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr31830_b.c | 3 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr31830_lto.c | 5 | ||||
-rwxr-xr-x | gold/testsuite/ver_test_pr31830_lto.sh | 61 |
8 files changed, 196 insertions, 0 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 0685e91..2f1348f 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1963,6 +1963,28 @@ ver_test_pr23409_1.so: gcctestdir/ld ver_test_1.o $(srcdir)/ver_test_pr23409_1.s 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 += ver_test_pr31830.sh +check_DATA += ver_test_pr31830_a.syms ver_test_pr31830_b.syms +ver_test_pr31830_a.syms: ver_test_pr31830_a.so + $(TEST_READELF) --dyn-syms -W $< >$@ +ver_test_pr31830_b.syms: ver_test_pr31830_b.so + $(TEST_READELF) --dyn-syms -W $< >$@ +ver_test_pr31830_a.so: gcctestdir/ld ver_test_pr31830_a.o ver_test_pr31830_b.o $(srcdir)/ver_test_pr31830.script + gcctestdir/ld -shared -o $@ ver_test_pr31830_a.o ver_test_pr31830_b.o --version-script $(srcdir)/ver_test_pr31830.script +ver_test_pr31830_b.so: gcctestdir/ld ver_test_pr31830_a.o ver_test_pr31830_b.o $(srcdir)/ver_test_pr31830.script + gcctestdir/ld -shared -o $@ ver_test_pr31830_b.o ver_test_pr31830_a.o --version-script $(srcdir)/ver_test_pr31830.script + +check_SCRIPTS += ver_test_pr31830_lto.sh +check_DATA += ver_test_pr31830_lto_a.syms ver_test_pr31830_lto_b.syms +ver_test_pr31830_lto_a.syms: ver_test_pr31830_lto_a.so + $(TEST_READELF) --dyn-syms -W $< >$@ +ver_test_pr31830_lto_a.so: gcctestdir/ld $(srcdir)/ver_test_pr31830_lto.c $(srcdir)/ver_test_pr31830.script + $(LINK) -Bgcctestdir/ -shared -o $@ -O2 -fPIC -flto-partition=max $(srcdir)/ver_test_pr31830_lto.c -Wl,--version-script,$(srcdir)/ver_test_pr31830.script +ver_test_pr31830_lto_b.syms: ver_test_pr31830_lto_b.so + $(TEST_READELF) --dyn-syms -W $< >$@ +ver_test_pr31830_lto_b.so: gcctestdir/ld $(srcdir)/ver_test_pr31830_lto.c $(srcdir)/ver_test_pr31830.script + $(LINK) -Bgcctestdir/ -shared -o $@ -O2 -fPIC -flto-partition=max -flto=2 $(srcdir)/ver_test_pr31830_lto.c -Wl,--version-script,$(srcdir)/ver_test_pr31830.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/Makefile.in b/gold/testsuite/Makefile.in index 33d5cd7..9cf21df 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -469,6 +469,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.sh ver_test_13.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_14.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr23409.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr31830.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr31830_lto.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 \ @@ -526,6 +528,10 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @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@ ver_test_pr31830_a.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr31830_b.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr31830_lto_a.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_pr31830_lto_b.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 \ @@ -5900,6 +5906,20 @@ ver_test_pr23409.sh.log: ver_test_pr23409.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_pr31830.sh.log: ver_test_pr31830.sh + @p='ver_test_pr31830.sh'; \ + b='ver_test_pr31830.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) +ver_test_pr31830_lto.sh.log: ver_test_pr31830_lto.sh + @p='ver_test_pr31830_lto.sh'; \ + b='ver_test_pr31830_lto.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'; \ @@ -8900,6 +8920,22 @@ uninstall-am: @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@ver_test_pr31830_a.syms: ver_test_pr31830_a.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) --dyn-syms -W $< >$@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_b.syms: ver_test_pr31830_b.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) --dyn-syms -W $< >$@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_a.so: gcctestdir/ld ver_test_pr31830_a.o ver_test_pr31830_b.o $(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ ver_test_pr31830_a.o ver_test_pr31830_b.o --version-script $(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_b.so: gcctestdir/ld ver_test_pr31830_a.o ver_test_pr31830_b.o $(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ ver_test_pr31830_b.o ver_test_pr31830_a.o --version-script $(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_lto_a.syms: ver_test_pr31830_lto_a.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) --dyn-syms -W $< >$@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_lto_a.so: gcctestdir/ld $(srcdir)/ver_test_pr31830_lto.c $(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -shared -o $@ -O2 -fPIC -flto-partition=max $(srcdir)/ver_test_pr31830_lto.c -Wl,--version-script,$(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_lto_b.syms: ver_test_pr31830_lto_b.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) --dyn-syms -W $< >$@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_pr31830_lto_b.so: gcctestdir/ld $(srcdir)/ver_test_pr31830_lto.c $(srcdir)/ver_test_pr31830.script +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -shared -o $@ -O2 -fPIC -flto-partition=max -flto=2 $(srcdir)/ver_test_pr31830_lto.c -Wl,--version-script,$(srcdir)/ver_test_pr31830.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 diff --git a/gold/testsuite/ver_test_pr31830.script b/gold/testsuite/ver_test_pr31830.script new file mode 100644 index 0000000..0dcc47f --- /dev/null +++ b/gold/testsuite/ver_test_pr31830.script @@ -0,0 +1,6 @@ +GLIBC_2.2.5 { + global: + foo; + local: + *; +}; diff --git a/gold/testsuite/ver_test_pr31830.sh b/gold/testsuite/ver_test_pr31830.sh new file mode 100755 index 0000000..2a3c034 --- /dev/null +++ b/gold/testsuite/ver_test_pr31830.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# ver_test_pr31830.sh -- a test case for version scripts + +# Copyright (C) 2024 Free Software Foundation, Inc. + +# 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_pr31830_a.syms "foo@GLIBC_2.2.5$" +check ver_test_pr31830_b.syms "foo@GLIBC_2.2.5$" + +check_missing ver_test_pr31830_a.syms "foo@@GLIBC_2.2.5$" +check_missing ver_test_pr31830_b.syms "foo@@GLIBC_2.2.5$" + +exit 0 diff --git a/gold/testsuite/ver_test_pr31830_a.c b/gold/testsuite/ver_test_pr31830_a.c new file mode 100644 index 0000000..bb57059 --- /dev/null +++ b/gold/testsuite/ver_test_pr31830_a.c @@ -0,0 +1,2 @@ +extern void foo(void); +void foo(void) {} diff --git a/gold/testsuite/ver_test_pr31830_b.c b/gold/testsuite/ver_test_pr31830_b.c new file mode 100644 index 0000000..aba07cc --- /dev/null +++ b/gold/testsuite/ver_test_pr31830_b.c @@ -0,0 +1,3 @@ +extern void __collector_foo_2_2(void); +__attribute__((__symver__("foo@GLIBC_2.2.5"))) +void __collector_foo_2_2(void) {} diff --git a/gold/testsuite/ver_test_pr31830_lto.c b/gold/testsuite/ver_test_pr31830_lto.c new file mode 100644 index 0000000..999dd63 --- /dev/null +++ b/gold/testsuite/ver_test_pr31830_lto.c @@ -0,0 +1,5 @@ +extern __inline __attribute__((__gnu_inline__)) void foo(void) {} +extern void __collector_foo_2_2(void); +__attribute__((__symver__("foo@GLIBC_2.2.5"))) +void __collector_foo_2_2(void) {} +void foo(void) {} diff --git a/gold/testsuite/ver_test_pr31830_lto.sh b/gold/testsuite/ver_test_pr31830_lto.sh new file mode 100755 index 0000000..4b939a1 --- /dev/null +++ b/gold/testsuite/ver_test_pr31830_lto.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# ver_test_pr31830_lto.sh -- a test case for version scripts with LTO + +# Copyright (C) 2024 Free Software Foundation, Inc. + +# 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_pr31830_lto_a.syms "foo@GLIBC_2.2.5$" +check ver_test_pr31830_lto_b.syms "foo@GLIBC_2.2.5$" + +check_missing ver_test_pr31830_lto_a.syms "foo@@GLIBC_2.2.5$" +check_missing ver_test_pr31830_lto_b.syms "foo@@GLIBC_2.2.5$" + +exit 0 |