This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold][PATCH] PR gold/17619: Check PC-relative offset overflow in PLT entry
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Cary Coutant <ccoutant at google dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Thu, 20 Nov 2014 08:07:26 -0800
- Subject: Re: [gold][PATCH] PR gold/17619: Check PC-relative offset overflow in PLT entry
- Authentication-results: sourceware.org; auth=none
- References: <20141118193634 dot GA16737 at intel dot com> <CAHACq4pASeVcQQa=iMw+WywpTEmWbnEvqp9DgcxQ1saAtYoo7Q at mail dot gmail dot com> <CAMe9rOrF2ZYJUdewPyHyK_x8uh59b9kMJi=25okGB4JFqnkMVA at mail dot gmail dot com>
On Wed, Nov 19, 2014 at 5:08 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, Nov 19, 2014 at 4:37 PM, Cary Coutant <ccoutant@google.com> wrote:
>>> + // 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"));
>>
>> It would be nice to print more information here. I think it's
>> next-to-impossible at this point to translate the PLT index into a
>
> I will update it.
>
Does this patch look OK? I got
./ld -shared -o libfoo.so gap.o foo.o
./ld: warning: overflow in PLT unwind data; unwinding through PLT may fail
./ld: error: PC-relative offset overflow in PLT entry 1
./ld: error: PC-relative offset overflow in PLT entry 2
make: *** [libfoo.so] Error 1
Thanks.
--
H.J.
From beb0c9c65259e42646ca5bfa61a037c1dc2a27ae Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 18 Nov 2014 11:34:11 -0800
Subject: [PATCH] Check PC-relative offset overflow in PLT entry
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 | 13 ++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 14b764e..c5d854b 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-20 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-20 Alan Modra <amodra@gmail.com>
* powerpc.cc (Stub_control::Stub_control): Init stub14_group_size_
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 1fb601d..25c2d8c 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -1516,11 +1516,18 @@ 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 %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,
--
1.9.3