This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[gold][PATCH] PR gold/17619: Check PC-relative offset overflow in PLT entry
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Cc: ccoutant at google dot com
- Date: Tue, 18 Nov 2014 11:36:34 -0800
- Subject: [gold][PATCH] PR gold/17619: Check PC-relative offset overflow in PLT entry
- Authentication-results: sourceware.org; auth=none
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
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