summaryrefslogtreecommitdiff
path: root/bfd/elf64-x86-64.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-08-31 04:26:16 +0000
committerH.J. Lu <hjl.tools@gmail.com>2012-08-31 04:26:16 +0000
commita0956b173302259572556aefc9608c9879c2aaa8 (patch)
tree8302cb336386cb092191cbce0135de375b390193 /bfd/elf64-x86-64.c
parente7d9ae3cd6e1f55d342749c944ddd09c9a5795bf (diff)
downloadbinutils-redhat-a0956b173302259572556aefc9608c9879c2aaa8.tar.gz
Convert mov to lea for loading local function address
bfd/ * elf32-i386.c (elf_i386_relocate_section): Convert "mov foo@GOT(%reg), %reg" to "lea foo@GOTOFF(%reg), %reg" for local symbols. * elf64-x86-64.c (elf_x86_64_relocate_section): Convert "mov foo@GOTPCREL(%rip), %reg" to "lea foo(%rip), %reg" for local symbols. ld/testsuite/ * ld-i386/i386.exp: Run lea1a, lea1b, lea1c. * ld-x86-64/x86-64.exp: Run lea1a, lea1b, lea1c, lea1d, lea1e, lea1f. * ld-i386/lea1.s: New file. * ld-i386/lea1a.d: Likewise. * ld-i386/lea1b.d: Likewise. * ld-i386/lea1c.d: Likewise. * ld-x86-64/lea1.s: Likewise. * ld-x86-64/lea1a.d: Likewise. * ld-x86-64/lea1b.d: Likewise. * ld-x86-64/lea1c.d: Likewise. * ld-x86-64/lea1d.d: Likewise. * ld-x86-64/lea1e.d: Likewise. * ld-x86-64/lea1f.d: Likewise.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r--bfd/elf64-x86-64.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index a29ba8a324..cc40404d7d 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3460,6 +3460,22 @@ elf_x86_64_relocate_section (bfd *output_bfd,
if (off >= (bfd_vma) -2)
abort ();
+ if (r_type == R_X86_64_GOTPCREL
+ && h->def_regular
+ && SYMBOL_REFERENCES_LOCAL (info, h)
+ && bfd_get_8 (input_bfd,
+ contents + rel->r_offset - 2) == 0x8b)
+ {
+ /* Convert
+ mov foo@GOTPCREL(%rip), %reg
+ to
+ lea foo(%rip), %reg
+ */
+ bfd_put_8 (output_bfd, 0x8d,
+ contents + rel->r_offset - 2);
+ break;
+ }
+
relocation = base_got->output_section->vma
+ base_got->output_offset + off;
if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)