xref: /llvm-project/llvm/test/DebugInfo/WebAssembly/tls_pic_globals.ll (revision e1f830bde8bad22d375bc92f2084e9055059cc77)
1; Non-PIC tests
2; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -filetype=obj -mattr=+bulk-memory,atomics - -o %t.localexec.o
3; RUN: sed -e 's/\[\[TLS_MODE\]\]//' %s | llc -filetype=obj -mattr=+bulk-memory,atomics - -o %t.generaldynamic.o
4; RUN: llvm-dwarfdump %t.localexec.o | FileCheck %s --check-prefixes=CHECK,NOPIC
5; RUN: llvm-dwarfdump %t.generaldynamic.o | FileCheck %s --check-prefixes=CHECK,NOPIC
6; RUN: llvm-readobj -r %t.localexec.o | FileCheck %s --check-prefixes=RELOCS-NOSPLIT
7; RUN: llvm-readobj -r %t.generaldynamic.o | FileCheck %s --check-prefixes=RELOCS-NOSPLIT
8
9; PIC tests
10; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -filetype=obj -mattr=+bulk-memory,atomics -relocation-model=pic - -o %t.localexec.pic.o
11; RUN: sed -e 's/\[\[TLS_MODE\]\]//' %s | llc -filetype=obj -mattr=+bulk-memory,atomics -relocation-model=pic - -o %t.generaldynamic.pic.o
12; RUN: llvm-dwarfdump %t.localexec.pic.o | FileCheck %s --check-prefixes=CHECK,PIC
13; RUN: llvm-dwarfdump %t.generaldynamic.pic.o | FileCheck %s --check-prefixes=CHECK,PIC
14; RUN: llvm-readobj -r %t.localexec.pic.o | FileCheck %s --check-prefixes=RELOCS-NOSPLIT,RELOCS-PIC-NOSPLIT
15; RUN: llvm-readobj -r %t.generaldynamic.pic.o | FileCheck %s --check-prefixes=RELOCS-NOSPLIT,RELOCS-PIC-NOSPLIT
16
17; Non-PIC + split DWARF tests
18; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -filetype=obj -mattr=+bulk-memory,atomics -split-dwarf-file=%t.localexec.split.dwo -split-dwarf-output=%t.localexec.split.dwo - -o %t.localexec.split.o
19; RUN: sed -e 's/\[\[TLS_MODE\]\]//' %s | llc -filetype=obj -mattr=+bulk-memory,atomics -split-dwarf-file=%t.generaldynamic.split.dwo -split-dwarf-output=%t.generaldynamic.split.dwo - -o %t.generaldynamic.split.o
20; RUN: llvm-dwarfdump %t.localexec.split.dwo | FileCheck %s --check-prefixes=CHECK,NOPIC
21; RUN: llvm-dwarfdump %t.generaldynamic.split.dwo | FileCheck %s --check-prefixes=CHECK,NOPIC
22; RUN: llvm-readobj -r %t.localexec.split.dwo | FileCheck %s --check-prefixes=RELOCS-SPLIT
23; RUN: llvm-readobj -r %t.generaldynamic.split.dwo | FileCheck %s --check-prefixes=RELOCS-SPLIT
24
25; PIC + split DWARF tests
26; RUN: sed -e 's/\[\[TLS_MODE\]\]/(localexec)/' %s | llc -filetype=obj -mattr=+bulk-memory,atomics -relocation-model=pic -split-dwarf-file=%t.localexec.pic.split.dwo -split-dwarf-output=%t.localexec.pic.split.dwo - -o %t.localexec.pic.split.o
27; RUN: sed -e 's/\[\[TLS_MODE\]\]//' %s | llc -filetype=obj -mattr=+bulk-memory,atomics -relocation-model=pic -split-dwarf-file=%t.generaldynamic.pic.split.dwo -split-dwarf-output=%t.generaldynamic.pic.split.dwo - -o %t.generaldynamic.pic.split.o
28; RUN: llvm-dwarfdump %t.localexec.pic.split.dwo | FileCheck %s --check-prefixes=CHECK,PIC
29; RUN: llvm-dwarfdump %t.generaldynamic.pic.split.dwo | FileCheck %s --check-prefixes=CHECK,PIC
30; RUN: llvm-readobj -r %t.localexec.pic.split.dwo | FileCheck %s --check-prefixes=RELOCS-SPLIT
31; RUN: llvm-readobj -r %t.generaldynamic.pic.split.dwo | FileCheck %s --check-prefixes=RELOCS-SPLIT
32
33; This test is generated from the following C code, after which some unnecessary
34; debug info is removed.
35
36; int external_var0 = 111;
37; int external_var1 = 222;
38; static int internal_var0 = 333;
39; static int internal_var1 = 444;
40; _Thread_local int external_tls_var0 = 555;
41; _Thread_local int external_tls_var1 = 666;
42; _Thread_local int internal_tls_var0 = 777;
43; _Thread_local int internal_tls_var1 = 888;
44;
45; void foo(int, int, int, int, int, int, int, int);
46;
47; void test_tls_pic_globals() {
48;   foo(external_var0, external_var1, internal_var0, internal_var1,
49;       external_tls_var0, external_tls_var1, internal_tls_var0,
50;       internal_tls_var1);
51; }
52
53target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20"
54target triple = "wasm32-unknown-emscripten"
55
56@external_var0 = global i32 111, align 4, !dbg !0
57@external_var1 = global i32 222, align 4, !dbg !5
58@internal_var0 = internal global i32 333, align 4, !dbg !8
59@internal_var1 = internal global i32 444, align 4, !dbg !10
60@external_tls_var0 = thread_local[[TLS_MODE]] global i32 555, align 4, !dbg !12
61@external_tls_var1 = thread_local[[TLS_MODE]] global i32 666, align 4, !dbg !14
62@internal_tls_var0 = internal thread_local[[TLS_MODE]] global i32 777, align 4, !dbg !16
63@internal_tls_var1 = internal thread_local[[TLS_MODE]] global i32 888, align 4, !dbg !18
64
65define void @foo(i32, i32, i32, i32, i32, i32, i32, i32) {
66  ret void
67}
68
69define void @test_tls_pic_globals() !dbg !24 {
70entry:
71  %0 = load i32, ptr @external_var0, align 4
72  %1 = load i32, ptr @external_var1, align 4
73  %2 = load i32, ptr @internal_var0, align 4
74  %3 = load i32, ptr @internal_var1, align 4
75  %4 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @external_tls_var0)
76  %5 = load i32, ptr %4, align 4
77  %6 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @external_tls_var1)
78  %7 = load i32, ptr %6, align 4
79  %8 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @internal_tls_var0)
80  %9 = load i32, ptr %8, align 4
81  %10 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @internal_tls_var1)
82  %11 = load i32, ptr %10, align 4
83  call void @foo(i32 %0, i32 %1, i32 %2, i32 %3, i32 %5, i32 %7, i32 %9, i32 %11)
84  ret void
85}
86
87; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
88declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
89
90attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
91
92!llvm.dbg.cu = !{!2}
93!llvm.module.flags = !{!20, !21, !22, !23}
94
95!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
96!1 = distinct !DIGlobalVariable(name: "external_var0", scope: !2, file: !3, line: 4, type: !7, isLocal: false, isDefinition: true)
97!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4)
98!3 = !DIFile(filename: "test.c", directory: "")
99!4 = !{!0, !5, !8, !10, !12, !14, !16, !18}
100!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
101!6 = distinct !DIGlobalVariable(name: "external_var1", scope: !2, file: !3, line: 4, type: !7, isLocal: false, isDefinition: true)
102!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
103!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
104!9 = distinct !DIGlobalVariable(name: "internal_var0", scope: !2, file: !3, line: 6, type: !7, isLocal: true, isDefinition: true)
105!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
106!11 = distinct !DIGlobalVariable(name: "internal_var1", scope: !2, file: !3, line: 7, type: !7, isLocal: true, isDefinition: true)
107!12 = !DIGlobalVariableExpression(var: !13, expr: !DIExpression())
108!13 = distinct !DIGlobalVariable(name: "external_tls_var0", scope: !2, file: !3, line: 8, type: !7, isLocal: false, isDefinition: true)
109!14 = !DIGlobalVariableExpression(var: !15, expr: !DIExpression())
110!15 = distinct !DIGlobalVariable(name: "external_tls_var1", scope: !2, file: !3, line: 9, type: !7, isLocal: false, isDefinition: true)
111!16 = !DIGlobalVariableExpression(var: !17, expr: !DIExpression())
112!17 = distinct !DIGlobalVariable(name: "internal_tls_var0", scope: !2, file: !3, line: 9, type: !7, isLocal: true, isDefinition: true)
113!18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression())
114!19 = distinct !DIGlobalVariable(name: "internal_tls_var1", scope: !2, file: !3, line: 9, type: !7, isLocal: true, isDefinition: true)
115!20 = !{i32 7, !"Dwarf Version", i32 5}
116!21 = !{i32 2, !"Debug Info Version", i32 3}
117!22 = !{i32 1, !"wchar_size", i32 4}
118!23 = !{i32 8, !"PIC Level", i32 2}
119!24 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 16, type: !25, spFlags: DISPFlagDefinition, unit: !2)
120!25 = !DISubroutineType(types: !26)
121!26 = !{null}
122
123; Tests if TLS variables and global variables in PIC mode have a correct debug
124; info location. TLS variables should have their location relative to __tls_base
125; global, and global variables in PIC objects should have their location
126; relative to __memory_base global.
127
128; CHECK:      DW_TAG_variable
129; CHECK-NEXT:   DW_AT_name  ("external_var0")
130; CHECK:        DW_AT_external  (true)
131; NOPIC:        DW_AT_location  (DW_OP_addrx 0x0)
132; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x0, DW_OP_plus)
133
134; CHECK:      DW_TAG_variable
135; CHECK-NEXT:   DW_AT_name  ("external_var1")
136; CHECK:        DW_AT_external  (true)
137; NOPIC:        DW_AT_location  (DW_OP_addrx 0x1)
138; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x1, DW_OP_plus)
139
140; CHECK:      DW_TAG_variable
141; CHECK-NEXT:   DW_AT_name  ("internal_var0")
142; NOPIC:        DW_AT_location  (DW_OP_addrx 0x2)
143; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x2, DW_OP_plus)
144
145; CHECK:      DW_TAG_variable
146; CHECK-NEXT:   DW_AT_name  ("internal_var1")
147; NOPIC:        DW_AT_location  (DW_OP_addrx 0x3)
148; PIC:          DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x3, DW_OP_plus)
149
150; CHECK:      DW_TAG_variable
151; CHECK-NEXT:   DW_AT_name  ("external_tls_var0")
152; CHECK:        DW_AT_external  (true)
153; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x4, DW_OP_plus)
154
155; CHECK:      DW_TAG_variable
156; CHECK-NEXT:   DW_AT_name  ("external_tls_var1")
157; CHECK:        DW_AT_external  (true)
158; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x5, DW_OP_plus)
159
160; CHECK:      DW_TAG_variable
161; CHECK-NEXT:   DW_AT_name  ("internal_tls_var0")
162; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x6, DW_OP_plus)
163
164; CHECK:      DW_TAG_variable
165; CHECK-NEXT:   DW_AT_name  ("internal_tls_var1")
166; CHECK:        DW_AT_location  (DW_OP_WASM_location 0x3 0x{{[0-9]+}}, DW_OP_addrx 0x7, DW_OP_plus)
167
168; In non-split DWARF, .debug_info section contains relocations referring to
169; __stack_pointer, __tls_base, and __memory_base (if used)
170
171; RELOCS-NOSPLIT:         Relocations [
172; RELOCS-NOSPLIT:           Section (8) .debug_info {
173; RELOCS-NOSPLIT-DAG:         0x{{.*}} R_WASM_GLOBAL_INDEX_I32 __tls_base
174; RELOCS-NOSPLIT-DAG:         0x{{.*}} R_WASM_GLOBAL_INDEX_I32 __stack_pointer
175; RELOCS-PIC-NOSPLIT-DAG:     0x{{.*}} R_WASM_GLOBAL_INDEX_I32 __memory_base
176; RELOCS-NOSPLIT:           }
177; RELOCS-NOSPLIT:           Section (9) .debug_str_offsets {
178
179; In split DWARF, there should be no relocations in .dwo files.
180
181; RELOCS-SPLIT:           Relocations [
182; RELOCS-SPLIT-NEXT:      ]
183