This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[gold] PATCH: Properly handle R_X86_64_32 for x32
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Cc: Ian Lance Taylor <iant at google dot com>
- Date: Tue, 10 Jan 2012 12:26:52 -0800
- Subject: [gold] PATCH: Properly handle R_X86_64_32 for x32
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
X32 uses small model in 32bit address space. For PIC, we can keep
R_X86_64_32 or replace it with R_X86_64_RELATIVE for local symbols.
It passes PIE and PIC tests in gold on x32. OK to install?
Thanks.
H.J.
---
2012-01-10 H.J. Lu <hongjiu.lu@intel.com>
* x86_64.cc (Scan::check_non_pic): Allow R_X86_64_32 for x32.
(Scan::local): Use R_X86_64_RELATIVE relocation for R_X86_64_32
under x32.
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 97a440d..3a2cace 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -1971,6 +1971,9 @@ Target_x86_64<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type,
return;
/* Fall through. */
case elfcpp::R_X86_64_32:
+ // R_X86_64_32 is OK for x32.
+ if (size == 32 && r_type == elfcpp::R_X86_64_32)
+ return;
if (this->issued_non_pic_error_)
return;
gold_assert(parameters->options().output_is_position_independent());
@@ -2079,6 +2082,19 @@ Target_x86_64<size>::Scan::local(Symbol_table* symtab,
// because that is always a 64-bit relocation.
if (parameters->options().output_is_position_independent())
{
+ // Use R_X86_64_RELATIVE relocation for R_X86_64_32 under x32.
+ if (size == 32 && r_type == elfcpp::R_X86_64_32)
+ {
+ unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
+ Reloc_section* rela_dyn = target->rela_dyn_section(layout);
+ rela_dyn->add_local_relative(object, r_sym,
+ elfcpp::R_X86_64_RELATIVE,
+ output_section, data_shndx,
+ reloc.get_r_offset(),
+ reloc.get_r_addend(), is_ifunc);
+ break;
+ }
+
this->check_non_pic(object, r_type, NULL);
Reloc_section* rela_dyn = target->rela_dyn_section(layout);