Fangrui Song | 0526c0c | 2019-05-30 10:00:20 | [diff] [blame] | 1 | # 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 Song | d4306e9 | 2019-09-16 07:05:34 | [diff] [blame] | 14 | # LD-REL-NEXT: 0x2318 R_X86_64_TLSDESC - 0x0 |
Fangrui Song | 0526c0c | 2019-05-30 10:00:20 | [diff] [blame] | 15 | # LD-REL-NEXT: } |
| 16 | |
Fangrui Song | d4306e9 | 2019-09-16 07:05:34 | [diff] [blame] | 17 | ## 0x2318-0x1267 = 4273 |
Fangrui Song | 0526c0c | 2019-05-30 10:00:20 | [diff] [blame] | 18 | ## dtpoff(a) = 8, dtpoff(b) = 12 |
Fangrui Song | d4306e9 | 2019-09-16 07:05:34 | [diff] [blame] | 19 | # LD: leaq 4273(%rip), %rax |
| 20 | # LD-NEXT: 1267: callq *(%rax) |
Fangrui Song | 0526c0c | 2019-05-30 10:00:20 | [diff] [blame] | 21 | # 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 | |
| 35 | leaq _TLS_MODULE_BASE_@tlsdesc(%rip), %rax |
| 36 | call *_TLS_MODULE_BASE_@tlscall(%rax) |
| 37 | movl %fs:a@dtpoff(%rax), %edx |
| 38 | addl %fs:b@dtpoff(%rax), %edx |
| 39 | |
| 40 | .section .tbss |
| 41 | .zero 8 |
| 42 | a: |
| 43 | .zero 4 |
| 44 | b: |
| 45 | .zero 4 |