Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / loongarch-tls-gd.s
blob2aecb44c17a343329a9790c5127a8e63d28e5ac3
1 # REQUIRES: loongarch
2 # RUN: rm -rf %t && split-file %s %t
4 ## LoongArch psABI doesn't specify TLS relaxation. Though the code sequences are not
5 ## relaxed, dynamic relocations can be omitted for GD->LE relaxation.
7 # RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/a.s -o %t/a.32.o
8 # RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/bc.s -o %t/bc.32.o
9 # RUN: ld.lld -shared -soname=bc.so %t/bc.32.o -o %t/bc.32.so
10 # RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/tga.s -o %t/tga.32.o
11 # RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/a.s -o %t/a.64.o
12 # RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/bc.s -o %t/bc.64.o
13 # RUN: ld.lld -shared -soname=bc.so %t/bc.64.o -o %t/bc.64.so
14 # RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/tga.s -o %t/tga.64.o
16 ## LA32 GD
17 # RUN: ld.lld -shared %t/a.32.o %t/bc.32.o -o %t/gd.32.so
18 # RUN: llvm-readobj -r %t/gd.32.so | FileCheck --check-prefix=GD32-REL %s
19 # RUN: llvm-objdump -d --no-show-raw-insn %t/gd.32.so | FileCheck --check-prefix=GD32 %s
21 ## LA32 GD -> LE
22 # RUN: ld.lld %t/a.32.o %t/bc.32.o %t/tga.32.o -o %t/le.32
23 # RUN: llvm-readelf -r %t/le.32 | FileCheck --check-prefix=NOREL %s
24 # RUN: llvm-readelf -x .got %t/le.32 | FileCheck --check-prefix=LE32-GOT %s
25 # RUN: ld.lld -pie %t/a.32.o %t/bc.32.o %t/tga.32.o -o %t/le-pie.32
26 # RUN: llvm-readelf -r %t/le-pie.32 | FileCheck --check-prefix=NOREL %s
27 # RUN: llvm-readelf -x .got %t/le-pie.32 | FileCheck --check-prefix=LE32-GOT %s
29 ## LA32 GD -> IE
30 # RUN: ld.lld %t/a.32.o %t/bc.32.so %t/tga.32.o -o %t/ie.32
31 # RUN: llvm-readobj -r %t/ie.32 | FileCheck --check-prefix=IE32-REL %s
32 # RUN: llvm-readelf -x .got %t/ie.32 | FileCheck --check-prefix=IE32-GOT %s
34 ## LA64 GD
35 # RUN: ld.lld -shared %t/a.64.o %t/bc.64.o -o %t/gd.64.so
36 # RUN: llvm-readobj -r %t/gd.64.so | FileCheck --check-prefix=GD64-REL %s
37 # RUN: llvm-objdump -d --no-show-raw-insn %t/gd.64.so | FileCheck --check-prefix=GD64 %s
39 ## LA64 GD -> LE
40 # RUN: ld.lld %t/a.64.o %t/bc.64.o %t/tga.64.o -o %t/le.64
41 # RUN: llvm-readelf -r %t/le.64 | FileCheck --check-prefix=NOREL %s
42 # RUN: llvm-readelf -x .got %t/le.64 | FileCheck --check-prefix=LE64-GOT %s
43 # RUN: ld.lld -pie %t/a.64.o %t/bc.64.o %t/tga.64.o -o %t/le-pie.64
44 # RUN: llvm-readelf -r %t/le-pie.64 | FileCheck --check-prefix=NOREL %s
45 # RUN: llvm-readelf -x .got %t/le-pie.64 | FileCheck --check-prefix=LE64-GOT %s
47 ## LA64 GD -> IE
48 # RUN: ld.lld %t/a.64.o %t/bc.64.so %t/tga.64.o -o %t/ie.64
49 # RUN: llvm-readobj -r %t/ie.64 | FileCheck --check-prefix=IE64-REL %s
50 # RUN: llvm-readelf -x .got %t/ie.64 | FileCheck --check-prefix=IE64-GOT %s
52 # GD32-REL: .rela.dyn {
53 # GD32-REL-NEXT: 0x20310 R_LARCH_TLS_DTPMOD32 a 0x0
54 # GD32-REL-NEXT: 0x20314 R_LARCH_TLS_DTPREL32 a 0x0
55 # GD32-REL-NEXT: 0x20318 R_LARCH_TLS_DTPMOD32 b 0x0
56 # GD32-REL-NEXT: 0x2031C R_LARCH_TLS_DTPREL32 b 0x0
57 # GD32-REL-NEXT: }
59 ## &DTPMOD(a) - . = 0x20310 - 0x10250: 0x10 pages, page offset 0x310
60 # GD32: 10250: pcalau12i $a0, 16
61 # GD32-NEXT: addi.w $a0, $a0, 784
62 # GD32-NEXT: bl 56
64 ## &DTPMOD(b) - . = 0x20318 - 0x1025c: 0x10 pages, page offset 0x318
65 # GD32: 1025c: pcalau12i $a0, 16
66 # GD32-NEXT: addi.w $a0, $a0, 792
67 # GD32-NEXT: bl 44
69 # GD64-REL: .rela.dyn {
70 # GD64-REL-NEXT: 0x204C0 R_LARCH_TLS_DTPMOD64 a 0x0
71 # GD64-REL-NEXT: 0x204C8 R_LARCH_TLS_DTPREL64 a 0x0
72 # GD64-REL-NEXT: 0x204D0 R_LARCH_TLS_DTPMOD64 b 0x0
73 # GD64-REL-NEXT: 0x204D8 R_LARCH_TLS_DTPREL64 b 0x0
74 # GD64-REL-NEXT: }
76 ## &DTPMOD(a) - . = 0x204c0 - 0x10398: 0x10 pages, page offset 0x4c0
77 # GD64: 10398: pcalau12i $a0, 16
78 # GD64-NEXT: addi.d $a0, $a0, 1216
79 # GD64-NEXT: bl 48
81 ## &DTPMOD(b) - . = 0x204d0 - 0x103a4: 0x10 pages, page offset 0x4d0
82 # GD64: 103a4: pcalau12i $a0, 16
83 # GD64-NEXT: addi.d $a0, $a0, 1232
84 # GD64-NEXT: bl 36
86 # NOREL: no relocations
88 ## .got contains pre-populated values: [a@dtpmod, a@dtprel, b@dtpmod, b@dtprel]
89 ## a@dtprel = st_value(a) = 0x8
90 ## b@dtprel = st_value(b) = 0xc
91 # LE32-GOT: section '.got':
92 # LE32-GOT-NEXT: 0x[[#%x,A:]] 01000000 08000000 01000000 0c000000
93 # LE64-GOT: section '.got':
94 # LE64-GOT-NEXT: 0x[[#%x,A:]] 01000000 00000000 08000000 00000000
95 # LE64-GOT-NEXT: 0x[[#%x,A:]] 01000000 00000000 0c000000 00000000
97 ## a is local - relaxed to LE - its DTPMOD/DTPREL slots are link-time constants.
98 ## b is external - DTPMOD/DTPREL dynamic relocations are required.
99 # IE32-REL: .rela.dyn {
100 # IE32-REL-NEXT: 0x30228 R_LARCH_TLS_DTPMOD32 b 0x0
101 # IE32-REL-NEXT: 0x3022C R_LARCH_TLS_DTPREL32 b 0x0
102 # IE32-REL-NEXT: }
103 # IE32-GOT: section '.got':
104 # IE32-GOT-NEXT: 0x00030220 01000000 08000000 00000000 00000000
106 # IE64-REL: .rela.dyn {
107 # IE64-REL-NEXT: 0x30388 R_LARCH_TLS_DTPMOD64 b 0x0
108 # IE64-REL-NEXT: 0x30390 R_LARCH_TLS_DTPREL64 b 0x0
109 # IE64-REL-NEXT: }
110 # IE64-GOT: section '.got':
111 # IE64-GOT-NEXT: 0x00030378 01000000 00000000 08000000 00000000
112 # IE64-GOT-NEXT: 0x00030388 00000000 00000000 00000000 00000000
114 #--- a.s
115 la.tls.gd $a0, a
116 bl %plt(__tls_get_addr)
118 la.tls.gd $a0, b
119 bl %plt(__tls_get_addr)
121 .section .tbss,"awT",@nobits
122 .globl a
123 .zero 8
125 .zero 4
127 #--- bc.s
128 .section .tbss,"awT",@nobits
129 .globl b, c
131 .zero 4
134 #--- tga.s
135 .globl __tls_get_addr
136 __tls_get_addr: