This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Fri, Nov 21, 2014 at 11:12 AM, Cary Coutant <ccoutant@google.com> wrote:
> +  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))
>
> Please use a uint64_t for the offset, and check for overflow with
> Bits<32>::has_overflow() from reloc.h.
>
> This is OK with that change. Thanks!

This is what I checked in:

>From 9d585188889de38c7191976051d9acdd8d57cbbf 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 | 11 ++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gold/ChangeLog b/gold/ChangeLog
index 66c7fca..73e601d 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -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
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 1fb601d..4baa2bf 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -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,
-- 
1.9.3


Thanks.

H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]