This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] PR gold/18695
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Andrew Senkevich <andrew dot n dot senkevich at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Wed, 26 Aug 2015 06:13:48 -0700
- Subject: Re: [PATCH] PR gold/18695
- Authentication-results: sourceware.org; auth=none
- References: <CAMXFM3t6BrUdey=bSO0XKVsSGuDs5uM9sEywyCGV1rm_hk9Tmw at mail dot gmail dot com>
On Wed, Aug 26, 2015 at 6:11 AM, Andrew Senkevich
<andrew.n.senkevich@gmail.com> wrote:
> Hi,
>
> is this patch ok?
>
> 2015-08-26 Andrew Senkevich <andrew.senkevich@intel.com>
>
> PR gold/18695
> * x86_64.cc: Overflow checks added.
>
> diff --git a/gold/x86_64.cc b/gold/x86_64.cc
> index 007af1d..2d0712f 100644
> --- a/gold/x86_64.cc
> +++ b/gold/x86_64.cc
> @@ -3320,6 +3320,32 @@ Target_x86_64<size>::do_finalize_sections(
> }
> }
>
> +template<int size, int valsize>
> +class x86_64_overflow_check
> +{
> +public:
> + typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
> +
> + static inline bool
> + has_overflow_signed(Address value)
> + {
> + // limit = 1 << (valsize - 1) without shift count exceeding size of type
> + Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
> + limit <<= ((valsize - 1) >> 1);
> + limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
> + return value + limit > (limit << 1) - 1;
> + }
> +
> + static inline bool
> + has_overflow_unsigned(Address value)
> + {
> + Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
> + limit <<= ((valsize - 1) >> 1);
> + limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
> + return value > (limit << 1) - 1;
> + }
> +};
> +
> // Perform a relocation.
Shouldn't there be generic address overflow checks which can be used
by all targets?
--
H.J.