This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] PR gold/18609
- From: Andrew Senkevich <andrew dot n dot senkevich at gmail dot com>
- To: ccoutant at gmail dot com
- Cc: binutils at sourceware dot org, "H.J. Lu" <hjl dot tools at gmail dot com>
- Date: Thu, 9 Jul 2015 16:49:54 +0300
- Subject: [PATCH] PR gold/18609
- Authentication-results: sourceware.org; auth=none
Hi,
this patch fixes https://sourceware.org/bugzilla/show_bug.cgi?id=18609
Is it ok?
2015-07-09 Andrew Senkevich <andrew.senkevich@intel.com>
* gold/x86_64.cc: Added overflow check for converting
R_X86_64_GOTPCREL to R_X86_64_PC32.
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 007af1d..0c66525 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -2480,23 +2480,6 @@ Target_x86_64<size>::Scan::local(Symbol_table* symtab,
// The symbol requires a GOT section.
Output_data_got<64, false>* got = target->got_section(symtab, layout);
- // If the relocation symbol isn't IFUNC,
- // and is local, then we will convert
- // mov foo@GOTPCREL(%rip), %reg
- // to lea foo(%rip), %reg.
- // in Relocate::relocate.
- if (r_type == elfcpp::R_X86_64_GOTPCREL
- && reloc.get_r_offset() >= 2
- && !is_ifunc)
- {
- section_size_type stype;
- const unsigned char* view = object->section_contents(data_shndx,
- &stype, true);
- if (view[reloc.get_r_offset() - 2] == 0x8b)
- break;
- }
-
-
// The symbol requires a GOT entry.
unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
@@ -2906,21 +2889,6 @@ Target_x86_64<size>::Scan::global(Symbol_table* symtab,
// The symbol requires a GOT entry.
Output_data_got<64, false>* got = target->got_section(symtab, layout);
- // If we convert this from
- // mov foo@GOTPCREL(%rip), %reg
- // to lea foo(%rip), %reg.
- // in Relocate::relocate, then there is nothing to do here.
- if (r_type == elfcpp::R_X86_64_GOTPCREL
- && reloc.get_r_offset() >= 2
- && Target_x86_64<size>::can_convert_mov_to_lea(gsym))
- {
- section_size_type stype;
- const unsigned char* view = object->section_contents(data_shndx,
- &stype, true);
- if (view[reloc.get_r_offset() - 2] == 0x8b)
- break;
- }
-
if (gsym->final_value_is_known())
{
// For a STT_GNU_IFUNC symbol we want the PLT address.
@@ -3543,7 +3511,9 @@ Target_x86_64<size>::Relocate::relocate(
// mov foo@GOTPCREL(%rip), %reg
// to lea foo(%rip), %reg.
// if possible.
- if (rela.get_r_offset() >= 2
+ int64_t x = psymval->value(object, addend) - address;
+ if (x == static_cast<int64_t>(static_cast<int32_t>(x))
+ && rela.get_r_offset() >= 2
&& view[-2] == 0x8b
&& ((gsym == NULL && !psymval->is_ifunc_symbol())
|| (gsym != NULL
--
WBR,
Andrew