diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2012-08-31 04:26:17 +0000 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2012-08-31 04:26:17 +0000 |
commit | 80d873266deca488bd8059e32780e8ce3ef6191d (patch) | |
tree | 3c0be3e693f706776a6a402516a1f013d75b1d2d /bfd | |
parent | 11cba4accf7f9a82fdb7902f0e36521038eda205 (diff) | |
download | gdb-80d873266deca488bd8059e32780e8ce3ef6191d.zip gdb-80d873266deca488bd8059e32780e8ce3ef6191d.tar.gz gdb-80d873266deca488bd8059e32780e8ce3ef6191d.tar.bz2 |
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')
-rw-r--r-- | bfd/ChangeLog | 10 | ||||
-rw-r--r-- | bfd/elf32-i386.c | 18 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 16 |
3 files changed, 44 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index a26977d..c6f424a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2012-08-30 H.J. Lu <hongjiu.lu@intel.com> + + * 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. + 2012-08-31 Alan Modra <amodra@gmail.com> PR ld/14464 diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 7d3652d..e67879f 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3470,6 +3470,24 @@ elf_i386_relocate_section (bfd *output_bfd, if (off >= (bfd_vma) -2) abort (); + if (h != NULL + && h->def_regular + && SYMBOL_REFERENCES_LOCAL (info, h) + && bfd_get_8 (input_bfd, + contents + rel->r_offset - 2) == 0x8b) + { + /* Convert + mov foo@GOT(%reg), %reg + to + lea foo@GOTOFF(%reg), %reg + */ + bfd_put_8 (output_bfd, 0x8d, + contents + rel->r_offset - 2); + relocation -= (htab->elf.sgotplt->output_section->vma + + htab->elf.sgotplt->output_offset); + break; + } + relocation = htab->elf.sgot->output_section->vma + htab->elf.sgot->output_offset + off - htab->elf.sgotplt->output_section->vma diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index a29ba8a..cc40404 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) |