2010-08-12 Cary Coutant <ccoutant@google.com>
authorDoug Kwan <dougkwan@google.com>
Fri, 13 Aug 2010 00:18:19 +0000 (00:18 +0000)
committerDoug Kwan <dougkwan@google.com>
Fri, 13 Aug 2010 00:18:19 +0000 (00:18 +0000)
    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.

gold/ChangeLog
gold/resolve.cc
gold/symtab.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/strong_ref_weak_def.sh [new file with mode: 0755]
gold/testsuite/strong_ref_weak_def_1.c [new file with mode: 0644]
gold/testsuite/strong_ref_weak_def_2.c [new file with mode: 0644]

index 72625019cbf5c3a341dfd5fcb8ac977f1ce13e15..ddbeed65ca01d4b5c8c45b361bc28cfa65c46242 100644 (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.
index af3d48921c6960f457857e249080f10219a3d58f..29d9d79c7a46c682215896c7b4d315e855e43edb 100644 (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.
index f46d8deb75a464a56487f3710d411053eb97d146..5a59f4c84369e34a64f931ee57f96e740fd7962c 100644 (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;
index c1eddcdb14433595c9cb3d2484ffb136c641ace7..ab3ca5508d3f86a5cdec3a5c14148fe546ddee2a 100644 (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
 
index f2552e31c32613a3e6a23accc991b72e9c85fc1e..afd0430cabf1d232a27f737774ef5d4ca085f2e2 100644 (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
diff --git a/gold/testsuite/strong_ref_weak_def.sh b/gold/testsuite/strong_ref_weak_def.sh
new file mode 100755 (executable)
index 0000000..17afc5b
--- /dev/null
@@ -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
diff --git a/gold/testsuite/strong_ref_weak_def_1.c b/gold/testsuite/strong_ref_weak_def_1.c
new file mode 100644 (file)
index 0000000..bc00e77
--- /dev/null
@@ -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;
+}
diff --git a/gold/testsuite/strong_ref_weak_def_2.c b/gold/testsuite/strong_ref_weak_def_2.c
new file mode 100644 (file)
index 0000000..4801f6d
--- /dev/null
@@ -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)
+{
+}
This page took 0.052086 seconds and 4 git commands to generate.