Browse Source
Linker can't optimize R_386_GOT32 and R_386_GOT32X relocations if addend isn't 0. It isn't valid to convert movl foo@GOT+1(%ecx), %eax to leal foo@GOTOFF+1(%ecx), %eax nor to convert movq foo@GOTPCREL+1(%rip), %rax to leaq foo(%rip), %rax for x86-64. We should check if addend is 0 before optimizing R_386_GOT32 and R_386_GOT32X relocations. Testcases are added for i386 and x86-64. bfd/ * elf32-i386.c (elf_i386_convert_load): Skip if addend isn't 0. (elf_i386_relocate_section): Skip R_386_GOT32X optimization if addend isn't 0. ld/testsuite/ * ld-i386/i386.exp: Run mov2a, mov2b and mov3. * ld-i386/mov2.s: New file. * ld-i386/mov2a.d: Likewise. * ld-i386/mov2b.d: Likewise. * ld-i386/mov3.d: Likewise. * ld-i386/mov3.s: Likewise. * ld-x86-64/mov2.s: Likewise. * ld-x86-64/mov2a.d: Likewise. * ld-x86-64/mov2b.d: Likewise. * ld-x86-64/mov2c.d: Likewise. * ld-x86-64/mov2d.d: Likewise. * ld-x86-64/x86-64.exp: Run mov2a, mov2b, mov2c and mov2d.gdb-7.11-branch
15 changed files with 186 additions and 13 deletions
@ -0,0 +1,15 @@ |
|||
.section my_section,"aw",@progbits |
|||
.long 0x12345678 |
|||
.text |
|||
.globl foo |
|||
.type foo, @function |
|||
foo: |
|||
ret |
|||
.size foo, .-foo |
|||
.globl _start |
|||
.type _start, @function |
|||
_start: |
|||
movl foo@GOT+1(%ecx), %eax |
|||
movl __start_my_section@GOT+1(%ecx), %eax |
|||
movl __stop_my_section@GOT+1(%ecx), %eax |
|||
.size _start, .-_start |
|||
@ -0,0 +1,15 @@ |
|||
#source: mov2.s |
|||
#as: --32 |
|||
#ld: -shared -melf_i386 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 8b 81 ([0-9a-f]{2} ){4} * mov -0x[a-f0-9]+\(%ecx\),%eax |
|||
[ ]*[a-f0-9]+: 8b 81 ([0-9a-f]{2} ){4} * mov -0x[a-f0-9]+\(%ecx\),%eax |
|||
[ ]*[a-f0-9]+: 8b 81 ([0-9a-f]{2} ){4} * mov -0x[a-f0-9]+\(%ecx\),%eax |
|||
#pass |
|||
@ -0,0 +1,15 @@ |
|||
#source: mov2.s |
|||
#as: --32 |
|||
#ld: -pie -melf_i386 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 8b 81 ([0-9a-f]{2} ){4} * mov -0x[a-f0-9]+\(%ecx\),%eax |
|||
[ ]*[a-f0-9]+: 8b 81 ([0-9a-f]{2} ){4} * mov -0x[a-f0-9]+\(%ecx\),%eax |
|||
[ ]*[a-f0-9]+: 8b 81 ([0-9a-f]{2} ){4} * mov -0x[a-f0-9]+\(%ecx\),%eax |
|||
#pass |
|||
@ -0,0 +1,14 @@ |
|||
#as: --32 |
|||
#ld: -melf_i386 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\,%eax |
|||
[ ]*[a-f0-9]+: 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\,%eax |
|||
[ ]*[a-f0-9]+: 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\,%eax |
|||
#pass |
|||
@ -0,0 +1,15 @@ |
|||
.section my_section,"aw",@progbits |
|||
.long 0x12345678 |
|||
.text |
|||
.globl foo |
|||
.type foo, @function |
|||
foo: |
|||
ret |
|||
.size foo, .-foo |
|||
.globl _start |
|||
.type _start, @function |
|||
_start: |
|||
movl foo@GOT+1, %eax |
|||
movl __start_my_section@GOT+1, %eax |
|||
movl __stop_my_section@GOT+1, %eax |
|||
.size _start, .-_start |
|||
@ -0,0 +1,15 @@ |
|||
.section my_section,"aw",@progbits |
|||
.long 0x12345678 |
|||
.text |
|||
.globl foo |
|||
.type foo, @function |
|||
foo: |
|||
ret |
|||
.size foo, .-foo |
|||
.globl _start |
|||
.type _start, @function |
|||
_start: |
|||
movq foo@GOTPCREL+1(%rip), %rax |
|||
movq __start_my_section@GOTPCREL+1(%rip), %rax |
|||
movq __stop_my_section@GOTPCREL+1(%rip), %rax |
|||
.size _start, .-_start |
|||
@ -0,0 +1,15 @@ |
|||
#source: mov2.s |
|||
#as: --64 |
|||
#ld: -shared -melf_x86_64 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
#pass |
|||
@ -0,0 +1,15 @@ |
|||
#source: mov2.s |
|||
#as: --64 |
|||
#ld: -pie -melf_x86_64 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
#pass |
|||
@ -0,0 +1,15 @@ |
|||
#source: mov2.s |
|||
#as: --x32 |
|||
#ld: -shared -melf32_x86_64 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
#pass |
|||
@ -0,0 +1,15 @@ |
|||
#source: mov2.s |
|||
#as: --x32 |
|||
#ld: -pie -melf32_x86_64 |
|||
#objdump: -dw |
|||
|
|||
.*: +file format .* |
|||
|
|||
|
|||
Disassembly of section .text: |
|||
|
|||
#... |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
[ ]*[a-f0-9]+: 48 8b 05 ([0-9a-f]{2} ){4} * mov 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+> |
|||
#pass |
|||
Loading…
Reference in new issue