blob: c7e68d1a8c80496108c6eac62b893d7660899461 [file] [log] [blame]
Fangrui Song0526c0c2019-05-30 10:00:201# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3
4# RUN: ld.lld -shared %t.o -o %t.so
5# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=LD-REL %s
6# RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=LD %s
7
8# RUN: ld.lld %t.o -o %t
9# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
10# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
11
12## Check _TLS_MODULE_BASE_ used by LD produces a dynamic relocation with a value of 0.
13# LD-REL: .rela.dyn {
Fangrui Songd4306e92019-09-16 07:05:3414# LD-REL-NEXT: 0x2318 R_X86_64_TLSDESC - 0x0
Fangrui Song0526c0c2019-05-30 10:00:2015# LD-REL-NEXT: }
16
Fangrui Songd4306e92019-09-16 07:05:3417## 0x2318-0x1267 = 4273
Fangrui Song0526c0c2019-05-30 10:00:2018## dtpoff(a) = 8, dtpoff(b) = 12
Fangrui Songd4306e92019-09-16 07:05:3419# LD: leaq 4273(%rip), %rax
20# LD-NEXT: 1267: callq *(%rax)
Fangrui Song0526c0c2019-05-30 10:00:2021# LD-NEXT: movl %fs:8(%rax), %edx
22# LD-NEXT: addl %fs:12(%rax), %edx
23
24## When producing an executable, the LD code sequence can be relaxed to LE.
25## It is the same as GD->LE.
26## tpoff(_TLS_MODULE_BASE_) = 0, tpoff(a) = -8, tpoff(b) = -4
27
28# NOREL: no relocations
29
30# LE: movq $0, %rax
31# LE-NEXT: nop
32# LE-NEXT: movl %fs:-8(%rax), %edx
33# LE-NEXT: addl %fs:-4(%rax), %edx
34
35leaq _TLS_MODULE_BASE_@tlsdesc(%rip), %rax
36call *_TLS_MODULE_BASE_@tlscall(%rax)
37movl %fs:a@dtpoff(%rax), %edx
38addl %fs:b@dtpoff(%rax), %edx
39
40.section .tbss
41.zero 8
42a:
43.zero 4
44b:
45.zero 4