[gold][PATCH] PR gold/17619: Check PC-relative offset overflow in PLT entry

H.J. Lu hongjiu.lu@intel.com
Tue Nov 18 19:36:00 GMT 2014


Hi,

This patch checks PC-relative offset overflow in pushq instruction in
x86-64 PLT entry.  OK for trunk?

Thanks.


H.J.
----
	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 |  6 ++++++
 gold/x86_64.cc | 12 +++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gold/ChangeLog b/gold/ChangeLog
index ec76ab9..e70b29b 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-18  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-13  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* x86_64.cc (Target_x86_64<size>::Scan::global): Don't make PLT
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 1fb601d..3ff1a13 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -1516,11 +1516,17 @@ 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.
+  bool gotplt_after_plt = got_address > plt_address;
+  int32_t plt_got_pcrel_offset = (got_address + got_offset
+				  - (plt_address + plt_offset + 6));
+  if ((gotplt_after_plt && plt_got_pcrel_offset < 0)
+      || (!gotplt_after_plt && plt_got_pcrel_offset > 0))
+    gold_error(_("PC-relative offset overflow in PLT entry"));
+
   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,
-- 
1.9.3



More information about the Binutils mailing list