1 # This test exercises a simple general dynamic TLS access model in X86_64.
3 # It is composed of two parts: a program and a shared library. The shared
4 # library uses TLS, but the program does not.
6 # The shared library should import __tls_get_addr, since it uses the general
7 # dynamic TLS access mode (see www.akkadia.org/drepper/tls.pdf). Notice that
8 # once we support TLS strength reduction, this test should be updated, since
9 # this can be converted into a local dynamic TLS model.
12 #RUN: yaml2obj -format=elf %p/Inputs/generaltls-so.o.yaml -o=%t.o.so
13 #RUN: lld -flavor gnu -target x86_64 -shared %t.o.so -o %T/libgeneraltls.so
14 #RUN: yaml2obj -format=elf %s -o=%t.o
16 # Link - (we supply --defsym=__tls_get_addr to avoid the need to link with
18 #RUN: lld -flavor gnu -target x86_64 -e main %t.o -L%T -lgeneraltls -o %t1 \
19 #RUN: --defsym=__tls_get_addr=0
22 #RUN: llvm-readobj -dyn-symbols %t1 | FileCheck -check-prefix CHECKPROG %s
23 #RUN: llvm-readobj -relocations -dyn-symbols %T/libgeneraltls.so | FileCheck \
24 #RUN: -check-prefix CHECKDSO %s
26 # Test case generated with the following code:
28 # DSO: (file %p/Inputs/generaltls-so.o.yaml)
30 # __thread int mynumber=33;
36 # Program: (this file). Note: The printf() relocation was removed to simplify
37 # this test and allow us to test this without libc.
43 # printf("getnumber() = %d\n", getnumber());
57 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
58 AddressAlign: 0x0000000000000010
59 Content: 554889E54883EC10C745FC00000000B000E80000000048BF000000000000000089C6B000E80000000031F68945F889F04883C4105DC3
63 AddressAlign: 0x0000000000000008
66 - Offset: 0x0000000000000012
70 - Offset: 0x0000000000000018
71 Symbol: .rodata.str1.1
76 Flags: [ SHF_WRITE, SHF_ALLOC ]
77 AddressAlign: 0x0000000000000004
81 Flags: [ SHF_WRITE, SHF_ALLOC ]
82 AddressAlign: 0x0000000000000004
84 - Name: .rodata.str1.1
86 Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
87 AddressAlign: 0x0000000000000001
88 Content: 6765746E756D6265722829203D2025640A00
100 - Name: .rodata.str1.1
102 Section: .rodata.str1.1
107 Size: 0x0000000000000036
110 # Program should import the function defined in the shared library
111 #CHECKPROG: getnumber@
112 # Program should not import __tls_get_addr, since it does not directly use TLS
113 #CHECKPROG-NOT: __tls_get_addr@
115 # Check for the presence of X86_64 TLS relocations in the shared library
116 #CHECKDSO: R_X86_64_DTPMOD64
117 #CHECKDSO: R_X86_64_DTPOFF64
118 #CHECKDSO: R_X86_64_JUMP_SLOT
120 # The shared library should import __tls_get_addr, since it uses the general
121 # dynamic TLS access mode.
122 #CHECKDSO: Name: __tls_get_addr@
123 #CHECKDSO-NEXT: Value: 0x0
124 #CHECKDSO-NEXT: Size: 0
125 #CHECKDSO-NEXT: Binding: Global
126 #CHECKDSO-NEXT: Type: None
127 #CHECKDSO-NEXT: Other: 0
128 #CHECKDSO-NEXT: Section: Undefined