diff options
author | Cary Coutant <ccoutant@gmail.com> | 2018-04-23 09:27:35 -0700 |
---|---|---|
committer | Cary Coutant <ccoutant@gmail.com> | 2018-04-24 13:51:24 -0700 |
commit | 890d155592e66dc01fc4a9affba806c4e9fc36ba (patch) | |
tree | 0ccfa6f963c937ec8f5648ecb9d401ae676c0778 /gold/testsuite | |
parent | f67c0c9171508672167b6868c67211571421a1c6 (diff) | |
download | gdb-890d155592e66dc01fc4a9affba806c4e9fc36ba.zip gdb-890d155592e66dc01fc4a9affba806c4e9fc36ba.tar.gz gdb-890d155592e66dc01fc4a9affba806c4e9fc36ba.tar.bz2 |
Fix internal error caused by conflicting default version definitions.
gold/
PR gold/16504
* dynobj.cc (Versions::symbol_section_contents): Don't set
VERSYM_HIDDEN flag for undefined symbols.
* symtab.cc (Symbol_table::add_from_object): Don't override default
version definition with a different default version.
* symtab.h (Symbol::from_dyn): New method.
* testsuite/plugin_test.c (struct sym_info): Add ver field.
(claim_file_hook): Pass symbol version to plugin API.
(parse_readelf_line): Parse symbol version.
* testsuite/Makefile.am (ver_test_pr16504): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/ver_test_pr16504.sh: New test script.
* testsuite/ver_test_pr16504_a.c: New source file.
* testsuite/ver_test_pr16504_a.script: New version script.
* testsuite/ver_test_pr16504_b.c: New source file.
* testsuite/ver_test_pr16504_b.script: New version script.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 17 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 22 | ||||
-rw-r--r-- | gold/testsuite/plugin_test.c | 39 | ||||
-rwxr-xr-x | gold/testsuite/ver_test_pr16504.sh | 41 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr16504_a.c | 5 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr16504_a.script | 4 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr16504_b.c | 10 | ||||
-rw-r--r-- | gold/testsuite/ver_test_pr16504_b.script | 4 |
8 files changed, 132 insertions, 10 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 7140df6..c926f8b 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -2516,6 +2516,23 @@ plugin_pr22868_b_ir.o: plugin_pr22868_b.c plugin_pr22868_b.o: plugin_pr22868_b.c $(COMPILE) -c -fpic -o $@ $< +check_SCRIPTS += ver_test_pr16504.sh +check_DATA += ver_test_pr16504.stdout +ver_test_pr16504.stdout: ver_test_pr16504.so + $(TEST_READELF) -W --dyn-syms $< >$@ 2>/dev/null +ver_test_pr16504.so: ver_test_pr16504_a.so ver_test_pr16504_b.o.syms ver_test_pr16504_b.script gcctestdir/ld + gcctestdir/ld -shared -o $@ --plugin ./plugin_test.so --version-script $(srcdir)/ver_test_pr16504_b.script ver_test_pr16504_b.o.syms ver_test_pr16504_a.so +ver_test_pr16504_a.so: ver_test_pr16504_a.o ver_test_pr16504_a.script gcctestdir/ld + gcctestdir/ld -shared -o $@ --version-script $(srcdir)/ver_test_pr16504_a.script ver_test_pr16504_a.o +ver_test_pr16504_a.o: ver_test_pr16504_a.c + $(COMPILE) -c -fpic -o $@ $< +# Filter out the UNDEFs from the symbols file to simulate GCC behavior, +# which does not pass the UNDEF from a .symver directive. +ver_test_pr16504_b.o.syms: ver_test_pr16504_b.o + $(TEST_READELF) -sW $< 2>/dev/null | grep -v "UND" >$@ +ver_test_pr16504_b.o: ver_test_pr16504_b.c + $(COMPILE) -c -fpic -o $@ $< + endif PLUGINS check_PROGRAMS += exclude_libs_test diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 48e5b9e..1e60807 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -612,7 +612,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_pr22868.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_53 = plugin_final_layout.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_layout_with_alignment.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_pr22868.sh +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_pr22868.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ ver_test_pr16504.sh # Uses the plugin_final_layout.sh script above to avoid duplication @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_54 = plugin_final_layout.stdout \ @@ -620,7 +621,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_layout_new_file.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_layout_new_file_readelf.stdout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_layout_with_alignment.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_pr22868.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_pr22868.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ ver_test_pr16504.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_55 = exclude_libs_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ local_labels_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test @@ -5368,6 +5370,8 @@ plugin_layout_with_alignment.sh.log: plugin_layout_with_alignment.sh @p='plugin_layout_with_alignment.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_pr22868.sh.log: plugin_pr22868.sh @p='plugin_pr22868.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +ver_test_pr16504.sh.log: ver_test_pr16504.sh + @p='ver_test_pr16504.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) exclude_libs_test.sh.log: exclude_libs_test.sh @p='exclude_libs_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) discard_locals_test.sh.log: discard_locals_test.sh @@ -7220,6 +7224,20 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(COMPILE) -c -DIR -fpic -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_pr22868_b.o: plugin_pr22868_b.c @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(COMPILE) -c -fpic -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ver_test_pr16504.stdout: ver_test_pr16504.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_READELF) -W --dyn-syms $< >$@ 2>/dev/null +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ver_test_pr16504.so: ver_test_pr16504_a.so ver_test_pr16504_b.o.syms ver_test_pr16504_b.script gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ gcctestdir/ld -shared -o $@ --plugin ./plugin_test.so --version-script $(srcdir)/ver_test_pr16504_b.script ver_test_pr16504_b.o.syms ver_test_pr16504_a.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ver_test_pr16504_a.so: ver_test_pr16504_a.o ver_test_pr16504_a.script gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ gcctestdir/ld -shared -o $@ --version-script $(srcdir)/ver_test_pr16504_a.script ver_test_pr16504_a.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ver_test_pr16504_a.o: ver_test_pr16504_a.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(COMPILE) -c -fpic -o $@ $< +# Filter out the UNDEFs from the symbols file to simulate GCC behavior, +# which does not pass the UNDEF from a .symver directive. +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ver_test_pr16504_b.o.syms: ver_test_pr16504_b.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_READELF) -sW $< 2>/dev/null | grep -v "UND" >$@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ver_test_pr16504_b.o: ver_test_pr16504_b.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(COMPILE) -c -fpic -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test.syms: exclude_libs_test @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -sW $< >$@ 2>/dev/null @GCC_TRUE@@NATIVE_LINKER_TRUE@libexclude_libs_test_1.a: exclude_libs_test_1.o diff --git a/gold/testsuite/plugin_test.c b/gold/testsuite/plugin_test.c index e80f926..a21abca 100644 --- a/gold/testsuite/plugin_test.c +++ b/gold/testsuite/plugin_test.c @@ -46,6 +46,7 @@ struct sym_info char* vis; char* sect; char* name; + char* ver; }; static struct claimed_file* first_claimed_file = NULL; @@ -397,7 +398,14 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed) syms[nsyms].name = malloc(len + 1); strncpy(syms[nsyms].name, info.name, len + 1); } - syms[nsyms].version = NULL; + if (info.ver == NULL) + syms[nsyms].version = NULL; + else + { + len = strlen(info.ver); + syms[nsyms].version = malloc(len + 1); + strncpy(syms[nsyms].version, info.ver, len + 1); + } syms[nsyms].def = def; syms[nsyms].visibility = vis; syms[nsyms].size = info.size; @@ -676,11 +684,26 @@ parse_readelf_line(char* p, struct sym_info* info) p += strspn(p, " "); /* Name field. */ - /* FIXME: Look for version. */ - len = strlen(p); - if (len == 0) - p = NULL; - else if (p[len-1] == '\n') - p[--len] = '\0'; - info->name = p; + len = strcspn(p, "@\n"); + if (len > 0 && p[len] == '@') + { + /* Get the symbol version. */ + char* vp = p + len; + int vlen; + + vp += strspn(vp, "@"); + vlen = strcspn(vp, "\n"); + vp[vlen] = '\0'; + if (vlen > 0) + info->ver = vp; + else + info->ver = NULL; + } + else + info->ver = NULL; + p[len] = '\0'; + if (len > 0) + info->name = p; + else + info->name = NULL; } diff --git a/gold/testsuite/ver_test_pr16504.sh b/gold/testsuite/ver_test_pr16504.sh new file mode 100755 index 0000000..f4e3b8b --- /dev/null +++ b/gold/testsuite/ver_test_pr16504.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# ver_test_pr16504.sh -- test that undef gets correct version with LTO. + +# 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_pr16504.stdout " FUNC .* UND *foo@VER2" +check ver_test_pr16504.stdout " IFUNC .* foo@@VER1" + +exit 0 diff --git a/gold/testsuite/ver_test_pr16504_a.c b/gold/testsuite/ver_test_pr16504_a.c new file mode 100644 index 0000000..7628022 --- /dev/null +++ b/gold/testsuite/ver_test_pr16504_a.c @@ -0,0 +1,5 @@ +const char* foo(void); + +const char* +foo(void) +{ return "x"; } diff --git a/gold/testsuite/ver_test_pr16504_a.script b/gold/testsuite/ver_test_pr16504_a.script new file mode 100644 index 0000000..86bb0a0 --- /dev/null +++ b/gold/testsuite/ver_test_pr16504_a.script @@ -0,0 +1,4 @@ +VER2 { +global: + foo; +}; diff --git a/gold/testsuite/ver_test_pr16504_b.c b/gold/testsuite/ver_test_pr16504_b.c new file mode 100644 index 0000000..e6d82b6 --- /dev/null +++ b/gold/testsuite/ver_test_pr16504_b.c @@ -0,0 +1,10 @@ +void +new_foo(void); +__asm__(".symver new_foo,foo@VER2"); + +static void (*resolve_foo(void)) (void) +{ + return new_foo; +} + +void foo(void) __attribute__((ifunc("resolve_foo"))); diff --git a/gold/testsuite/ver_test_pr16504_b.script b/gold/testsuite/ver_test_pr16504_b.script new file mode 100644 index 0000000..94b373d --- /dev/null +++ b/gold/testsuite/ver_test_pr16504_b.script @@ -0,0 +1,4 @@ +VER1 { +global: + foo; +}; |