From 386c048c7aebbff667dbbddd6a4b68299d1920dd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 12 Nov 2007 17:51:55 +0000 Subject: [PATCH] Correct handling of GOT references in a regular object. --- gold/i386.cc | 7 ++++--- gold/symtab.h | 4 ++++ gold/testsuite/Makefile.am | 14 ++++++++++++++ gold/testsuite/Makefile.in | 36 ++++++++++++++++++++++++++++++++++++ gold/x86_64.cc | 3 ++- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/gold/i386.cc b/gold/i386.cc index dcbb839ce1b..eae6b7fa339 100644 --- a/gold/i386.cc +++ b/gold/i386.cc @@ -1046,9 +1046,10 @@ Target_i386::Scan::global(const General_options& options, if (!gsym->final_value_is_known()) { Reloc_section* rel_dyn = target->rel_dyn_section(layout); - if (gsym->is_preemptible()) - rel_dyn->add_global(gsym, elfcpp::R_386_GLOB_DAT, got, - gsym->got_offset()); + if (gsym->is_from_dynobj() + || gsym->is_preemptible()) + rel_dyn->add_global(gsym, elfcpp::R_386_GLOB_DAT, got, + gsym->got_offset()); else { rel_dyn->add_local(object, 0, elfcpp::R_386_RELATIVE, diff --git a/gold/symtab.h b/gold/symtab.h index 2f43c4b7f92..81ad2d91f2b 100644 --- a/gold/symtab.h +++ b/gold/symtab.h @@ -405,6 +405,10 @@ class Symbol bool is_preemptible() const { + // It doesn't make sense to ask whether a symbol defined in + // another object is preemptible. + gold_assert(!this->is_from_dynobj()); + return (this->visibility_ != elfcpp::STV_INTERNAL && this->visibility_ != elfcpp::STV_HIDDEN && this->visibility_ != elfcpp::STV_PROTECTED diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 38e34c055fa..4ac2e5c3516 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -42,6 +42,8 @@ NATIVE_PROGS = \ two_file_pic_test \ two_file_shared_1_test \ two_file_shared_2_test \ + two_file_shared_1_pic_2_test \ + two_file_shared_2_pic_1_test \ two_file_same_shared_test \ two_file_separate_shared_12_test \ two_file_separate_shared_21_test \ @@ -182,6 +184,18 @@ two_file_shared_2_test_DEPENDENCIES = gcctestdir/ld two_file_shared_2.so two_file_shared_2_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. two_file_shared_2_test_LDADD = two_file_shared_2.so +two_file_shared_1_pic_2_test_SOURCES = two_file_test_main.cc +two_file_shared_1_pic_2_test_DEPENDENCIES = \ + gcctestdir/ld two_file_shared_1.so two_file_test_1_pic.o +two_file_shared_1_pic_2_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. +two_file_shared_1_pic_2_test_LDADD = two_file_test_1_pic.o two_file_shared_2.so + +two_file_shared_2_pic_1_test_SOURCES = two_file_test_main.cc +two_file_shared_2_pic_1_test_DEPENDENCIES = \ + gcctestdir/ld two_file_shared_2.so two_file_test_2_pic.o +two_file_shared_2_pic_1_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. +two_file_shared_2_pic_1_test_LDADD = two_file_test_2_pic.o two_file_shared_1.so + two_file_same_shared_test_SOURCES = two_file_test_main.cc two_file_same_shared_test_DEPENDENCIES = gcctestdir/ld two_file_shared.so two_file_same_shared_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 5e3b60768ce..44214f1144c 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -156,6 +156,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_pic_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_1_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_2_test$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_1_pic_2_test$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_2_pic_1_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_same_shared_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_separate_shared_12_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_separate_shared_21_test$(EXEEXT) \ @@ -302,6 +304,11 @@ am__two_file_shared_1_nonpic_test_SOURCES_DIST = two_file_test_2.cc \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_test_main.$(OBJEXT) two_file_shared_1_nonpic_test_OBJECTS = \ $(am_two_file_shared_1_nonpic_test_OBJECTS) +am__two_file_shared_1_pic_2_test_SOURCES_DIST = two_file_test_main.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@am_two_file_shared_1_pic_2_test_OBJECTS = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_test_main.$(OBJEXT) +two_file_shared_1_pic_2_test_OBJECTS = \ + $(am_two_file_shared_1_pic_2_test_OBJECTS) am__two_file_shared_1_test_SOURCES_DIST = two_file_test_2.cc \ two_file_test_main.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@am_two_file_shared_1_test_OBJECTS = \ @@ -314,6 +321,11 @@ am__two_file_shared_2_nonpic_test_SOURCES_DIST = two_file_test_1.cc \ @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_test_main.$(OBJEXT) two_file_shared_2_nonpic_test_OBJECTS = \ $(am_two_file_shared_2_nonpic_test_OBJECTS) +am__two_file_shared_2_pic_1_test_SOURCES_DIST = two_file_test_main.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@am_two_file_shared_2_pic_1_test_OBJECTS = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_test_main.$(OBJEXT) +two_file_shared_2_pic_1_test_OBJECTS = \ + $(am_two_file_shared_2_pic_1_test_OBJECTS) am__two_file_shared_2_test_SOURCES_DIST = two_file_test_1.cc \ two_file_test_main.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@am_two_file_shared_2_test_OBJECTS = \ @@ -375,8 +387,10 @@ SOURCES = $(libgoldtest_a_SOURCES) $(constructor_static_test_SOURCES) \ $(two_file_separate_shared_21_nonpic_test_SOURCES) \ $(two_file_separate_shared_21_test_SOURCES) \ $(two_file_shared_1_nonpic_test_SOURCES) \ + $(two_file_shared_1_pic_2_test_SOURCES) \ $(two_file_shared_1_test_SOURCES) \ $(two_file_shared_2_nonpic_test_SOURCES) \ + $(two_file_shared_2_pic_1_test_SOURCES) \ $(two_file_shared_2_test_SOURCES) \ $(two_file_static_test_SOURCES) $(two_file_test_SOURCES) \ $(weak_test_SOURCES) @@ -404,8 +418,10 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES) \ $(am__two_file_separate_shared_21_nonpic_test_SOURCES_DIST) \ $(am__two_file_separate_shared_21_test_SOURCES_DIST) \ $(am__two_file_shared_1_nonpic_test_SOURCES_DIST) \ + $(am__two_file_shared_1_pic_2_test_SOURCES_DIST) \ $(am__two_file_shared_1_test_SOURCES_DIST) \ $(am__two_file_shared_2_nonpic_test_SOURCES_DIST) \ + $(am__two_file_shared_2_pic_1_test_SOURCES_DIST) \ $(am__two_file_shared_2_test_SOURCES_DIST) \ $(am__two_file_static_test_SOURCES_DIST) \ $(am__two_file_test_SOURCES_DIST) \ @@ -564,6 +580,8 @@ TESTS = object_unittest $(am__append_1) $(NATIVE_TESTING) @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_pic_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_1_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_2_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_1_pic_2_test \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared_2_pic_1_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_same_shared_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_separate_shared_12_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_separate_shared_21_test \ @@ -626,6 +644,18 @@ object_unittest_SOURCES = object_unittest.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_test_DEPENDENCIES = gcctestdir/ld two_file_shared_2.so @GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. @GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_test_LDADD = two_file_shared_2.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_1_pic_2_test_SOURCES = two_file_test_main.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_1_pic_2_test_DEPENDENCIES = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld two_file_shared_1.so two_file_test_1_pic.o + +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_1_pic_2_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_1_pic_2_test_LDADD = two_file_test_1_pic.o two_file_shared_2.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_pic_1_test_SOURCES = two_file_test_main.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_pic_1_test_DEPENDENCIES = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld two_file_shared_2.so two_file_test_2_pic.o + +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_pic_1_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. +@GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_shared_2_pic_1_test_LDADD = two_file_test_2_pic.o two_file_shared_1.so @GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_same_shared_test_SOURCES = two_file_test_main.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_same_shared_test_DEPENDENCIES = gcctestdir/ld two_file_shared.so @GCC_TRUE@@NATIVE_LINKER_TRUE@two_file_same_shared_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,. @@ -871,12 +901,18 @@ two_file_separate_shared_21_test$(EXEEXT): $(two_file_separate_shared_21_test_OB two_file_shared_1_nonpic_test$(EXEEXT): $(two_file_shared_1_nonpic_test_OBJECTS) $(two_file_shared_1_nonpic_test_DEPENDENCIES) @rm -f two_file_shared_1_nonpic_test$(EXEEXT) $(CXXLINK) $(two_file_shared_1_nonpic_test_LDFLAGS) $(two_file_shared_1_nonpic_test_OBJECTS) $(two_file_shared_1_nonpic_test_LDADD) $(LIBS) +two_file_shared_1_pic_2_test$(EXEEXT): $(two_file_shared_1_pic_2_test_OBJECTS) $(two_file_shared_1_pic_2_test_DEPENDENCIES) + @rm -f two_file_shared_1_pic_2_test$(EXEEXT) + $(CXXLINK) $(two_file_shared_1_pic_2_test_LDFLAGS) $(two_file_shared_1_pic_2_test_OBJECTS) $(two_file_shared_1_pic_2_test_LDADD) $(LIBS) two_file_shared_1_test$(EXEEXT): $(two_file_shared_1_test_OBJECTS) $(two_file_shared_1_test_DEPENDENCIES) @rm -f two_file_shared_1_test$(EXEEXT) $(CXXLINK) $(two_file_shared_1_test_LDFLAGS) $(two_file_shared_1_test_OBJECTS) $(two_file_shared_1_test_LDADD) $(LIBS) two_file_shared_2_nonpic_test$(EXEEXT): $(two_file_shared_2_nonpic_test_OBJECTS) $(two_file_shared_2_nonpic_test_DEPENDENCIES) @rm -f two_file_shared_2_nonpic_test$(EXEEXT) $(CXXLINK) $(two_file_shared_2_nonpic_test_LDFLAGS) $(two_file_shared_2_nonpic_test_OBJECTS) $(two_file_shared_2_nonpic_test_LDADD) $(LIBS) +two_file_shared_2_pic_1_test$(EXEEXT): $(two_file_shared_2_pic_1_test_OBJECTS) $(two_file_shared_2_pic_1_test_DEPENDENCIES) + @rm -f two_file_shared_2_pic_1_test$(EXEEXT) + $(CXXLINK) $(two_file_shared_2_pic_1_test_LDFLAGS) $(two_file_shared_2_pic_1_test_OBJECTS) $(two_file_shared_2_pic_1_test_LDADD) $(LIBS) two_file_shared_2_test$(EXEEXT): $(two_file_shared_2_test_OBJECTS) $(two_file_shared_2_test_DEPENDENCIES) @rm -f two_file_shared_2_test$(EXEEXT) $(CXXLINK) $(two_file_shared_2_test_LDFLAGS) $(two_file_shared_2_test_OBJECTS) $(two_file_shared_2_test_LDADD) $(LIBS) diff --git a/gold/x86_64.cc b/gold/x86_64.cc index 5bc74bf29a8..0614e89c606 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -1020,7 +1020,8 @@ Target_x86_64::Scan::global(const General_options& options, if (!gsym->final_value_is_known()) { Reloc_section* rela_dyn = target->rela_dyn_section(layout); - if (gsym->is_preemptible()) + if (gsym->is_from_dynobj() + || gsym->is_preemptible()) rela_dyn->add_global(gsym, elfcpp::R_X86_64_GLOB_DAT, got, gsym->got_offset(), 0); else -- 2.30.2