2015-01-24 11:55:22 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
|
2013-05-11 00:44:02 +08:00
|
|
|
# This tests verifies that TLS variables have correct offsets
|
2013-04-05 02:59:24 +08:00
|
|
|
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 -static \
|
2013-09-23 12:24:15 +08:00
|
|
|
RUN: --output-filetype=yaml --noinhibit-exec | FileCheck %s -check-prefix=YAML
|
2013-02-01 15:14:14 +08:00
|
|
|
|
2013-04-05 03:17:58 +08:00
|
|
|
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tls.x86-64 -o %t \
|
2013-04-05 02:59:24 +08:00
|
|
|
RUN: --noinhibit-exec -e main -static && llvm-objdump -d %t | FileCheck %s
|
2013-02-01 15:13:49 +08:00
|
|
|
|
|
|
|
// Verify that the TLS accesses have the correct offsets.
|
|
|
|
|
2013-04-05 02:59:24 +08:00
|
|
|
YAML: name: main
|
2014-01-27 11:09:26 +08:00
|
|
|
YAML: references:
|
2013-04-05 02:59:24 +08:00
|
|
|
YAML: kind: R_X86_64_TPOFF32
|
|
|
|
YAML: offset: 9
|
|
|
|
YAML: target: tls1
|
|
|
|
YAML: kind: R_X86_64_TPOFF32
|
|
|
|
YAML: offset: 17
|
|
|
|
YAML: target: tls0
|
|
|
|
YAML: kind: R_X86_64_TPOFF32
|
|
|
|
YAML: offset: 25
|
|
|
|
YAML: target: tls2
|
|
|
|
|
|
|
|
YAML: name: GOTTPOFF
|
[ELF/x86_64] Fix initial-exec TLS access
Current approach for initial-exec in ELF/x86_64 is to create a GOT entry
and change the relocation to R_X86_64_PC32 to be handled as a GOT offfset.
However there are two issues with this approach: 1. the R_X86_64_PC32 is
not really required since the GOT relocation will be handle dynamically and
2. the TLS symbols are not being exported externally and then correct
realocation are not being applied.
This patch fixes the R_X86_64_GOTTPOFF handling by just emitting a
R_X86_64_TPOFF64 dynamically one; it also sets R_X86_64_TPOFF64 to be
handled by runtime one. For second part, the patches uses a similar
strategy used for aarch64, by reimplementing buildDynamicSymbolTable
from X86_64ExecutableWriter and adding the TLS symbols in the dynamic
symbol table.
Some tests had to be adjusted due the now missing R_X86_64_PC32 relocation.
With this test the simple testcase:
* t1.c:
__thread int t0;
__thread int t1;
__thread int t2;
__thread int t3;
* t0.c:
extern __thread int t0;
extern __thread int t1;
extern __thread int t2;
extern __thread int t3;
__thread int t4;
__thread int t5;
__thread int t6;
__thread int t7;
int main ()
{
t0 = 1;
t1 = 2;
t2 = 3;
t3 = 4;
t4 = 5;
t5 = 6;
t6 = 7;
t7 = 8;
printf ("%i %i %i %i\n", t0, t1, t2, t3);
printf ("%i %i %i %i\n", t4, t5, t6, t7);
return 0;
}
Shows correct output for x86_64.
llvm-svn: 239908
2015-06-17 22:00:12 +08:00
|
|
|
YAML: kind: R_X86_64_GOTTPOFF
|
2013-04-05 02:59:24 +08:00
|
|
|
YAML: target: [[GOTNAME:[a-zA-Z0-9_]+]]
|
|
|
|
|
ELF: Don't use LayoutPass.
Previously we applied the LayoutPass to order atoms and then
apply elf::ArrayOrderPass to sort them again. The first pass is
basically supposed to sort atoms in the normal fashion (which
is to sort symbols in the same order as the input files).
The second pass sorts atoms in {init,fini}_array.<priority> by
priority.
The problem is that the LayoutPass is overkill. It analyzes
references between atoms to make a decision how to sort them.
It's slow, hard to understand, and above all, it doesn't seem
that we need its feature for ELF in the first place.
This patch remove the LayoutPass from ELF pass list. Now all
reordering is done in elf::OrderPass. That pass sorts atoms by
{init,fini}_array, and if they are not in the special section,
they are ordered as the same order as they appear in the command
line. The new code is far easier to understand, faster, and
still able to create valid executables.
Unlike the previous layout pass, elf::OrderPass doesn't count
any attributes of an atom (e.g. permissions) except its
position. It's OK because the writer takes care of them if we
have to.
This patch changes the order of final output, although that's
benign. Tests are updated.
http://reviews.llvm.org/D7278
llvm-svn: 227666
2015-01-31 10:05:01 +08:00
|
|
|
YAML: type: got
|
|
|
|
YAML: references:
|
|
|
|
YAML: kind: R_X86_64_TPOFF64
|
|
|
|
YAML: target: tls2
|
2013-02-01 15:14:14 +08:00
|
|
|
|
2013-02-06 03:14:07 +08:00
|
|
|
// main
|
2013-02-01 15:14:14 +08:00
|
|
|
CHECK: addl %fs:-4
|
|
|
|
CHECK: addl %fs:-8
|
|
|
|
CHECK: addl %fs:-12
|
|
|
|
|
2013-02-06 03:14:07 +08:00
|
|
|
// GOTTPOFF
|
2013-02-01 15:14:14 +08:00
|
|
|
CHECK: movq {{[0-9]+}}(%rip)
|
2013-02-06 03:14:07 +08:00
|
|
|
|
|
|
|
// TLSLD
|
|
|
|
CHECK: movq %fs:0, %rax
|
|
|
|
CHECK: leaq -8(%rax), %rax
|