[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / ppc64-pcrel-call-to-extern.s
blob500132fd88f50c5e9ff5da627020d157dd89da9a
1 # REQUIRES: ppc
2 # RUN: echo 'SECTIONS { \
3 # RUN: .text_caller1 0x10010000 : { *(.text_caller1) } \
4 # RUN: .text_caller2 0x10020000 : { *(.text_caller2) } \
5 # RUN: .text_caller3 0x10030000 : { *(.text_caller3) } \
6 # RUN: }' > %t.script
8 # RUN: llvm-mc -filetype=obj -triple=powerpc64le --defsym AUX=1 %s -o %t1.o
9 # RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t2.o
10 # RUN: ld.lld --shared %t2.o -o %t2.so
11 # RUN: ld.lld -T %t.script %t1.o %t2.so -o %t
12 # RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL
13 # RUN: llvm-readelf -S -d %t | FileCheck %s --check-prefix=SEC
14 # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL
15 # RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s
17 # RUN: llvm-mc -filetype=obj -triple=powerpc64 --defsym AUX=1 %s -o %t1.o
18 # RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t2.o
19 # RUN: ld.lld --shared %t2.o -o %t2.so
20 # RUN: ld.lld -T %t.script %t1.o %t2.so -o %t
21 # RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL
22 # RUN: llvm-readelf -S -d %t | FileCheck %s --check-prefix=SEC
23 # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL
24 # RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s
26 # RUN: llvm-mc -filetype=obj -triple=powerpc64le --defsym AUX=1 %s -o %t1.o
27 # RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t2.o
28 # RUN: ld.lld --shared %t2.o -o %t2.so
29 # RUN: ld.lld -T %t.script %t1.o %t2.so -o %t --no-power10-stubs
30 # RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL-NOP10
31 # RUN: llvm-readelf -S -d %t | FileCheck %s --check-prefix=SEC-NOP10
32 # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL-NOP10
33 # RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s --check-prefix=CHECK-NOP10
35 # RUN: llvm-mc -filetype=obj -triple=powerpc64 --defsym AUX=1 %s -o %t1.o
36 # RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t2.o
37 # RUN: ld.lld --shared %t2.o -o %t2.so
38 # RUN: ld.lld -T %t.script %t1.o %t2.so -o %t --no-power10-stubs
39 # RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYMBOL-NOP10
40 # RUN: llvm-readelf -S -d %t | FileCheck %s --check-prefix=SEC-NOP10
41 # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL-NOP10
42 # RUN: llvm-objdump -d --no-show-raw-insn --mcpu=pwr10 %t | FileCheck %s --check-prefix=CHECK-NOP10
44 ## The test is created to check that when a function without TOC access an
45 ## external function, a r12 setup stub is inserted.
47 # SYMBOL: Symbol table '.dynsym' contains 4 entries:
48 # SYMBOL: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND callee_global_stother0
49 # SYMBOL-NEXT: 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x20>] UND callee_global_stother1
50 # SYMBOL-NEXT: 3: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x60>] UND callee_global_TOC
52 # SYMBOL: Symbol table '.symtab' contains 12 entries:
53 # SYMBOL: 2: 0000000010010000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 6 caller1
54 # SYMBOL-NEXT: 3: 0000000010020000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 7 caller2
55 # SYMBOL-NEXT: 4: 0000000010030000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 8 caller3
56 # SYMBOL: 6: 0000000010010010 32 FUNC LOCAL DEFAULT 6 __plt_pcrel_callee_global_stother0
57 # SYMBOL-NEXT: 7: 0000000010020010 32 FUNC LOCAL DEFAULT 7 __plt_pcrel_callee_global_stother1
58 # SYMBOL-NEXT: 8: 0000000010030010 32 FUNC LOCAL DEFAULT 8 __plt_pcrel_callee_global_TOC
59 # SYMBOL-NEXT: 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND callee_global_stother0
60 # SYMBOL-NEXT: 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x20>] UND callee_global_stother1
61 # SYMBOL-NEXT: 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x60>] UND callee_global_TOC
63 # SYMBOL-NOP10: Symbol table '.symtab' contains 12 entries:
64 # SYMBOL-NOP10: 2: 0000000010010000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 6 caller1
65 # SYMBOL-NOP10-NEXT: 3: 0000000010020000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 7 caller2
66 # SYMBOL-NOP10-NEXT: 4: 0000000010030000 0 NOTYPE LOCAL DEFAULT [<other: 0x20>] 8 caller3
67 # SYMBOL-NOP10: 6: 0000000010010010 32 FUNC LOCAL DEFAULT 6 __plt_pcrel_callee_global_stother0
68 # SYMBOL-NOP10-NEXT: 7: 0000000010020010 32 FUNC LOCAL DEFAULT 7 __plt_pcrel_callee_global_stother1
69 # SYMBOL-NOP10-NEXT: 8: 0000000010030010 32 FUNC LOCAL DEFAULT 8 __plt_pcrel_callee_global_TOC
70 # SYMBOL-NOP10-NEXT: 9: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND callee_global_stother0
71 # SYMBOL-NOP10-NEXT: 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x20>] UND callee_global_stother1
72 # SYMBOL-NOP10-NEXT: 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT [<other: 0x60>] UND callee_global_TOC
74 ## DT_PLTGOT points to .plt
75 # SEC: .plt NOBITS 0000000010030158 040158 000028 00 WA 0 0 8
76 # SEC-OG: .plt NOBITS 0000000010030148 040148 000028 00 WA 0 0 8
77 # SEC: 0x0000000000000003 (PLTGOT) 0x10030158
78 # SEC-OG: 0x0000000000000003 (PLTGOT) 0x10030158
80 ## DT_PLTGOT points to .plt
81 # SEC-NOP10: .plt NOBITS 0000000010030158 040158 000028 00 WA 0 0 8
82 # SEC-NOP10: 0x0000000000000003 (PLTGOT) 0x10030158
84 ## The first 2 entries in the .plt are reserved for the dynamic linkers
85 ## usage. The JMP_SLOT relocations are stored at .plt[2], .plt[3], .plt[4].
86 ## Check that we emit 3 R_PPC64_JMP_SLOT in .rela.plt.
87 # REL: .rela.plt {
88 # REL-NEXT: 0x10030168 R_PPC64_JMP_SLOT callee_global_stother0 0x0
89 # REL-NEXT-OG: 0x10030158 R_PPC64_JMP_SLOT callee_global_stother0 0x0
90 # REL-NEXT: 0x10030170 R_PPC64_JMP_SLOT callee_global_stother1 0x0
91 # REL-NEXT-OG: 0x10030160 R_PPC64_JMP_SLOT callee_global_stother1 0x0
92 # REL-NEXT: 0x10030178 R_PPC64_JMP_SLOT callee_global_TOC 0x0
93 # REL-NEXT-OG: 0x10030168 R_PPC64_JMP_SLOT callee_global_TOC 0x0
94 # REL-NEXT: }
96 # REL-NOP10: .rela.plt {
97 # REL-NOP10-NEXT: 0x10030168 R_PPC64_JMP_SLOT callee_global_stother0 0x0
98 # REL-NOP10-NEXT: 0x10030170 R_PPC64_JMP_SLOT callee_global_stother1 0x0
99 # REL-NOP10-NEXT: 0x10030178 R_PPC64_JMP_SLOT callee_global_TOC 0x0
100 # REL-NOP10-NEXT: }
102 # CHECK-LABEL: <caller1>:
103 # CHECK: 10010000: bl 0x10010010
104 # CHECK-NEXT: 10010004: blr
106 # CHECK-NOP10-LABEL: <caller1>:
107 # CHECK-NOP10: 10010000: bl 0x10010010
108 # CHECK-NOP10-NEXT: 10010004: blr
110 ## .plt[2] - 0x10010010 = 0x10030168 - 0x10010010 = 0x20158 = 131416
111 # CHECK-LABEL: <__plt_pcrel_callee_global_stother0>:
112 # CHECK: 10010010: pld 12, 131416(0), 1
113 # CHECK-NEXT: 10010018: mtctr 12
114 # CHECK-NEXT: 1001001c: bctr
116 ## No P10; branch to next inst to get addr
117 # CHECK-NOP10-LABEL: <__plt_pcrel_callee_global_stother0>:
118 # CHECK-NOP10: 10010010: mflr 0
119 # CHECK-NOP10-NEXT: 10010014: bcl 20, 31, 0x10010018
120 # CHECK-NOP10: 10010018: mflr 11
121 # CHECK-NOP10: 1001001c: mtlr 12
122 # CHECK-NOP10: 10010020: addis 12, 11, -4097
123 # CHECK-NOP10: 10010024: addi 12, 12, -24
124 # CHECK-NOP10-NEXT: 10010028: mtctr 12
125 # CHECK-NOP10-NEXT: 1001002c: bctr
127 # CHECK-LABEL: <caller2>:
128 # CHECK: 10020000: bl 0x10020010
129 # CHECK-NEXT: 10020004: blr
131 # CHECK-NOP10-LABEL: <caller2>:
132 # CHECK-NOP10: 10020000: bl 0x10020010
133 # CHECK-NOP10-NEXT: 10020004: blr
135 ## .plt[3] - 0x10020010 = 0x10030170 - 0x10020010 = 0x10160 = 65888
136 # CHECK-LABEL: <__plt_pcrel_callee_global_stother1>:
137 # CHECK: 10020010: pld 12, 65888(0), 1
138 # CHECK-NEXT: 10020018: mtctr 12
139 # CHECK-NEXT: 1002001c: bctr
141 ## no P10; branch to next inst to get addr
142 # CHECK-NOP10-LABEL: <__plt_pcrel_callee_global_stother1>:
143 # CHECK-NOP10: 10020010: mflr 0
144 # CHECK-NOP10-NEXT: 10020014: bcl 20, 31, 0x10020018
145 # CHECK-NOP10-NEXT: 10020018: mflr 11
146 # CHECK-NOP10-NEXT: 1002001c: mtlr 12
147 # CHECK-NOP10-NEXT: 10020020: addis 12, 11, -4098
148 # CHECK-NOP10-NEXT: 10020024: addi 12, 12, -24
149 # CHECK-NOP10-NEXT: 10020028: mtctr 12
150 # CHECK-NOP10-NEXT: 1002002c: bctr
152 # CHECK-LABEL: <caller3>:
153 # CHECK: 10030000: bl 0x10030010
154 # CHECK-NEXT: 10030004: blr
156 # CHECK-NOP10-LABEL: <caller3>:
157 # CHECK-NOP10: 10030000: bl 0x10030010
158 # CHECK-NOP10-NEXT: 10030004: blr
160 ## .plt[4] - 0x10030010 = 0x10030178 - 0x10030010 = 0x168 = 360
161 # CHECK-LABEL: <__plt_pcrel_callee_global_TOC>:
162 # CHECK: 10030010: pld 12, 360(0), 1
163 # CHECK-NEXT: 10030018: mtctr 12
164 # CHECK-NEXT: 1003001c: bctr
166 ## no P10; branch to next inst to get addr
167 # CHECK-NOP10-LABEL: <__plt_pcrel_callee_global_TOC>:
168 # CHECK-NOP10-NEXT: 10030010: mflr 0
169 # CHECK-NOP10-NEXT: 10030014: bcl 20, 31, 0x10030018
170 # CHECK-NOP10-NEXT: 10030018: mflr 11
171 # CHECK-NOP10-NEXT: 1003001c: mtlr 12
172 # CHECK-NOP10-NEXT: 10030020: addis 12, 11, -4099
173 # CHECK-NOP10-NEXT: 10030024: addi 12, 12, -24
174 # CHECK-NOP10-NEXT: 10030028: mtctr 12
175 # CHECK-NOP10-NEXT: 1003002c: bctr
177 .ifdef AUX
178 .section .text_caller1, "ax", %progbits
179 caller1:
180 .localentry caller1, 1
181 bl callee_global_stother0@notoc
183 .section .text_caller2, "ax", %progbits
184 caller2:
185 .localentry caller2, 1
186 bl callee_global_stother1@notoc
189 .section .text_caller3, "ax", %progbits
190 caller3:
191 .localentry caller3, 1
192 bl callee_global_TOC@notoc
195 .else
196 func_extern:
198 .globl callee_global_stother0
199 callee_global_stother0:
201 .globl callee_global_stother1
202 callee_global_stother1:
203 .localentry callee_global_stother1, 1
204 ## nop is not needed after bl for R_PPC64_REL24_NOTOC
205 bl func_extern@notoc
207 .globl callee_global_TOC
208 callee_global_TOC:
209 .Lfunc_gep1:
210 addis 2, 12, .TOC.-.Lfunc_gep1@ha
211 addi 2, 2, .TOC.-.Lfunc_gep1@l
212 .Lfunc_lep1:
213 .localentry callee_global_TOC, .Lfunc_lep1-.Lfunc_gep1
214 addis 4, 2, global@toc@ha
215 lwz 3, global@toc@l(4)
217 global:
218 .long 0
219 .size global, 4
220 .endif