2010-08-12 Cary Coutant <ccoutant@google.com>

Doug Kwan  <dougkwan@google.com>

	* 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.
This commit is contained in:
Doug Kwan 2010-08-13 00:18:19 +00:00
parent e06bb621df
commit 74f6756095
8 changed files with 181 additions and 3 deletions

View File

@ -1,3 +1,17 @@
2010-08-12 Cary Coutant <ccoutant@google.com>
Doug Kwan <dougkwan@google.com>
* 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 <ccoutant@google.com>
* testsuite/incremental_test.sh: Rewrite.

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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 <dougkwan@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.
# 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

View File

@ -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 <dougkwan@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.
// 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;
}

View File

@ -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 <dougkwan@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.
// 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)
{
}