From f3a2388fc96c63c0233cdc3449ea61cf36e4975b Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Thu, 10 Jun 2010 17:20:27 +0000 Subject: [PATCH] * object.cc (Sized_relobj::do_layout): Defer layout for reloc sections. (Sized_relobj::do_layout_deferred_sections): Do layout for deferred reloc sections. * object.h (Sized_relobj::deferred_layout_relocs_): New data member. PR 11683 * symtab.h (Symbol::is_placeholder): New member function. * target-reloc.h (relocate_section): Check for placeholder symbols. * testsuite/Makefile.am (plugin_test_8): New test. (plugin_test_9): New test. * testsuite/Makefile.in: Regenerate. --- gold/ChangeLog | 15 +++++++++++ gold/object.cc | 41 +++++++++++++++++++++++++++++ gold/object.h | 2 ++ gold/symtab.h | 7 +++++ gold/target-reloc.h | 2 +- gold/testsuite/Makefile.am | 28 ++++++++++++++++++++ gold/testsuite/Makefile.in | 53 +++++++++++++++++++++++++++++++++++--- 7 files changed, 143 insertions(+), 5 deletions(-) diff --git a/gold/ChangeLog b/gold/ChangeLog index b19b90a471d..d333449348d 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,18 @@ +2010-06-10 Cary Coutant + + * object.cc (Sized_relobj::do_layout): Defer layout for reloc sections. + (Sized_relobj::do_layout_deferred_sections): Do layout for deferred + reloc sections. + * object.h (Sized_relobj::deferred_layout_relocs_): New data member. + + PR 11683 + * symtab.h (Symbol::is_placeholder): New member function. + * target-reloc.h (relocate_section): Check for placeholder symbols. + + * testsuite/Makefile.am (plugin_test_8): New test. + (plugin_test_9): New test. + * testsuite/Makefile.in: Regenerate. + 2010-06-09 Nick Clifton * yyscript.y (input_list_element): Allow strings prefixed with diff --git a/gold/object.cc b/gold/object.cc index 24fd5862960..b034ee209ac 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -1371,6 +1371,17 @@ Sized_relobj::do_layout(Symbol_table* symtab, } Output_section* data_section = out_sections[data_shndx]; + if (data_section == reinterpret_cast(2)) + { + // The layout for the data section was deferred, so we need + // to defer the relocation section, too. + const char* name = pnames + shdr.get_sh_name(); + this->deferred_layout_relocs_.push_back( + Deferred_layout(i, name, pshdr, 0, elfcpp::SHT_NULL)); + out_sections[i] = reinterpret_cast(2); + out_section_offsets[i] = invalid_address; + continue; + } if (data_section == NULL) { out_sections[i] = NULL; @@ -1471,6 +1482,36 @@ Sized_relobj::do_layout_deferred_sections(Layout* layout) } this->deferred_layout_.clear(); + + // Now handle the deferred relocation sections. + + Output_sections& out_sections(this->output_sections()); + std::vector
& out_section_offsets(this->section_offsets_); + + for (deferred = this->deferred_layout_relocs_.begin(); + deferred != this->deferred_layout_relocs_.end(); + ++deferred) + { + unsigned int shndx = deferred->shndx_; + typename This::Shdr shdr(deferred->shdr_data_); + unsigned int data_shndx = this->adjust_shndx(shdr.get_sh_info()); + + Output_section* data_section = out_sections[data_shndx]; + if (data_section == NULL) + { + out_sections[shndx] = NULL; + out_section_offsets[shndx] = invalid_address; + continue; + } + + Relocatable_relocs* rr = new Relocatable_relocs(); + this->set_relocatable_relocs(shndx, rr); + + Output_section* os = layout->layout_reloc(this, shndx, shdr, + data_section, rr); + out_sections[shndx] = os; + out_section_offsets[shndx] = invalid_address; + } } // Add the symbols to the symbol table. diff --git a/gold/object.h b/gold/object.h index 02747a7caa6..bc2b558f57f 100644 --- a/gold/object.h +++ b/gold/object.h @@ -2022,6 +2022,8 @@ class Sized_relobj : public Relobj unsigned int discarded_eh_frame_shndx_; // The list of sections whose layout was deferred. std::vector deferred_layout_; + // The list of relocation sections whose layout was deferred. + std::vector deferred_layout_relocs_; }; // A class to manage the list of all objects. diff --git a/gold/symtab.h b/gold/symtab.h index 4a97461ca5f..7d75e06b422 100644 --- a/gold/symtab.h +++ b/gold/symtab.h @@ -459,6 +459,13 @@ class Symbol return this->source_ == FROM_OBJECT && this->object()->is_dynamic(); } + // Return whether this is a placeholder symbol from a plugin object. + bool + is_placeholder() const + { + return this->source_ == FROM_OBJECT && this->object()->pluginobj() != NULL; + } + // Return whether this is an undefined symbol. bool is_undefined() const diff --git a/gold/target-reloc.h b/gold/target-reloc.h index 34c13e8173d..23866e373d5 100644 --- a/gold/target-reloc.h +++ b/gold/target-reloc.h @@ -341,7 +341,7 @@ relocate_section( } if (sym != NULL - && sym->is_undefined() + && (sym->is_undefined() || sym->is_placeholder()) && sym->binding() != elfcpp::STB_WEAK && !is_defined_in_discarded_section && !target->is_defined_by_abi(sym) diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 67d03335f13..7a427cdcd41 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1314,6 +1314,34 @@ plugin_test_7_2.o: plugin_test_7_2.c $(COMPILE) -O0 -c -ffunction-sections -fdata-sections -o $@ $< plugin_test_7.err: plugin_test_7 +# Test plugins with -r. +check_PROGRAMS += plugin_test_8 +plugin_test_8.o: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.o ../ld-new plugin_test.so + ../ld-new -r -o $@ --no-demangle --plugin "./plugin_test.so" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.o +plugin_test_8: plugin_test_8.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle plugin_test_8.o + +# Test that symbols known in the IR file but not in the replacement file +# produce an unresolved symbol error. +check_DATA += plugin_test_9.err +MOSTLYCLEANFILES += plugin_test_9.err +plugin_test_9.err: two_file_test_main.o two_file_test_1c.syms two_file_test_2.syms gcctestdir/ld plugin_test.so + @echo $(CXXLINK) -Bgcctestdir/ -o plugin_test_9 -Wl,--no-demangle,--plugin,"./plugin_test.so" two_file_test_main.o two_file_test_1c.syms two_file_test_2.syms "2>$@" + @if $(CXXLINK) -Bgcctestdir/ -o plugin_test_9 -Wl,--no-demangle,--plugin,"./plugin_test.so" two_file_test_main.o two_file_test_1c.syms two_file_test_2.syms 2>$@; then \ + echo 1>&2 "Link of plugin_test_9 should have failed"; \ + rm -f $@; \ + exit 1; \ + fi +# Make a .syms file that claims to define the symbol _Z4t16av. +two_file_test_1c.syms: two_file_test_1.syms two_file_test_1c.o + cp two_file_test_1.syms $@.tmp + grep "_Z4t16av" two_file_test_1b.syms >> $@.tmp + mv -f $@.tmp $@ +# Make a copy of two_file_test_1.o, which does not define the symbol _Z4t16av. +MOSTLYCLEANFILES += two_file_test_1c.o +two_file_test_1c.o: two_file_test_1.o + cp two_file_test_1.o $@ + plugin_test.so: plugin_test.o $(LINK) -Bgcctestdir/ -shared plugin_test.o plugin_test.o: plugin_test.c diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index efc3bcd7ff8..ce03d13a142 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -250,6 +250,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @NATIVE_LINKER_FALSE@binary_test_DEPENDENCIES = @GCC_FALSE@thin_archive_test_2_DEPENDENCIES = @NATIVE_LINKER_FALSE@thin_archive_test_2_DEPENDENCIES = + +# Test plugins with -r. @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_22 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2 \ @@ -257,7 +259,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_5 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_6 \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7 +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_8 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_23 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.sh \ @@ -265,6 +268,9 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_6.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.sh + +# Test that symbols known in the IR file but not in the replacement file +# produce an unresolved symbol error. @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_24 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.err \ @@ -272,7 +278,9 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_6.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.syms +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.syms \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_9.err +# Make a copy of two_file_test_1.o, which does not define the symbol _Z4t16av. @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_25 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.err \ @@ -281,6 +289,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_6.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_9.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ two_file_test_1c.o \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ unused.c @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = exclude_libs_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ local_labels_test \ @@ -499,7 +509,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_5$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_6$(EXEEXT) \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7$(EXEEXT) +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_8$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_17 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exclude_libs_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ local_labels_test$(EXEEXT) \ @@ -757,6 +768,12 @@ plugin_test_7_LDADD = $(LDADD) plugin_test_7_DEPENDENCIES = libgoldtest.a ../libgold.a \ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +plugin_test_8_SOURCES = plugin_test_8.c +plugin_test_8_OBJECTS = plugin_test_8.$(OBJEXT) +plugin_test_8_LDADD = $(LDADD) +plugin_test_8_DEPENDENCIES = libgoldtest.a ../libgold.a \ + ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) @GCC_TRUE@@NATIVE_LINKER_TRUE@am_protected_1_OBJECTS = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_1.$(OBJEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_2.$(OBJEXT) \ @@ -1120,7 +1137,7 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \ $(object_unittest_SOURCES) permission_test.c plugin_test_1.c \ plugin_test_2.c plugin_test_3.c plugin_test_4.c \ plugin_test_5.c plugin_test_6.c plugin_test_7.c \ - $(protected_1_SOURCES) $(protected_2_SOURCES) \ + plugin_test_8.c $(protected_1_SOURCES) $(protected_2_SOURCES) \ $(relro_script_test_SOURCES) $(relro_test_SOURCES) \ $(script_test_1_SOURCES) $(script_test_2_SOURCES) \ script_test_3.c $(searched_file_test_SOURCES) \ @@ -1958,6 +1975,15 @@ object_unittest$(EXEEXT): $(object_unittest_OBJECTS) $(object_unittest_DEPENDENC @PLUGINS_FALSE@plugin_test_7$(EXEEXT): $(plugin_test_7_OBJECTS) $(plugin_test_7_DEPENDENCIES) @PLUGINS_FALSE@ @rm -f plugin_test_7$(EXEEXT) @PLUGINS_FALSE@ $(LINK) $(plugin_test_7_OBJECTS) $(plugin_test_7_LDADD) $(LIBS) +@GCC_FALSE@plugin_test_8$(EXEEXT): $(plugin_test_8_OBJECTS) $(plugin_test_8_DEPENDENCIES) +@GCC_FALSE@ @rm -f plugin_test_8$(EXEEXT) +@GCC_FALSE@ $(LINK) $(plugin_test_8_OBJECTS) $(plugin_test_8_LDADD) $(LIBS) +@NATIVE_LINKER_FALSE@plugin_test_8$(EXEEXT): $(plugin_test_8_OBJECTS) $(plugin_test_8_DEPENDENCIES) +@NATIVE_LINKER_FALSE@ @rm -f plugin_test_8$(EXEEXT) +@NATIVE_LINKER_FALSE@ $(LINK) $(plugin_test_8_OBJECTS) $(plugin_test_8_LDADD) $(LIBS) +@PLUGINS_FALSE@plugin_test_8$(EXEEXT): $(plugin_test_8_OBJECTS) $(plugin_test_8_DEPENDENCIES) +@PLUGINS_FALSE@ @rm -f plugin_test_8$(EXEEXT) +@PLUGINS_FALSE@ $(LINK) $(plugin_test_8_OBJECTS) $(plugin_test_8_LDADD) $(LIBS) protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES) @rm -f protected_1$(EXEEXT) $(protected_1_LINK) $(protected_1_OBJECTS) $(protected_1_LDADD) $(LIBS) @@ -2191,6 +2217,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_5.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_6.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_7.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_8.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_3.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_2.Po@am__quote@ @@ -3076,6 +3103,24 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7_2.o: plugin_test_7_2.c @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(COMPILE) -O0 -c -ffunction-sections -fdata-sections -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_7.err: plugin_test_7 +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_8.o: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.o ../ld-new plugin_test.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ ../ld-new -r -o $@ --no-demangle --plugin "./plugin_test.so" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_8: plugin_test_8.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle plugin_test_8.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_9.err: two_file_test_main.o two_file_test_1c.syms two_file_test_2.syms gcctestdir/ld plugin_test.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ @echo $(CXXLINK) -Bgcctestdir/ -o plugin_test_9 -Wl,--no-demangle,--plugin,"./plugin_test.so" two_file_test_main.o two_file_test_1c.syms two_file_test_2.syms "2>$@" +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ @if $(CXXLINK) -Bgcctestdir/ -o plugin_test_9 -Wl,--no-demangle,--plugin,"./plugin_test.so" two_file_test_main.o two_file_test_1c.syms two_file_test_2.syms 2>$@; then \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ echo 1>&2 "Link of plugin_test_9 should have failed"; \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ rm -f $@; \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ exit 1; \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ fi +# Make a .syms file that claims to define the symbol _Z4t16av. +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@two_file_test_1c.syms: two_file_test_1.syms two_file_test_1c.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ cp two_file_test_1.syms $@.tmp +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ grep "_Z4t16av" two_file_test_1b.syms >> $@.tmp +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ mv -f $@.tmp $@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@two_file_test_1c.o: two_file_test_1.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ cp two_file_test_1.o $@ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test.so: plugin_test.o @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(LINK) -Bgcctestdir/ -shared plugin_test.o -- 2.30.2