This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gold patch committed: Warn about _32 and _PC32 in shared object


PR 12324 points out that gold does not issue the same warnings as GNU ld
when it comes to putting non-PIC relocations in shared objects.  When I
added the warning, I looked at the list of relocations that glibc
supports, but I didn't consider that two of them can overflow at
runtime.  This patch warns about those two.  I had to adjust a test case
to compile with -fpic.  Committed to mainline.

Ian


2010-12-15  Ian Lance Taylor  <iant@google.com>

	PR gold/12324
	* x86_64.cc (Target_x86_64::Scan::check_non_pic): Give an error
	for R_X86_64_32 and R_X86_64_PC32.
	* testsuite/Makefile.am (ver_matching_def.so): Depend on and use
	ver_matching_def_pic.o.
	(ver_matching_def_pic.o): New target.


Index: x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.120
diff -p -u -r1.120 x86_64.cc
--- x86_64.cc	14 Dec 2010 19:03:30 -0000	1.120
+++ x86_64.cc	15 Dec 2010 15:33:35 -0000
@@ -1329,7 +1329,8 @@ Target_x86_64::Scan::check_non_pic(Relob
 {
   switch (r_type)
     {
-      // These are the relocation types supported by glibc for x86_64.
+      // These are the relocation types supported by glibc for x86_64
+      // which should always work.
     case elfcpp::R_X86_64_RELATIVE:
     case elfcpp::R_X86_64_IRELATIVE:
     case elfcpp::R_X86_64_GLOB_DAT:
@@ -1338,9 +1339,18 @@ Target_x86_64::Scan::check_non_pic(Relob
     case elfcpp::R_X86_64_DTPOFF64:
     case elfcpp::R_X86_64_TPOFF64:
     case elfcpp::R_X86_64_64:
+    case elfcpp::R_X86_64_COPY:
+      return;
+
+      // glibc supports these reloc types, but they can overflow.
     case elfcpp::R_X86_64_32:
     case elfcpp::R_X86_64_PC32:
-    case elfcpp::R_X86_64_COPY:
+      if (this->issued_non_pic_error_)
+	return;
+      gold_assert(parameters->options().output_is_position_independent());
+      object->error(_("requires dynamic reloc which may overflow at runtime; "
+		      "recompile with -fPIC"));
+      this->issued_non_pic_error_ = true;
       return;
 
     default:
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.152
diff -p -u -r1.152 Makefile.am
--- testsuite/Makefile.am	29 Oct 2010 15:45:40 -0000	1.152
+++ testsuite/Makefile.am	15 Dec 2010 15:33:35 -0000
@@ -1146,8 +1146,10 @@ binary.txt: $(srcdir)/binary.in
 check_SCRIPTS += ver_matching_test.sh
 check_DATA += ver_matching_test.stdout
 MOSTLYCLEANFILES += ver_matching_test.stdout
-ver_matching_def.so: ver_matching_def.cc $(srcdir)/version_script.map gcctestdir/ld
-	$(CXXLINK) -O0 -Bgcctestdir/ -shared $(srcdir)/ver_matching_def.cc -Wl,--version-script=$(srcdir)/version_script.map
+ver_matching_def.so: ver_matching_def_pic.o $(srcdir)/version_script.map gcctestdir/ld
+	$(CXXLINK) -O0 -Bgcctestdir/ -shared ver_matching_def_pic.o -Wl,--version-script=$(srcdir)/version_script.map
+ver_matching_def_pic.o: ver_matching_def.cc
+	$(CXXCOMPILE) -O0 -c -fpic -o $@ $<
 ver_matching_test.stdout: ver_matching_def.so
 	$(TEST_OBJDUMP) -T ver_matching_def.so | $(TEST_CXXFILT) > ver_matching_test.stdout
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]