From 74f67560959c1ba65f6be4571d846b759522fcd5 Mon Sep 17 00:00:00 2001 From: Doug Kwan Date: Fri, 13 Aug 2010 00:18:19 +0000 Subject: [PATCH] 2010-08-12 Cary Coutant Doug Kwan * resolve.cc (Symbol_table::should_override): When a weak dynamic defintion overrides non-weak undef, remember that the original undef is not weak. * symtab.cc (Symbol_table::sized_write_global): For undef without an original weak binding, set binding to global in output. * testsuite/Makefile.am: Add new test strong_ref_weak_def. * testsuite/Makefile.in: Regenerate. * testsuite/strong_ref_weak_def.sh: New file. * testsuite/strong_ref_weak_def_1.c: Ditto. * testsuite/strong_ref_weak_def_2.c: Ditto. --- gold/ChangeLog | 14 +++++++++ gold/resolve.cc | 5 +++ gold/symtab.cc | 2 ++ gold/testsuite/Makefile.am | 18 +++++++++++ gold/testsuite/Makefile.in | 27 +++++++++++++++-- gold/testsuite/strong_ref_weak_def.sh | 42 ++++++++++++++++++++++++++ gold/testsuite/strong_ref_weak_def_1.c | 39 ++++++++++++++++++++++++ gold/testsuite/strong_ref_weak_def_2.c | 37 +++++++++++++++++++++++ 8 files changed, 181 insertions(+), 3 deletions(-) create mode 100755 gold/testsuite/strong_ref_weak_def.sh create mode 100644 gold/testsuite/strong_ref_weak_def_1.c create mode 100644 gold/testsuite/strong_ref_weak_def_2.c diff --git a/gold/ChangeLog b/gold/ChangeLog index 72625019cb..ddbeed65ca 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,17 @@ +2010-08-12 Cary Coutant + Doug Kwan + + * resolve.cc (Symbol_table::should_override): When a weak dynamic + defintion overrides non-weak undef, remember that the original undef + is not weak. + * symtab.cc (Symbol_table::sized_write_global): For undef without + an original weak binding, set binding to global in output. + * testsuite/Makefile.am: Add new test strong_ref_weak_def. + * testsuite/Makefile.in: Regenerate. + * testsuite/strong_ref_weak_def.sh: New file. + * testsuite/strong_ref_weak_def_1.c: Ditto. + * testsuite/strong_ref_weak_def_2.c: Ditto. + 2010-08-12 Cary Coutant * testsuite/incremental_test.sh: Rewrite. diff --git a/gold/resolve.cc b/gold/resolve.cc index af3d48921c..29d9d79c7a 100644 --- a/gold/resolve.cc +++ b/gold/resolve.cc @@ -576,6 +576,11 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits, return false; case UNDEF * 16 + DYN_WEAK_DEF: + // When overriding an undef by a dynamic weak definition, + // we need to remember that the original undef was not weak. + *adjust_dyndef = true; + return true; + case DYN_UNDEF * 16 + DYN_WEAK_DEF: case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF: // Use a weak dynamic definition if we have a reference. diff --git a/gold/symtab.cc b/gold/symtab.cc index f46d8deb75..5a59f4c843 100644 --- a/gold/symtab.cc +++ b/gold/symtab.cc @@ -2756,6 +2756,8 @@ Symbol_table::sized_write_globals(const Stringpool* sympool, shndx = elfcpp::SHN_UNDEF; if (sym->is_undef_binding_weak()) binding = elfcpp::STB_WEAK; + else + binding = elfcpp::STB_GLOBAL; } else if (symobj->pluginobj() != NULL) shndx = elfcpp::SHN_UNDEF; diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index c1eddcdb14..ab3ca5508d 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1530,6 +1530,24 @@ no_version_test.o: no_version_test.c no_version_test.stdout: libno_version_test.so $(TEST_OBJDUMP) -h $< > $@ +# Test that strong reference to a weak symbol in a DSO remains strong. +check_SCRIPTS += strong_ref_weak_def.sh +check_DATA += strong_ref_weak_def.stdout +MOSTLYCLEANFILES += strong_ref_weak_def_1.so strong_ref_weak_def_2.so \ + strong_ref_weak_def.stdout +strong_ref_weak_def_2.o: strong_ref_weak_def_2.c + $(COMPILE) -o $@ -c -fPIC $< +strong_ref_weak_def_2.so: strong_ref_weak_def_2.o gcctestdir/ld + gcctestdir/ld -shared -o $@ strong_ref_weak_def_2.o +strong_ref_weak_def_1.o: strong_ref_weak_def_1.c + $(COMPILE) -o $@ -c -fPIC $< +strong_ref_weak_def_1.so: strong_ref_weak_def_1.o strong_ref_weak_def_2.so \ + gcctestdir/ld + gcctestdir/ld -shared -o $@ strong_ref_weak_def_1.o \ + strong_ref_weak_def_2.so +strong_ref_weak_def.stdout: strong_ref_weak_def_1.so + $(TEST_READELF) -sWD $< > $@ + endif GCC endif NATIVE_LINKER diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index f2552e31c3..afd0430cab 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -307,18 +307,22 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ # Test that no .gnu.version sections are created when # symbol versioning is not used. + +# Test that strong reference to a weak symbol in a DSO remains strong. @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_27 = exclude_libs_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ hidden_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ retain_symbols_file_test.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.sh +@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def.sh @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_28 = exclude_libs_test.syms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.syms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_relocatable_test1.syms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_relocatable_test2.syms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ hidden_test.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ retain_symbols_file_test.stdout \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_29 = exclude_libs_test.syms \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ libexclude_libs_test_1.a \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ libexclude_libs_test_2.a \ @@ -336,7 +340,10 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ searched_file_test_lib.o \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/searched_file_test_lib.a \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ libno_version_test.so \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.stdout +@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.stdout \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def_1.so \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def_2.so \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def.stdout @GCC_TRUE@@MCMODEL_MEDIUM_TRUE@@NATIVE_LINKER_TRUE@am__append_30 = large @GCC_FALSE@large_DEPENDENCIES = @MCMODEL_MEDIUM_FALSE@large_DEPENDENCIES = @@ -2669,6 +2676,8 @@ retain_symbols_file_test.sh.log: retain_symbols_file_test.sh @p='retain_symbols_file_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) no_version_test.sh.log: no_version_test.sh @p='no_version_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +strong_ref_weak_def.sh.log: strong_ref_weak_def.sh + @p='strong_ref_weak_def.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) split_i386.sh.log: split_i386.sh @p='split_i386.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) split_x86_64.sh.log: split_x86_64.sh @@ -3674,6 +3683,18 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -o $@ -c -fPIC $< @GCC_TRUE@@NATIVE_LINKER_TRUE@no_version_test.stdout: libno_version_test.so @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -h $< > $@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@strong_ref_weak_def_2.o: strong_ref_weak_def_2.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -o $@ -c -fPIC $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@strong_ref_weak_def_2.so: strong_ref_weak_def_2.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ strong_ref_weak_def_2.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@strong_ref_weak_def_1.o: strong_ref_weak_def_1.c +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -o $@ -c -fPIC $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@strong_ref_weak_def_1.so: strong_ref_weak_def_1.o strong_ref_weak_def_2.so \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ strong_ref_weak_def_1.o \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def_2.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@strong_ref_weak_def.stdout: strong_ref_weak_def_1.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -sWD $< > $@ @DEFAULT_TARGET_I386_TRUE@split_i386_1.o: split_i386_1.s @DEFAULT_TARGET_I386_TRUE@ $(TEST_AS) -o $@ $< @DEFAULT_TARGET_I386_TRUE@split_i386_2.o: split_i386_2.s diff --git a/gold/testsuite/strong_ref_weak_def.sh b/gold/testsuite/strong_ref_weak_def.sh new file mode 100755 index 0000000000..17afc5bd96 --- /dev/null +++ b/gold/testsuite/strong_ref_weak_def.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# strong_ref_weak_def.sh -- test non-weak reference to a weak symbol defined +# in a DSO. + +# Copyright 2010 Free Software Foundation, Inc. +# Written by Doug Kwan . + +# 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 checks that the reference to 'weak_def' have GLOBAL binding. + +check() +{ + file=$1 + pattern=$2 + found=`grep "$pattern" $file` + if test -z "$found"; then + echo "pattern \"$pattern\" not found in file $file." + echo $found + exit 1 + fi +} + +check strong_ref_weak_def.stdout ".* FUNC.* GLOBAL.* UND.* weak_def" + +exit 0 diff --git a/gold/testsuite/strong_ref_weak_def_1.c b/gold/testsuite/strong_ref_weak_def_1.c new file mode 100644 index 0000000000..bc00e770a9 --- /dev/null +++ b/gold/testsuite/strong_ref_weak_def_1.c @@ -0,0 +1,39 @@ +// strong_ref_weak_def_1.c -- test a strong reference to a weak definition +// in a DSO. + +// Copyright 2010 Free Software Foundation, Inc. +// Written by Doug Kwan . + +// 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. + +// We test that we correctly deal with a non-weak reference to +// a weak symbol in an DSO. We need to make sure that reference +// is not turned into a weak one. + +// This source is used to build an executable that references a weak +// symbol in a DSO. + +// Strong reference to a weak symbol. +extern void weak_def (void); + +int +main (void) +{ + weak_def (); + return 0; +} diff --git a/gold/testsuite/strong_ref_weak_def_2.c b/gold/testsuite/strong_ref_weak_def_2.c new file mode 100644 index 0000000000..4801f6d2eb --- /dev/null +++ b/gold/testsuite/strong_ref_weak_def_2.c @@ -0,0 +1,37 @@ +// strong_ref_weak_def_2.c -- test a strong reference to a weak definition +// in a DSO. + +// Copyright 2010 Free Software Foundation, Inc. +// Written by Doug Kwan . + +// 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. + +// We test that we correctly deal with a non-weak reference to +// a weak symbol in an DSO. We need to make sure that reference +// is not turned into a weak one. + +// This source is used to build a shared library that defines a +// weak symbol. + +void weak_def (void); + +void +__attribute__((weak)) +weak_def (void) +{ +} -- 2.34.1