diff options
author | Cary Coutant <ccoutant@google.com> | 2014-07-08 22:34:27 -0700 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2014-07-08 22:52:37 -0700 |
commit | e051745c838bf29e564fb2665339f97c8383b9e8 (patch) | |
tree | f95cb0a6f37660cfa33bacef128b335f4dc678e3 /gold/testsuite | |
parent | ecf3e831f71257e8ff7bf794f394f23b26d75137 (diff) | |
download | gdb-e051745c838bf29e564fb2665339f97c8383b9e8.zip gdb-e051745c838bf29e564fb2665339f97c8383b9e8.tar.gz gdb-e051745c838bf29e564fb2665339f97c8383b9e8.tar.bz2 |
Fix --defsym to copy symbol attributes.
Alan Modra committed a patch to Gnu ld to fix a problem encountered on
PPC where the --defsym option wasn't copying the st_other bits to the
newly-defined symbol.
https://sourceware.org/ml/binutils/2014-07/msg00094.html
Gold has the same problem, and additionally wasn't copying the symbol type.
This patch fixes both problems, by copying the symbol type, visibility, and
the remaining st_other bits to the new symbol for --defsym=sym1=sym2
assignments.
gold/
* expression.cc (struct Expression::Expression_eval_info): Add
new fields type_pointer, vis_pointer, and nonvis_pointer.
(Expression::eval_maybe_dot): Add type_pointer, vis_pointer, and
nonvis_pointer parameters. Adjust all calls.
(Symbol_expression::value): Update type, visibility, and nonvis bits
in caller.
* script.cc (Symbol_assignment::sized_finalize): Update type,
visibility, and remaining st_other bits for new symbol.
* script.h: (Expression::eval_maybe_dot): Add type_pointer,
vis_pointer, and nonvis_pointer parameters.
* symtab.h (Symbol::set_type): New method.
* testsuite/Makefile.am (defsym_test): New test.
* testsuite/Makefile.in: Regenerate.
* testsuite/defsym_test.c: New file.
* testsuite/defsym_test.sh: New file.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 11 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 19 | ||||
-rw-r--r-- | gold/testsuite/defsym_test.c | 15 | ||||
-rwxr-xr-x | gold/testsuite/defsym_test.sh | 40 |
4 files changed, 82 insertions, 3 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 379ac8a..5e1cd0d 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -2253,6 +2253,17 @@ ehdr_start_test_5_CXXFLAGS = -DEHDR_START_USER_DEF ehdr_start_test_5_LDFLAGS = -Bgcctestdir/ ehdr_start_test_5_LDADD = +# Test that the --defsym option copies the symbol type and visibility. +check_SCRIPTS += defsym_test.sh +check_DATA += defsym_test.syms +MOSTLYCLEANFILES += defsym_test.syms +defsym_test.syms: defsym_test + $(TEST_READELF) -sW $< > $@ +defsym_test: defsym_test.o gcctestdir/ld + $(LINK) -Bgcctestdir/ -Wl,--defsym=bar=foo defsym_test.o +defsym_test.o: defsym_test.c + $(COMPILE) -c -o $@ $< + # End-to-end incremental linking tests. # Incremental linking is currently supported only on the x86_64 target. diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 04a42e8..7d0f78b 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -568,9 +568,14 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ # Test that __ehdr_start is left undefined when the text segment is not # appropriately aligned. -@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_70 = ehdr_start_test_4.sh -@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_71 = ehdr_start_test_4.syms -@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_72 = ehdr_start_test_4 + +# Test that the --defsym option copies the symbol type and visibility. +@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_70 = ehdr_start_test_4.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ defsym_test.sh +@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_71 = ehdr_start_test_4.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ defsym_test.syms +@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_72 = ehdr_start_test_4 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ defsym_test.syms @GCC_FALSE@ehdr_start_test_5_DEPENDENCIES = @NATIVE_LINKER_FALSE@ehdr_start_test_5_DEPENDENCIES = @@ -4132,6 +4137,8 @@ gdb_index_test_4.sh.log: gdb_index_test_4.sh @p='gdb_index_test_4.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) ehdr_start_test_4.sh.log: ehdr_start_test_4.sh @p='ehdr_start_test_4.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +defsym_test.sh.log: defsym_test.sh + @p='defsym_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) script_test_10.sh.log: script_test_10.sh @p='script_test_10.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) split_i386.sh.log: split_i386.sh @@ -5600,6 +5607,12 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,-Ttext=0x100100 $< @GCC_TRUE@@NATIVE_LINKER_TRUE@ehdr_start_test_4.o: ehdr_start_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -DEHDR_START_WEAK -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@defsym_test.syms: defsym_test +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -sW $< > $@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@defsym_test: defsym_test.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,--defsym=bar=foo defsym_test.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@defsym_test.o: defsym_test.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -o $@ $< # End-to-end incremental linking tests. # Incremental linking is currently supported only on the x86_64 target. diff --git a/gold/testsuite/defsym_test.c b/gold/testsuite/defsym_test.c new file mode 100644 index 0000000..0bf68b2 --- /dev/null +++ b/gold/testsuite/defsym_test.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +void foo (void) __attribute__ ((noinline, visibility ("hidden"))); + +void foo (void) { + printf("foo called.\n"); +} + +void bar(void); + +int main(void) { + foo(); + bar(); + return 0; +} diff --git a/gold/testsuite/defsym_test.sh b/gold/testsuite/defsym_test.sh new file mode 100755 index 0000000..e83fa9f --- /dev/null +++ b/gold/testsuite/defsym_test.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# defsym_test.sh -- test that --defsym copies type and visiblity. + +# Copyright (C) 2014 Free Software Foundation, Inc. +# Written by Cary Coutant <ccoutant@google.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 defsym_test.syms "FUNC *GLOBAL *HIDDEN *[0-9]* *bar" + +exit 0 |