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.
This commit is contained in:
parent
11cba4accf
commit
80d873266d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -1,3 +1,21 @@
|
||||
2012-08-30 H.J. Lu <hongjiu.lu@intel.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2012-08-30 H.J. Lu <hongjiu.lu@intel.com>
|
||||
|
||||
PR ld/14525
|
||||
|
@ -233,6 +233,9 @@ run_dump_test "pr12718"
|
||||
run_dump_test "pr12921"
|
||||
run_dump_test "pr12570a"
|
||||
run_dump_test "pr12570b"
|
||||
run_dump_test "lea1a"
|
||||
run_dump_test "lea1b"
|
||||
run_dump_test "lea1c"
|
||||
|
||||
if { !([istarget "i?86-*-linux*"]
|
||||
|| [istarget "i?86-*-gnu*"]
|
||||
|
11
ld/testsuite/ld-i386/lea1.s
Normal file
11
ld/testsuite/ld-i386/lea1.s
Normal file
@ -0,0 +1,11 @@
|
||||
.text
|
||||
.globl foo
|
||||
.type foo, @function
|
||||
foo:
|
||||
ret
|
||||
.size foo, .-foo
|
||||
.globl _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
movl foo@GOT(%ecx), %eax
|
||||
.size _start, .-_start
|
13
ld/testsuite/ld-i386/lea1a.d
Normal file
13
ld/testsuite/ld-i386/lea1a.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --32
|
||||
#ld: -Bsymbolic -shared -melf_i386
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 8d 81 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%ecx\),%eax
|
||||
#pass
|
13
ld/testsuite/ld-i386/lea1b.d
Normal file
13
ld/testsuite/ld-i386/lea1b.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --32
|
||||
#ld: -pie -melf_i386
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 8d 81 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%ecx\),%eax
|
||||
#pass
|
13
ld/testsuite/ld-i386/lea1c.d
Normal file
13
ld/testsuite/ld-i386/lea1c.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --32
|
||||
#ld: -melf_i386
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 8d 81 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%ecx\),%eax
|
||||
#pass
|
11
ld/testsuite/ld-x86-64/lea1.s
Normal file
11
ld/testsuite/ld-x86-64/lea1.s
Normal file
@ -0,0 +1,11 @@
|
||||
.text
|
||||
.globl foo
|
||||
.type foo, @function
|
||||
foo:
|
||||
ret
|
||||
.size foo, .-foo
|
||||
.globl _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
movq foo@GOTPCREL(%rip), %rax
|
||||
.size _start, .-_start
|
13
ld/testsuite/ld-x86-64/lea1a.d
Normal file
13
ld/testsuite/ld-x86-64/lea1a.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --64
|
||||
#ld: -Bsymbolic -shared -melf_x86_64
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <foo>
|
||||
#pass
|
13
ld/testsuite/ld-x86-64/lea1b.d
Normal file
13
ld/testsuite/ld-x86-64/lea1b.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --64
|
||||
#ld: -pie -melf_x86_64
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <foo>
|
||||
#pass
|
13
ld/testsuite/ld-x86-64/lea1c.d
Normal file
13
ld/testsuite/ld-x86-64/lea1c.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --64
|
||||
#ld: -melf_x86_64
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <foo>
|
||||
#pass
|
13
ld/testsuite/ld-x86-64/lea1d.d
Normal file
13
ld/testsuite/ld-x86-64/lea1d.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --x32
|
||||
#ld: -Bsymbolic -shared -melf32_x86_64
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <foo>
|
||||
#pass
|
13
ld/testsuite/ld-x86-64/lea1e.d
Normal file
13
ld/testsuite/ld-x86-64/lea1e.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --x32
|
||||
#ld: -pie -melf32_x86_64
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <foo>
|
||||
#pass
|
13
ld/testsuite/ld-x86-64/lea1f.d
Normal file
13
ld/testsuite/ld-x86-64/lea1f.d
Normal file
@ -0,0 +1,13 @@
|
||||
#source: lea1.s
|
||||
#as: --x32
|
||||
#ld: -melf32_x86_64
|
||||
#objdump: -dw
|
||||
|
||||
.*: +file format .*
|
||||
|
||||
|
||||
Disassembly of section .text:
|
||||
|
||||
#...
|
||||
[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <foo>
|
||||
#pass
|
@ -276,6 +276,12 @@ run_dump_test "pr13082-5a"
|
||||
run_dump_test "pr13082-5b"
|
||||
run_dump_test "pr13082-6a"
|
||||
run_dump_test "pr13082-6b"
|
||||
run_dump_test "lea1a"
|
||||
run_dump_test "lea1b"
|
||||
run_dump_test "lea1c"
|
||||
run_dump_test "lea1d"
|
||||
run_dump_test "lea1e"
|
||||
run_dump_test "lea1f"
|
||||
|
||||
# Must be native with the C compiler
|
||||
if { [isnative] && [which $CC] != 0 } {
|
||||
|
Loading…
Reference in New Issue
Block a user