aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gold/ChangeLog16
-rw-r--r--gold/common.cc22
-rw-r--r--gold/symtab.h4
-rw-r--r--gold/testsuite/Makefile.am14
-rw-r--r--gold/testsuite/Makefile.in32
-rw-r--r--gold/testsuite/common_test_2.c33
-rw-r--r--gold/testsuite/common_test_3.c32
7 files changed, 146 insertions, 7 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 508968d..027940e 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,6 +1,22 @@
2009-12-30 Ian Lance Taylor <iant@google.com>
PR 10979
+ * common.cc (Sort_commons::operator()): Stabilize sort when both
+ entries are NULL.
+ (Symbol_table::do_allocate_commons_list): When allocating common
+ symbols, skip a symbol which is no longer common.
+ * symtab.h (Symbol::is_common): Test whether the symbol comes from
+ an object before checking its type.
+ * testsuite/common_test_2.c: New file.
+ * testsuite/common_test_3.c: New file.
+ * testsuite/Makefile.am (check_PROGRAMS): Add common_test_2.
+ (common_test_2_SOURCES, common_test_2_DEPENDENCIES): Define.
+ (common_test_2_LDFLAGS, common_test_2_LDADD): Define.
+ (common_test_2_pic.o, common_test_2.so): New targets.
+ (common_test_3_pic.o, common_test_3.so): New targets.
+ * testsuite/Makefile.in: Rebuild.
+
+ PR 10979
* script.cc (read_input_script): If we see a new SECTIONS clause,
and we have added an input section, give an error.
* layout.h (class Layout): Add have_added_input_section function.
diff --git a/gold/common.cc b/gold/common.cc
index c4ff047..8859338 100644
--- a/gold/common.cc
+++ b/gold/common.cc
@@ -91,7 +91,16 @@ bool
Sort_commons<size>::operator()(const Symbol* pa, const Symbol* pb) const
{
if (pa == NULL)
- return false;
+ {
+ if (pb == NULL)
+ {
+ // Stabilize sort. The order really doesn't matter, because
+ // these entries will be discarded, but we want to return
+ // the same result every time we compare pa and pb.
+ return pa < pb;
+ }
+ return false;
+ }
if (pb == NULL)
return true;
@@ -312,6 +321,17 @@ Symbol_table::do_allocate_commons_list(
Symbol* sym = *p;
if (sym == NULL)
break;
+
+ // Because we followed forwarding symbols above, but we didn't
+ // do it reliably before adding symbols to the list, it is
+ // possible for us to have the same symbol on the list twice.
+ // This can happen in the horrible case where a program defines
+ // a common symbol with the same name as a versioned libc
+ // symbol. That will show up here as a symbol which has already
+ // been allocated and is therefore no longer a common symbol.
+ if (!sym->is_common())
+ continue;
+
Sized_symbol<size>* ssym = this->get_sized_symbol<size>(sym);
// Record the symbol in the map file now, before we change its
diff --git a/gold/symtab.h b/gold/symtab.h
index 8ee2091..f79fc8d 100644
--- a/gold/symtab.h
+++ b/gold/symtab.h
@@ -478,10 +478,10 @@ class Symbol
bool
is_common() const
{
- if (this->type_ == elfcpp::STT_COMMON)
- return true;
if (this->source_ != FROM_OBJECT)
return false;
+ if (this->type_ == elfcpp::STT_COMMON)
+ return true;
bool is_ordinary;
unsigned int shndx = this->shndx(&is_ordinary);
return !is_ordinary && Symbol::is_common_shndx(shndx);
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 61934aa..7b5532e 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -407,6 +407,20 @@ common_test_1_DEPENDENCIES = gcctestdir/ld
common_test_1_LDFLAGS = -Bgcctestdir/
common_test_1_LDADD =
+check_PROGRAMS += common_test_2
+common_test_2_SOURCES = common_test_1.c
+common_test_2_DEPENDENCIES = common_test_2.so common_test_3.so gcctestdir/ld
+common_test_2_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+common_test_2_LDADD = common_test_2.so common_test_3.so
+common_test_2_pic.o: common_test_2.c
+ $(COMPILE) -c -fpic -o $@ $<
+common_test_2.so: common_test_2_pic.o common_test_3.so gcctestdir/ld
+ $(LINK) -Bgcctestdir/ -shared common_test_2_pic.o common_test_3.so
+common_test_3_pic.o: common_test_3.c
+ $(COMPILE) -c -fpic -o $@ $<
+common_test_3.so: common_test_3_pic.o ver_test_2.script gcctestdir/ld
+ $(LINK) -Bgcctestdir/ -shared common_test_3_pic.o -Wl,--version-script,$(srcdir)/ver_test_2.script
+
check_PROGRAMS += exception_test
check_PROGRAMS += exception_static_test
check_PROGRAMS += exception_shared_1_test
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 81b8b7f..291eab7 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -140,7 +140,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_mixed_2_shared_test
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_6 = two_file_strip_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_same_shared_strip_test \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ common_test_1 exception_test \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ common_test_1 common_test_2 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_static_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_shared_1_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_shared_2_test \
@@ -366,6 +367,7 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_strip_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_same_shared_strip_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ common_test_1$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ common_test_2$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_static_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_shared_1_test$(EXEEXT) \
@@ -476,6 +478,12 @@ am__common_test_1_SOURCES_DIST = common_test_1.c
common_test_1_OBJECTS = $(am_common_test_1_OBJECTS)
common_test_1_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(common_test_1_LDFLAGS) $(LDFLAGS) -o $@
+am__common_test_2_SOURCES_DIST = common_test_1.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am_common_test_2_OBJECTS = \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ common_test_1.$(OBJEXT)
+common_test_2_OBJECTS = $(am_common_test_2_OBJECTS)
+common_test_2_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(common_test_2_LDFLAGS) $(LDFLAGS) -o $@
am__constructor_static_test_SOURCES_DIST = constructor_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__objects_1 = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test.$(OBJEXT)
@@ -1064,9 +1072,9 @@ CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \
basic_static_pic_test.c basic_static_test.c basic_test.c \
$(binary_test_SOURCES) $(binary_unittest_SOURCES) \
- $(common_test_1_SOURCES) $(constructor_static_test_SOURCES) \
- $(constructor_test_SOURCES) $(copy_test_SOURCES) \
- $(discard_locals_test_SOURCES) \
+ $(common_test_1_SOURCES) $(common_test_2_SOURCES) \
+ $(constructor_static_test_SOURCES) $(constructor_test_SOURCES) \
+ $(copy_test_SOURCES) $(discard_locals_test_SOURCES) \
$(exception_same_shared_test_SOURCES) \
$(exception_separate_shared_12_test_SOURCES) \
$(exception_separate_shared_21_test_SOURCES) \
@@ -1119,6 +1127,7 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \
basic_pie_test.c basic_static_pic_test.c basic_static_test.c \
basic_test.c $(am__binary_test_SOURCES_DIST) \
$(binary_unittest_SOURCES) $(am__common_test_1_SOURCES_DIST) \
+ $(am__common_test_2_SOURCES_DIST) \
$(am__constructor_static_test_SOURCES_DIST) \
$(am__constructor_test_SOURCES_DIST) \
$(am__copy_test_SOURCES_DIST) \
@@ -1505,6 +1514,10 @@ binary_unittest_SOURCES = binary_unittest.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_1_DEPENDENCIES = gcctestdir/ld
@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_1_LDFLAGS = -Bgcctestdir/
@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_1_LDADD =
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_2_SOURCES = common_test_1.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_2_DEPENDENCIES = common_test_2.so common_test_3.so gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_2_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_2_LDADD = common_test_2.so common_test_3.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_test_SOURCES = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_test_main.cc \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_test_1.cc \
@@ -1806,6 +1819,9 @@ binary_unittest$(EXEEXT): $(binary_unittest_OBJECTS) $(binary_unittest_DEPENDENC
common_test_1$(EXEEXT): $(common_test_1_OBJECTS) $(common_test_1_DEPENDENCIES)
@rm -f common_test_1$(EXEEXT)
$(common_test_1_LINK) $(common_test_1_OBJECTS) $(common_test_1_LDADD) $(LIBS)
+common_test_2$(EXEEXT): $(common_test_2_OBJECTS) $(common_test_2_DEPENDENCIES)
+ @rm -f common_test_2$(EXEEXT)
+ $(common_test_2_LINK) $(common_test_2_OBJECTS) $(common_test_2_LDADD) $(LIBS)
constructor_static_test$(EXEEXT): $(constructor_static_test_OBJECTS) $(constructor_static_test_DEPENDENCIES)
@rm -f constructor_static_test$(EXEEXT)
$(constructor_static_test_LINK) $(constructor_static_test_OBJECTS) $(constructor_static_test_LDADD) $(LIBS)
@@ -2642,6 +2658,14 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_STRIP) -o two_file_strip_test two_file_test
@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_strip.so: two_file_shared.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_STRIP) -S -o two_file_shared_strip.so two_file_shared.so
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_2_pic.o: common_test_2.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -fpic -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_2.so: common_test_2_pic.o common_test_3.so gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -shared common_test_2_pic.o common_test_3.so
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_3_pic.o: common_test_3.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -fpic -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@common_test_3.so: common_test_3_pic.o ver_test_2.script gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -shared common_test_3_pic.o -Wl,--version-script,$(srcdir)/ver_test_2.script
@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_test_1_pic.o: exception_test_1.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_test_2_pic.o: exception_test_2.cc
diff --git a/gold/testsuite/common_test_2.c b/gold/testsuite/common_test_2.c
new file mode 100644
index 0000000..ef6d83d
--- /dev/null
+++ b/gold/testsuite/common_test_2.c
@@ -0,0 +1,33 @@
+/* common_test_2.c -- test common symbol name conflicts
+
+ Copyright 2009 Free Software Foundation, Inc.
+ Written by Ian Lance Taylor <iant@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. */
+
+/* Call a function. The function will come from a shared library. */
+
+extern void c1 (void);
+
+void fn (void);
+
+void
+fn (void)
+{
+ c1 ();
+}
diff --git a/gold/testsuite/common_test_3.c b/gold/testsuite/common_test_3.c
new file mode 100644
index 0000000..ba8960c
--- /dev/null
+++ b/gold/testsuite/common_test_3.c
@@ -0,0 +1,32 @@
+/* common_test_3.c -- test common symbol name conflicts
+
+ Copyright 2009 Free Software Foundation, Inc.
+ Written by Ian Lance Taylor <iant@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. */
+
+/* Define a function with a default version whose name is the same as
+ a common symbol. This file will wind up in a shared library. */
+
+void c1_v1 (void);
+
+void
+c1_v1 (void)
+{
+}
+__asm__ (".symver c1_v1,c1@@VER1");