]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/elf/X86_64/general-dynamic-tls.test
Vendor import of lld trunk r233088:
[FreeBSD/FreeBSD.git] / test / elf / X86_64 / general-dynamic-tls.test
1 # This test exercises a simple general dynamic TLS access model in X86_64.
2 #
3 # It is composed of two parts: a program and a shared library. The shared
4 # library uses TLS, but the program does not.
5 #
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.
10
11 # Prepare inputs
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
15
16 # Link - (we supply --defsym=__tls_get_addr to avoid the need to link with
17 # system libraries)
18 #RUN: lld -flavor gnu  -target x86_64 -e main %t.o -L%T -lgeneraltls -o %t1 \
19 #RUN:   --defsym=__tls_get_addr=0
20
21 # Check
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
25
26 # Test case generated with the following code:
27 #
28 # DSO: (file %p/Inputs/generaltls-so.o.yaml)
29 #
30 # __thread int mynumber=33;
31 #
32 # int getnumber() {
33 #     return mynumber;
34 # }
35 #
36 # Program: (this file). Note: The printf() relocation was removed to simplify
37 # this test and allow us to test this without libc.
38 #
39 # #include <stdio.h>
40 # int getnumber();
41 #
42 # int main() {
43 #     printf("getnumber() = %d\n", getnumber());
44 #     return 0;
45 # }
46 #
47 ---
48 FileHeader:
49   Class:           ELFCLASS64
50   Data:            ELFDATA2LSB
51   OSABI:           ELFOSABI_GNU
52   Type:            ET_REL
53   Machine:         EM_X86_64
54 Sections:
55   - Name:            .text
56     Type:            SHT_PROGBITS
57     Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
58     AddressAlign:    0x0000000000000010
59     Content:         554889E54883EC10C745FC00000000B000E80000000048BF000000000000000089C6B000E80000000031F68945F889F04883C4105DC3
60   - Name:            .rela.text
61     Type:            SHT_RELA
62     Link:            .symtab
63     AddressAlign:    0x0000000000000008
64     Info:            .text
65     Relocations:
66       - Offset:          0x0000000000000012
67         Symbol:          getnumber
68         Type:            R_X86_64_PC32
69         Addend:          -4
70       - Offset:          0x0000000000000018
71         Symbol:          .rodata.str1.1
72         Type:            R_X86_64_64
73         Addend:          0
74   - Name:            .data
75     Type:            SHT_PROGBITS
76     Flags:           [ SHF_WRITE, SHF_ALLOC ]
77     AddressAlign:    0x0000000000000004
78     Content:         ''
79   - Name:            .bss
80     Type:            SHT_NOBITS
81     Flags:           [ SHF_WRITE, SHF_ALLOC ]
82     AddressAlign:    0x0000000000000004
83     Content:         ''
84   - Name:            .rodata.str1.1
85     Type:            SHT_PROGBITS
86     Flags:           [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
87     AddressAlign:    0x0000000000000001
88     Content:         6765746E756D6265722829203D2025640A00
89 Symbols:
90   Local:
91     - Name:            .text
92       Type:            STT_SECTION
93       Section:         .text
94     - Name:            .data
95       Type:            STT_SECTION
96       Section:         .data
97     - Name:            .bss
98       Type:            STT_SECTION
99       Section:         .bss
100     - Name:            .rodata.str1.1
101       Type:            STT_SECTION
102       Section:         .rodata.str1.1
103   Global:
104     - Name:            main
105       Type:            STT_FUNC
106       Section:         .text
107       Size:            0x0000000000000036
108     - Name:            getnumber
109
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@
114
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
119
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
129