[PATCH] X86: Work around a bfd ld quirk wrt GOTTPOFF relocation processing
H.J. Lu
hjl.tools at gmail.com
Mon Jan 5 05:48:40 PST 2015
On Mon, Jan 5, 2015 at 2:44 AM, David Majnemer <david.majnemer at gmail.com> wrote:
> Hi chandlerc, echristo, hansw, rafael,
>
> bfd ld has a quirk which surfaces when transitioning a initial-exec
> model relocation to a local-exec style code sequence.
>
> However, it expects the R_X86_64_GOTTPOFF relocation to target a movq or
> addq instruction and will fatally error if we have shrunk the load to a
> movl or addl.
>
> Work around this by prohibiting the truncation of such loads.
>
> This fixes PR22083.
>
> N.B. It could be argued that this isn't a bug in bfd ld because the
> "ELF Handling for Thread-Local Storage" declares that GOTTPOFF be used
> with addq and movq exclusively. However, bfd ld is happy to 'Do The
It is due to the requirement of the REX prefix for IE->LE optimization:
https://sourceware.org/bugzilla/show_bug.cgi?id=17482
You can force a REX prefix with addl/movl.
> Right Thing' (TM) in X32 mode and gold has no qualms acting on a
The x32 assembler was changed to:
[hjl at gnu-tools-1 tmp]$ cat x.s
mov foo at gottpoff(%rip), %r12
mov foo at gottpoff(%rip), %eax
add foo at gottpoff(%rip), %r12
add foo at gottpoff(%rip), %eax
[hjl at gnu-tools-1 tmp]$ gcc -mx32 x.s -c
[hjl at gnu-tools-1 tmp]$ objdump -dwr x.o
x.o: file format elf32-x86-64
Disassembly of section .text:
00000000 <.text>:
0: 4c 8b 25 00 00 00 00 mov 0x0(%rip),%r12 # 0x7 3:
R_X86_64_GOTTPOFF foo-0x4
7: 40 8b 05 00 00 00 00 rex mov 0x0(%rip),%eax # 0xe a:
R_X86_64_GOTTPOFF foo-0x4
e: 4c 03 25 00 00 00 00 add 0x0(%rip),%r12 # 0x15 11:
R_X86_64_GOTTPOFF foo-0x4
15: 40 03 05 00 00 00 00 rex add 0x0(%rip),%eax # 0x1c 18:
R_X86_64_GOTTPOFF foo-0x4
[hjl at gnu-tools-1 tmp]$
A REX prefix is always added for addl/movl if it isn't there already.
> movl/addl.
>
--
H.J.
More information about the llvm-commits
mailing list