[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / ppc64-tls-gd.s
blob9a1e6fc7455a7aae7912881b4a10ef4dc6647668
1 # REQUIRES: ppc
2 # RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
3 # RUN: echo '.tbss; .globl b, c; b: .zero 4; c:' | llvm-mc -filetype=obj -triple=powerpc64le - -o %t1.o
4 # RUN: ld.lld -shared -soname=t1.so %t1.o -o %t1.so
6 # RUN: ld.lld -shared %t.o %t1.o -o %t.so
7 # RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=GD-REL %s
8 # RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck --check-prefix=GD %s
10 # RUN: ld.lld %t.o %t1.o -o %t
11 # RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
12 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
14 # RUN: ld.lld %t.o %t1.so -o %t
15 # RUN: llvm-readobj -r %t | FileCheck --check-prefix=IE-REL %s
16 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=IE %s
18 # GD-REL: .rela.dyn {
19 # GD-REL-NEXT: 0x20550 R_PPC64_DTPMOD64 a 0x0
20 # GD-REL-NEXT: 0x20558 R_PPC64_DTPREL64 a 0x0
21 # GD-REL-NEXT: 0x20560 R_PPC64_DTPMOD64 b 0x0
22 # GD-REL-NEXT: 0x20568 R_PPC64_DTPREL64 b 0x0
23 # GD-REL-NEXT: 0x20570 R_PPC64_DTPMOD64 c 0x0
24 # GD-REL-NEXT: 0x20578 R_PPC64_DTPREL64 c 0x0
25 # GD-REL-NEXT: }
27 ## Start with .got[1] as .got[0] is the .TOC.
28 ## &DTPMOD(a) - .TOC. = &.got[1] - (.got+0x8000) = -32760
29 # GD: addis 3, 2, 0
30 # GD-NEXT: addi 3, 3, -32760
31 # GD-NEXT: bl 0x10400
32 # GD-NEXT: ld 2, 24(1)
34 ## &DTPMOD(b) - .TOC. = &.got[3] - (.got+0x8000) = -32744
35 # GD-NEXT: addis 3, 2, 0
36 # GD-NEXT: addi 3, 3, -32744
37 # GD-NEXT: bl 0x10400
38 # GD-NEXT: ld 2, 24(1)
40 ## &DTPMOD(b) - .TOC. = &.got[5] - (.got+0x8000) = -32728
41 # GD-NEXT: li 3, -32728
42 # GD-NEXT: bl 0x10400
43 # GD-NEXT: ld 2, 24(1)
45 # NOREL: no relocations
47 ## a@tprel = st_value(a)-0x7000 = -28664
48 # LE: nop
49 # LE-NEXT: addis 3, 13, 0
50 # LE-NEXT: nop
51 # LE-NEXT: addi 3, 3, -28664
52 ## b@tprel = st_value(b)-0x7000 = -28660
53 # LE: nop
54 # LE-NEXT: addis 3, 13, 0
55 # LE-NEXT: nop
56 # LE-NEXT: addi 3, 3, -28660
57 ## c@tprel = st_value(c)-0x7000 = -28656
58 # LE-NEXT: addis 3, 13, 0
59 # LE-NEXT: nop
60 # LE-NEXT: addi 3, 3, -28656
62 # IE-REL: .rela.dyn {
63 # IE-REL-NEXT: 0x10020420 R_PPC64_TPREL64 b 0x0
64 # IE-REL-NEXT: 0x10020428 R_PPC64_TPREL64 c 0x0
65 # IE-REL-NEXT: }
67 ## a is relaxed to use LE.
68 ## a@tprel = st_value(a)-0x7000 = -28664
69 # IE: nop
70 # IE-NEXT: addis 3, 13, 0
71 # IE-NEXT: nop
72 # IE-NEXT: addi 3, 3, -28664
73 ## &DTPMOD(b) - .TOC. = &.got[1] - (.got+0x8000) = -32760
74 # IE-NEXT: addis 3, 2, 0
75 # IE-NEXT: ld 3, -32760(3)
76 # IE-NEXT: nop
77 # IE-NEXT: add 3, 3, 13
78 ## &DTPMOD(c) - .TOC. = &.got[2] - (.got+0x8000) = -32752
79 ## r0 is wrong. R_PPC64_GOT_TLS16 cannot be relaxed to IE but the behavior is
80 ## consistent with ld.bfd
81 # IE-NEXT: ld 3, -32752(0)
82 # IE-NEXT: nop
83 # IE-NEXT: add 3, 3, 13
85 addis 3, 2, a@got@tlsgd@ha
86 addi 3, 3, a@got@tlsgd@l
87 bl __tls_get_addr(a@tlsgd)
88 nop
90 addis 3, 2, b@got@tlsgd@ha
91 addi 3, 3, b@got@tlsgd@l
92 bl __tls_get_addr(b@tlsgd)
93 nop
95 addi 3, 0, c@got@tlsgd
96 bl __tls_get_addr(c@tlsgd)
97 nop
99 .section .tbss
100 .globl a
101 .zero 8
103 .zero 4