|
| 1 | +#--WeakUndefTLS.test----------Executable--------# |
| 2 | +BEGIN_COMMENT |
| 3 | +# Test R_X86_64_TPOFF32/64 and R_X86_64_DTPOFF32/64 relocations against |
| 4 | +# weak undefined TLS symbols. A weak undefined TLS symbol has no TLS slot, |
| 5 | +# so the tpoff formula must not run; the result is the addend only (= 0 |
| 6 | +# for the common case). Mirrors lld's R_TPREL guard: |
| 7 | +# if (sym.isUndefined()) return a; |
| 8 | +# Also verifies that defined TLS symbols are unaffected (regression guard). |
| 9 | +#END_COMMENT |
| 10 | + |
| 11 | +#START_TEST |
| 12 | + |
| 13 | +# Case 1: TPOFF32 + weak-undef -> 0x00000000 |
| 14 | +RUN: %clang %clangopts -c %p/Inputs/weak_tls_le.s -o %t.le.o |
| 15 | +RUN: %link %linkopts -static %t.le.o -o %t.le.exe |
| 16 | +RUN: llvm-objdump -s -j .data %t.le.exe | FileCheck %s --check-prefix=LE32 |
| 17 | + |
| 18 | +# Case 2: TPOFF64 + weak-undef -> 0x0000000000000000 |
| 19 | +RUN: %clang %clangopts -c %p/Inputs/weak_tls_le64.s -o %t.le64.o |
| 20 | +RUN: %link %linkopts -static %t.le64.o -o %t.le64.exe |
| 21 | +RUN: llvm-objdump -s -j .data %t.le64.exe | FileCheck %s --check-prefix=LE64 |
| 22 | + |
| 23 | +# Case 3: DTPOFF32 + weak-undef -> 0x00000000 |
| 24 | +RUN: %clang %clangopts -c %p/Inputs/weak_tls_ld.s -o %t.ld.o |
| 25 | +RUN: %link %linkopts -static %t.ld.o -o %t.ld.exe |
| 26 | +RUN: llvm-objdump -s -j .data %t.ld.exe | FileCheck %s --check-prefix=LD32 |
| 27 | + |
| 28 | +# Case 4: DTPOFF64 + weak-undef -> 0x0000000000000000 |
| 29 | +RUN: %clang %clangopts -c %p/Inputs/weak_tls_ld64.s -o %t.ld64.o |
| 30 | +RUN: %link %linkopts -static %t.ld64.o -o %t.ld64.exe |
| 31 | +RUN: llvm-objdump -s -j .data %t.ld64.exe | FileCheck %s --check-prefix=LD64 |
| 32 | + |
| 33 | +# Case 5: TPOFF32 + defined symbol -> -4 = 0xfffffffc (regression guard) |
| 34 | +RUN: %clang %clangopts -c %p/Inputs/weak_tls_defined.s -o %t.def.o |
| 35 | +RUN: %link %linkopts -static %t.def.o -o %t.def.exe |
| 36 | +RUN: llvm-objdump -s -j .data %t.def.exe | FileCheck %s --check-prefix=DEFINED |
| 37 | + |
| 38 | +# Case 6: TPOFF32 + weak-undef + addend=2 -> 0x00000002 |
| 39 | +RUN: %clang %clangopts -c %p/Inputs/weak_tls_le_addend.s -o %t.addend.o |
| 40 | +RUN: %link %linkopts -static %t.addend.o -o %t.addend.exe |
| 41 | +RUN: llvm-objdump -s -j .data %t.addend.exe | FileCheck %s --check-prefix=ADDEND |
| 42 | + |
| 43 | +LE32: Contents of section .data: |
| 44 | +LE32-NEXT: {{[0-9a-f]+}} 00000000 |
| 45 | + |
| 46 | +LE64: Contents of section .data: |
| 47 | +LE64-NEXT: {{[0-9a-f]+}} 00000000 00000000 |
| 48 | + |
| 49 | +LD32: Contents of section .data: |
| 50 | +LD32-NEXT: {{[0-9a-f]+}} 00000000 |
| 51 | + |
| 52 | +LD64: Contents of section .data: |
| 53 | +LD64-NEXT: {{[0-9a-f]+}} 00000000 00000000 |
| 54 | + |
| 55 | +DEFINED: Contents of section .data: |
| 56 | +DEFINED-NEXT: {{[0-9a-f]+}} fcffffff |
| 57 | + |
| 58 | +ADDEND: Contents of section .data: |
| 59 | +ADDEND-NEXT: {{[0-9a-f]+}} 02000000 |
| 60 | + |
| 61 | +#END_TEST |
0 commit comments