Add R_X86_64_PC32_BND/R_X86_64_PLT32_BND suppor to gold
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 17 Nov 2013 18:30:28 +0000 (10:30 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 18 Nov 2013 17:55:09 +0000 (09:55 -0800)
elfcpp/

* x86_64.h (R_X86_64_PC32_BND): New.
(R_X86_64_PLT32_BND): Likewise.

gold/

* x86_64.cc (Target_x86_64<size>::Scan::get_reference_flags):
Handle R_X86_64_PC32_BND and R_X86_64_PLT32_BND just like
R_X86_64_PC32 and R_X86_64_PLT32, respectively.
(Target_x86_64<size>::Scan::local): Likewise.
(Target_x86_64<size>::Scan::global): Likewise.
(Target_x86_64<size>::Relocate::relocate): Likewise.
(Target_x86_64<size>::Relocatable_size_for_reloc::get_size_for_reloc):
Likewise.
(Target_x86_64<size>::Scan::check_non_pic(): Handle
R_X86_64_PC32_BND.

* testsuite/Makefile.am (check_PROGRAMS): Add
exception_x86_64_bnd_test.
(exception_x86_64_bnd_test_SOURCES): New macro.
(exception_x86_64_bnd_test_DEPENDENCIES): Likewise.
(exception_x86_64_bnd_test_LDFLAGS): Likewise.
(exception_x86_64_bnd_test_LDADD): Likewise.
(exception_x86_64_bnd_1.o): New rule.
(exception_x86_64_bnd_2.o): Likewise.
* testsuite/Makefile.in: Regenerated.

elfcpp/ChangeLog
elfcpp/x86_64.h
gold/ChangeLog
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/x86_64.cc

index 4d0a5037f762dfac46a5c9440b421c81c54fb4ed..2399da69ec6d6cdbdfbdd25513ba0d42974cbcfc 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * x86_64.h (R_X86_64_PC32_BND): New.
+       (R_X86_64_PLT32_BND): Likewise.
+
 2013-10-30  Alan Modra  <amodra@gmail.com>
 
        * powerpc.h (EF_PPC64_ABI): New enum constant.
index a53beac947c11a40ff1a2a25b7539f65d9627b76..79fa13fcf5341b4e5953e4db8f82b9c514c43aed 100644 (file)
@@ -92,6 +92,8 @@ enum
   R_X86_64_TLSDESC = 36,         // 2 by 64-bit TLS descriptor
   R_X86_64_IRELATIVE = 37,          // Adjust indirectly by program base
   R_X86_64_RELATIVE64 = 38,      // 64-bit adjust by program base
+  R_X86_64_PC32_BND = 39,  // PC relative 32 bit signed with BND prefix
+  R_X86_64_PLT32_BND = 40, // 32 bit PLT address with BND prefix
   // GNU vtable garbage collection extensions.
   R_X86_64_GNU_VTINHERIT = 250,
   R_X86_64_GNU_VTENTRY = 251
index 97ac6965fec3d8dcbf59706bbbaddab9b5ac48ad..5724e5982fd377a7bd361e0b61232946dcb38e19 100644 (file)
@@ -1,3 +1,26 @@
+2013-11-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * x86_64.cc (Target_x86_64<size>::Scan::get_reference_flags):
+       Handle R_X86_64_PC32_BND and R_X86_64_PLT32_BND just like
+       R_X86_64_PC32 and R_X86_64_PLT32, respectively.
+       (Target_x86_64<size>::Scan::local): Likewise.
+       (Target_x86_64<size>::Scan::global): Likewise.
+       (Target_x86_64<size>::Relocate::relocate): Likewise.
+       (Target_x86_64<size>::Relocatable_size_for_reloc::get_size_for_reloc):
+       Likewise.
+       (Target_x86_64<size>::Scan::check_non_pic(): Handle
+       R_X86_64_PC32_BND.
+
+       * testsuite/Makefile.am (check_PROGRAMS): Add
+       exception_x86_64_bnd_test.
+       (exception_x86_64_bnd_test_SOURCES): New macro.
+       (exception_x86_64_bnd_test_DEPENDENCIES): Likewise.
+       (exception_x86_64_bnd_test_LDFLAGS): Likewise.
+       (exception_x86_64_bnd_test_LDADD): Likewise.
+       (exception_x86_64_bnd_1.o): New rule.
+       (exception_x86_64_bnd_2.o): Likewise.
+       * testsuite/Makefile.in: Regenerated.
+
 2013-11-15  Alan Modra  <amodra@gmail.com>
 
        * powerpc.cc (Target_powerpc::glink_section): Provide non-const
index 0d40e3ff4d77a413f882aee1391141258201521e..2b7b5ae2a09259ea0d6209ce2715ebd72e0d1787 100644 (file)
@@ -2256,6 +2256,19 @@ incremental_comdat_test_1: incr_comdat_test_1.o incr_comdat_test_2_v1.o incr_com
 
 endif DEFAULT_TARGET_X86_64
 
+if DEFAULT_TARGET_X86_64
+check_PROGRAMS += exception_x86_64_bnd_test
+exception_x86_64_bnd_test_SOURCES = exception_test_main.cc
+exception_x86_64_bnd_test_DEPENDENCIES = exception_x86_64_bnd_1.o \
+                                        exception_x86_64_bnd_2.o
+exception_x86_64_bnd_test_LDFLAGS = $(exception_test_LDFLAGS)
+exception_x86_64_bnd_test_LDADD = $(exception_x86_64_bnd_test_DEPENDENCIES)
+exception_x86_64_bnd_1.o: exception_test_1.cc
+       $(CXXCOMPILE) -c -fpic -Bgcctestdir/ -Wa,-madd-bnd-prefix -o $@ $<
+exception_x86_64_bnd_2.o: exception_test_2.cc
+       $(CXXCOMPILE) -c -Bgcctestdir/ -Wa,-madd-bnd-prefix -o $@ $<
+endif DEFAULT_TARGET_X86_64
+
 endif GCC
 endif NATIVE_LINKER
 
index 07bb534ab72c831566d53d87a51132663adb6488..b7798c48561031e44961ce9f9694a868ec61d47c 100644 (file)
@@ -549,7 +549,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_test_6 \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_copy_test \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_common_test_1 \
-@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_comdat_test_1
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_comdat_test_1 \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     exception_x86_64_bnd_test
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_71 = two_file_test_tmp_2.o \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     two_file_test_tmp_3.o \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_test_4.base \
@@ -885,7 +886,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_test_6$(EXEEXT) \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_copy_test$(EXEEXT) \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_common_test_1$(EXEEXT) \
-@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_comdat_test_1$(EXEEXT)
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_comdat_test_1$(EXEEXT) \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     exception_x86_64_bnd_test$(EXEEXT)
 basic_pic_test_SOURCES = basic_pic_test.c
 basic_pic_test_OBJECTS = basic_pic_test.$(OBJEXT)
 basic_pic_test_LDADD = $(LDADD)
@@ -1014,6 +1016,11 @@ exception_static_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
 exception_test_OBJECTS = $(am_exception_test_OBJECTS)
 exception_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
        $(exception_test_LDFLAGS) $(LDFLAGS) -o $@
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am_exception_x86_64_bnd_test_OBJECTS = exception_test_main.$(OBJEXT)
+exception_x86_64_bnd_test_OBJECTS =  \
+       $(am_exception_x86_64_bnd_test_OBJECTS)
+exception_x86_64_bnd_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
+       $(exception_x86_64_bnd_test_LDFLAGS) $(LDFLAGS) -o $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am_exclude_libs_test_OBJECTS =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ exclude_libs_test.$(OBJEXT)
 exclude_libs_test_OBJECTS = $(am_exclude_libs_test_OBJECTS)
@@ -1772,6 +1779,7 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \
        $(exception_shared_1_test_SOURCES) \
        $(exception_shared_2_test_SOURCES) \
        $(exception_static_test_SOURCES) $(exception_test_SOURCES) \
+       $(exception_x86_64_bnd_test_SOURCES) \
        $(exclude_libs_test_SOURCES) \
        flagstest_compress_debug_sections.c flagstest_o_specialfile.c \
        flagstest_o_specialfile_and_compress_debug_sections.c \
@@ -2590,6 +2598,12 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \
 @GCC_TRUE@@IFUNC_TRUE@@NATIVE_LINKER_TRUE@ifuncvar_DEPENDENCIES = gcctestdir/ld ifuncvar.so
 @GCC_TRUE@@IFUNC_TRUE@@NATIVE_LINKER_TRUE@ifuncvar_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
 @GCC_TRUE@@IFUNC_TRUE@@NATIVE_LINKER_TRUE@ifuncvar_LDADD = ifuncvar.so
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_test_SOURCES = exception_test_main.cc
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_test_DEPENDENCIES = exception_x86_64_bnd_1.o \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@                                      exception_x86_64_bnd_2.o
+
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_test_LDFLAGS = $(exception_test_LDFLAGS)
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_test_LDADD = $(exception_x86_64_bnd_test_DEPENDENCIES)
 @DEFAULT_TARGET_I386_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@SPLIT_DEFSYMS = --defsym __morestack=0x100 --defsym __morestack_non_split=0x200
 @DEFAULT_TARGET_X86_64_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@SPLIT_DEFSYMS = --defsym __morestack=0x100 --defsym __morestack_non_split=0x200
 all: $(BUILT_SOURCES)
@@ -2718,6 +2732,9 @@ exception_static_test$(EXEEXT): $(exception_static_test_OBJECTS) $(exception_sta
 exception_test$(EXEEXT): $(exception_test_OBJECTS) $(exception_test_DEPENDENCIES) 
        @rm -f exception_test$(EXEEXT)
        $(exception_test_LINK) $(exception_test_OBJECTS) $(exception_test_LDADD) $(LIBS)
+exception_x86_64_bnd_test$(EXEEXT): $(exception_x86_64_bnd_test_OBJECTS) $(exception_x86_64_bnd_test_DEPENDENCIES) 
+       @rm -f exception_x86_64_bnd_test$(EXEEXT)
+       $(exception_x86_64_bnd_test_LINK) $(exception_x86_64_bnd_test_OBJECTS) $(exception_x86_64_bnd_test_LDADD) $(LIBS)
 exclude_libs_test$(EXEEXT): $(exclude_libs_test_OBJECTS) $(exclude_libs_test_DEPENDENCIES) 
        @rm -f exclude_libs_test$(EXEEXT)
        $(exclude_libs_test_LINK) $(exclude_libs_test_OBJECTS) $(exclude_libs_test_LDADD) $(LIBS)
@@ -4231,6 +4248,8 @@ incremental_common_test_1.log: incremental_common_test_1$(EXEEXT)
        @p='incremental_common_test_1$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 incremental_comdat_test_1.log: incremental_comdat_test_1$(EXEEXT)
        @p='incremental_comdat_test_1$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+exception_x86_64_bnd_test.log: exception_x86_64_bnd_test$(EXEEXT)
+       @p='exception_x86_64_bnd_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 .test.log:
        @p='$<'; $(am__check_pre) $(TEST_LOG_COMPILE) "$$tst" $(am__check_post)
 @am__EXEEXT_TRUE@.test$(EXEEXT).log:
@@ -5390,6 +5409,10 @@ uninstall-am:
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     @sleep 1
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     cp -f incr_comdat_test_2_v3.o incr_comdat_test_1_tmp.o
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     $(CXXLINK) -Wl,--incremental-update -Bgcctestdir/ incr_comdat_test_1.o incr_comdat_test_1_tmp.o
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_1.o: exception_test_1.cc
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     $(CXXCOMPILE) -c -fpic -Bgcctestdir/ -Wa,-madd-bnd-prefix -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@exception_x86_64_bnd_2.o: exception_test_2.cc
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     $(CXXCOMPILE) -c -Bgcctestdir/ -Wa,-madd-bnd-prefix -o $@ $<
 @NATIVE_OR_CROSS_LINKER_TRUE@script_test_10.o: script_test_10.s
 @NATIVE_OR_CROSS_LINKER_TRUE@  $(TEST_AS) -o $@ $<
 @NATIVE_OR_CROSS_LINKER_TRUE@script_test_10: $(srcdir)/script_test_10.t script_test_10.o gcctestdir/ld
index b9f9f17accf48964c040977313615db5602b20dd..a0c4fce8899cacb670f694d018cbc1813027eea6 100644 (file)
@@ -2113,12 +2113,14 @@ Target_x86_64<size>::Scan::get_reference_flags(unsigned int r_type)
 
     case elfcpp::R_X86_64_PC64:
     case elfcpp::R_X86_64_PC32:
+    case elfcpp::R_X86_64_PC32_BND:
     case elfcpp::R_X86_64_PC16:
     case elfcpp::R_X86_64_PC8:
     case elfcpp::R_X86_64_GOTOFF64:
       return Symbol::RELATIVE_REF;
 
     case elfcpp::R_X86_64_PLT32:
+    case elfcpp::R_X86_64_PLT32_BND:
     case elfcpp::R_X86_64_PLTOFF64:
       return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
 
@@ -2200,6 +2202,7 @@ Target_x86_64<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type,
 
       // glibc supports these reloc types, but they can overflow.
     case elfcpp::R_X86_64_PC32:
+    case elfcpp::R_X86_64_PC32_BND:
       // A PC relative reference is OK against a local symbol or if
       // the symbol is defined locally.
       if (gsym == NULL
@@ -2219,12 +2222,28 @@ Target_x86_64<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type,
        object->error(_("requires dynamic R_X86_64_32 reloc which may "
                        "overflow at runtime; recompile with -fPIC"));
       else
-       object->error(_("requires dynamic %s reloc against '%s' which may "
-                       "overflow at runtime; recompile with -fPIC"),
-                     (r_type == elfcpp::R_X86_64_32
-                      ? "R_X86_64_32"
-                      : "R_X86_64_PC32"),
-                     gsym->name());
+       {
+         const char *r_name;
+         switch (r_type)
+           {
+           case elfcpp::R_X86_64_32:
+             r_name = "R_X86_64_32";
+             break;
+           case elfcpp::R_X86_64_PC32:
+             r_name = "R_X86_64_PC32";
+             break;
+           case elfcpp::R_X86_64_PC32_BND:
+             r_name = "R_X86_64_PC32_BND";
+             break;
+           default:
+             gold_unreachable();
+             break;
+           }
+         object->error(_("requires dynamic %s reloc against '%s' "
+                         "which may overflow at runtime; recompile "
+                         "with -fPIC"),
+                       r_name, gsym->name());
+       }
       this->issued_non_pic_error_ = true;
       return;
 
@@ -2368,11 +2387,13 @@ Target_x86_64<size>::Scan::local(Symbol_table* symtab,
 
     case elfcpp::R_X86_64_PC64:
     case elfcpp::R_X86_64_PC32:
+    case elfcpp::R_X86_64_PC32_BND:
     case elfcpp::R_X86_64_PC16:
     case elfcpp::R_X86_64_PC8:
       break;
 
     case elfcpp::R_X86_64_PLT32:
+    case elfcpp::R_X86_64_PLT32_BND:
       // Since we know this is a local symbol, we can handle this as a
       // PC32 reloc.
       break;
@@ -2765,6 +2786,7 @@ Target_x86_64<size>::Scan::global(Symbol_table* symtab,
 
     case elfcpp::R_X86_64_PC64:
     case elfcpp::R_X86_64_PC32:
+    case elfcpp::R_X86_64_PC32_BND:
     case elfcpp::R_X86_64_PC16:
     case elfcpp::R_X86_64_PC8:
       {
@@ -2869,6 +2891,7 @@ Target_x86_64<size>::Scan::global(Symbol_table* symtab,
       break;
 
     case elfcpp::R_X86_64_PLT32:
+    case elfcpp::R_X86_64_PLT32_BND:
       // If the symbol is fully resolved, this is just a PC32 reloc.
       // Otherwise we need a PLT entry.
       if (gsym->final_value_is_known())
@@ -3217,6 +3240,8 @@ Target_x86_64<size>::Relocate::relocate(
   if (this->skip_call_tls_get_addr_)
     {
       if ((r_type != elfcpp::R_X86_64_PLT32
+          && r_type != elfcpp::R_X86_64_PLT32_BND
+          && r_type != elfcpp::R_X86_64_PC32_BND
           && r_type != elfcpp::R_X86_64_PC32)
          || gsym == NULL
          || strcmp(gsym->name(), "__tls_get_addr") != 0)
@@ -3320,6 +3345,7 @@ Target_x86_64<size>::Relocate::relocate(
       break;
 
     case elfcpp::R_X86_64_PC32:
+    case elfcpp::R_X86_64_PC32_BND:
       Relocate_functions<size, false>::pcrela32(view, object, psymval, addend,
                                                address);
       break;
@@ -3343,6 +3369,7 @@ Target_x86_64<size>::Relocate::relocate(
       break;
 
     case elfcpp::R_X86_64_PLT32:
+    case elfcpp::R_X86_64_PLT32_BND:
       gold_assert(gsym == NULL
                  || gsym->has_plt_offset()
                  || gsym->final_value_is_known()
@@ -4151,7 +4178,9 @@ Target_x86_64<size>::Relocatable_size_for_reloc::get_size_for_reloc(
     case elfcpp::R_X86_64_32:
     case elfcpp::R_X86_64_32S:
     case elfcpp::R_X86_64_PC32:
+    case elfcpp::R_X86_64_PC32_BND:
     case elfcpp::R_X86_64_PLT32:
+    case elfcpp::R_X86_64_PLT32_BND:
     case elfcpp::R_X86_64_GOTPC32:
     case elfcpp::R_X86_64_GOT32:
       return 4;