Check PC-relative offset overflow in PLT entry
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 18 Nov 2014 19:34:11 +0000 (11:34 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 21 Nov 2014 19:26:56 +0000 (11:26 -0800)
PR gold/17619
* x86_64.cc (Output_data_plt_x86_64_standard<size>::do_fill_plt_entry):
Check PC-relative offset overflow in PLT entry.

gold/ChangeLog
gold/x86_64.cc

index 66c7fca37b0afb1abc7953c2bdbca1ea6538c7b4..73e601d8ba0df845010446107bf10efca733960a 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gold/17619
+       * x86_64.cc (Output_data_plt_x86_64_standard<size>::do_fill_plt_entry):
+       Check PC-relative offset overflow in PLT entry.
+
 2014-11-21  Alan Modra  <amodra@gmail.com>
 
        * powerpc.cc (Target_powerpc::Relocate::relocate): Correct test
index 1fb601d30fb9807146a56ba0723838b5932856ae..4baa2bf8eebf7caa258c9934a6674083516a6e44 100644 (file)
@@ -1516,11 +1516,16 @@ Output_data_plt_x86_64_standard<size>::do_fill_plt_entry(
     unsigned int plt_offset,
     unsigned int plt_index)
 {
+  // Check PC-relative offset overflow in PLT entry.
+  uint64_t plt_got_pcrel_offset = (got_address + got_offset
+                                  - (plt_address + plt_offset + 6));
+  if (Bits<32>::has_overflow(plt_got_pcrel_offset))
+    gold_error(_("PC-relative offset overflow in PLT entry %d"),
+              plt_index + 1);
+
   memcpy(pov, plt_entry, plt_entry_size);
   elfcpp::Swap_unaligned<32, false>::writeval(pov + 2,
-                                             (got_address + got_offset
-                                              - (plt_address + plt_offset
-                                                 + 6)));
+                                             plt_got_pcrel_offset);
 
   elfcpp::Swap_unaligned<32, false>::writeval(pov + 7, plt_index);
   elfcpp::Swap<32, false>::writeval(pov + 12,