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.
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;
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
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);
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
@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 \
@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) \
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)
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) \
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) \
@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 \
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)
@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
--- /dev/null
+/* 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 ();
+}
--- /dev/null
+/* 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");