Optimize R_386_GOT32/R_386_GOT32X only if addend is 0
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 4 Dec 2015 16:43:45 +0000 (08:43 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 4 Dec 2015 17:03:04 +0000 (09:03 -0800)
commit02e2aef89bb58e8e0cc4390db41c5f775e1b7c3e
tree323891844d56806214ca3851131d40cea1d8fc68
parentf27c5390b2fcff06b1e2199a4f051d543670aa03
Optimize R_386_GOT32/R_386_GOT32X only if addend is 0

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.
15 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
ld/testsuite/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/mov2.s [new file with mode: 0644]
ld/testsuite/ld-i386/mov2a.d [new file with mode: 0644]
ld/testsuite/ld-i386/mov2b.d [new file with mode: 0644]
ld/testsuite/ld-i386/mov3.d [new file with mode: 0644]
ld/testsuite/ld-i386/mov3.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/mov2.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/mov2a.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/mov2b.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/mov2c.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/mov2d.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp
This page took 0.028465 seconds and 4 git commands to generate.