2 // RUN
: rm
-rf
%t && split-file
%s
%t && cd
%t
3 // RUN
: llvm-mc
-filetype
=obj
-triple
=aarch64 asm
-o
a.o
4 // RUN
: ld.lld
--shared
--script
=lds
a.o
-o out.so
--defsym absolute
=0xf0000000
5 // RUN
: llvm-objdump
-d
--no-show-raw-insn out.so | FileCheck
%s
6 // RUN
: llvm-objdump
-d
--no-show-raw-insn out.so | FileCheck
%s
--check-prefix
=CHECK-PADS
7 // RUN
: llvm-mc
-filetype
=obj
-triple
=aarch64 shared
-o shared.o
8 // RUN
: ld.lld
--shared
-o shared.so shared.o
9 // RUN
: ld.lld shared.so
--script
=lds
a.o
-o exe
--defsym absolute
=0xf0000000
10 // RUN
: llvm-objdump
-d
--no-show-raw-insn exe | FileCheck
%s
--check-prefix
=CHECK-EXE
11 // RUN
: llvm-objdump
-d
--no-show-raw-insn exe | FileCheck
%s
--check-prefix
=CHECK-PADS
13 /// Test thunk generation when destination does
not have
a BTI compatible
14 /// landing pad. Linker must generate landing pad sections for thunks that use
15 /// indirect branches.
18 .section ".note.gnu.property", "a"
26 .long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND.
28 .long 1 // GNU_PROPERTY_AARCH64_FEATURE_1_BTI.
32 /// Short thunks are direct branches so we don
't need landing pads. Expect
33 /// all thunks to branch directly to target.
34 .section .text.0, "ax", %progbits
37 .type _start, %function
44 bl .text.2 + 0x4 // fn2
45 b .text.2 + 0x4 // fn2
53 /// We cannot add landing pads for absolute symbols.
56 /// padding so that we require thunks that can be placed after this section.
57 /// The thunks are close enough to the target to be short.
60 // CHECK-PADS-LABEL: <_start>:
61 // CHECK-PADS-NEXT: 10001000: bl 0x1000203c
62 // CHECK-PADS-NEXT: bl 0x10002040
63 // CHECK-PADS-NEXT: bl 0x10002044
64 // CHECK-PADS-NEXT: bl 0x10002048
65 // CHECK-PADS-NEXT: bl 0x1000204c
66 // CHECK-PADS-NEXT: bl 0x10002050
67 // CHECK-PADS-NEXT: b 0x10002050
68 // CHECK-PADS-NEXT: bl 0x10002054
69 // CHECK-PADS-NEXT: b 0x10002054
70 // CHECK-PADS-NEXT: bl 0x10002058
71 // CHECK-PADS-NEXT: b 0x10002058
72 // CHECK-PADS-NEXT: bl 0x1000205c
73 // CHECK-PADS-NEXT: b 0x1000205c
74 // CHECK-PADS-NEXT: bl 0x10002060
75 // CHECK-PADS-NEXT: bl 0x10002064
77 // CHECK-LABEL: <__AArch64ADRPThunk_>:
78 // CHECK-NEXT: 1000203c: b 0x18001000 <bti_c_target>
80 // CHECK-LABEL: <__AArch64ADRPThunk_>:
81 // CHECK-NEXT: 10002040: b 0x18001008 <bti_j_target>
83 // CHECK-LABEL: <__AArch64ADRPThunk_>:
84 // CHECK-NEXT: 10002044: b 0x18001010 <bti_jc_target>
86 // CHECK-LABEL: <__AArch64ADRPThunk_>:
87 // CHECK-NEXT: 10002048: b 0x18001018 <paciasp_target>
89 // CHECK-LABEL: <__AArch64ADRPThunk_>:
90 // CHECK-NEXT: 1000204c: b 0x18001020 <pacibsp_target>
92 // CHECK-LABEL: <__AArch64ADRPThunk_>:
93 // CHECK-NEXT: 10002050: b 0x18001038 <fn2>
95 // CHECK-LABEL: <__AArch64ADRPThunk_>:
96 // CHECK-NEXT: 10002054: b 0x18001034 <fn1>
98 // CHECK-LABEL: <__AArch64ADRPThunk_>:
99 // CHECK-NEXT: 10002058: b 0x18001040 <fn3>
101 // CHECK-LABEL: <__AArch64ADRPThunk_>:
102 // CHECK-NEXT: 1000205c: b 0x18001050 <fn4>
104 // CHECK-LABEL: <__AArch64ADRPThunk_via_plt>:
105 // CHECK-NEXT: 10002060: b 0x18001080 <via_plt@plt>
107 // CHECK-LABEL: <__AArch64ADRPThunk_absolute>:
108 // CHECK-NEXT: 10002064: b 0x18001098 <absolute@plt>
110 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
111 // CHECK-EXE-NEXT: 1000203c: b 0x18001000 <bti_c_target>
113 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
114 // CHECK-EXE-NEXT: 10002040: b 0x18001008 <bti_j_target>
116 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
117 // CHECK-EXE-NEXT: 10002044: b 0x18001010 <bti_jc_target>
119 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
120 // CHECK-EXE-NEXT: 10002048: b 0x18001018 <paciasp_target>
122 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
123 // CHECK-EXE-NEXT: 1000204c: b 0x18001020 <pacibsp_target>
125 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
126 // CHECK-EXE-NEXT: 10002050: b 0x18001038 <fn2>
128 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
129 // CHECK-EXE-NEXT: 10002054: b 0x18001034 <fn1>
131 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
132 // CHECK-EXE-NEXT: 10002058: b 0x18001040 <fn3>
134 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_>:
135 // CHECK-EXE-NEXT: 1000205c: b 0x18001050 <fn4>
137 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_via_plt>:
138 // CHECK-EXE-NEXT: 10002060: b 0x18001080 <via_plt@plt>
140 // CHECK-EXE-LABEL: <__AArch64AbsLongThunk_absolute>:
141 // CHECK-EXE-NEXT: 10002064: ldr x16, 0x1000206c <__AArch64AbsLongThunk_absolute+0x8>
142 // CHECK-EXE-NEXT: br x16
143 // CHECK-EXE-NEXT: 00 00 00 f0 .word 0xf0000000
144 // CHECK-EXE-NEXT: 00 00 00 00 .word 0x00000000
146 .section .text.1, "ax", %progbits
147 /// These indirect branch targets already have a BTI compatible landing pad,
148 /// no alternative entry point required.
150 .type bti_c_target, %function
156 .type bti_j_target, %function
161 .hidden bti_jc_target
162 .type bti_jc_target, %function
167 .hidden paciasp_target
168 .type paciasp_target, %function
173 .hidden pacibsp_target
174 .type pacibsp_target, %function
179 // CHECk-PADS-LABEL: <bti_c_target>:
180 // CHECK-PADS: 18001000: bti c
181 // CHECK-PADS-NEXT: ret
183 // CHECK-PADS-LABEL: <bti_j_target>:
184 // CHECK-PADS-NEXT: 18001008: bti j
185 // CHECK-PADS-NEXT: ret
187 // CHECK-PADS-LABEL: <bti_jc_target>:
188 // CHECK-PADS-NEXT: 18001010: bti jc
189 // CHECK-PADS-NEXT: ret
191 // CHECK-PADS-LABEL: <paciasp_target>:
192 // CHECK-PADS-NEXT: 18001018: paciasp
193 // CHECK-PADS-NEXT: ret
195 // CHECK-PADS-LABEL: <pacibsp_target>:
196 // CHECK-PADS-NEXT: 18001020: pacibsp
197 // CHECK-PADS-NEXT: ret
199 /// These functions do not have BTI compatible landing pads. Expect linker
200 /// generated landing pads for indirect branch thunks.
201 .section .text.2, "ax", %progbits
211 // CHECK-PADS-LABEL: <__AArch64BTIThunk_>:
212 // CHECK-PADS-NEXT: 18001028: bti c
213 // CHECK-PADS-NEXT: b 0x18001038 <fn2>
215 // CHECK-PADS-LABEL: <__AArch64BTIThunk_>:
216 // CHECK-PADS-NEXT: 18001030: bti c
218 // CHECK-PADS-LABEL: <fn1>:
219 // CHECK-PADS-NEXT: 18001034: ret
221 // CHECK-PADS-LABEL <fn2>:
222 // CHECK-PADS: 18001038: ret
224 /// Section with only one function at offset 0. Landing pad should be able to
226 .section .text.3, "ax", %progbits
232 // CHECK-PADS-LABEL: <__AArch64BTIThunk_>:
233 // CHECK-PADS-NEXT: 1800103c: bti c
235 // CHECK-PADS-LABEL: <fn3>:
236 // CHECK-PADS-NEXT: 18001040: ret
238 /// Section with only one function at offset 0, also with a high alignment
239 /// requirement. Check that we don't fall through into alignment padding.
240 .section .text.4, "ax", %progbits
247 // CHECK-PADS-LABEL
: <__AArch64BTIThunk_
>:
248 // CHECK-PADS
: 18001044: bti c
249 // CHECK-PADS-NEXT
: b 0x18001050 <fn4
>
250 // CHECK-PADS-NEXT
: udf
#0x0
252 // CHECK-PADS-LABEL
: <fn4
>:
253 // CHECK-PADS-NEXT
: 18001050: ret
255 .section .long_calls, "ax", %progbits
257 .type long_calls, %function
259 /// Expect thunk to target as targets have BTI
or implicit BTI.
265 /// Expect thunk to target
a linker generated entry point with BTI landing pad.
266 /// Two calls to make sure only one landing pad is created.
267 bl .text.2 + 0x4 // fn2
268 b .text.2 + 0x4 // fn2
269 /// fn2 before fn1 so that landing pad for fn1 can fall through.
276 /// PLT entries reachable via Thunks have
a BTI c at the start of each entry
277 /// so no additional landing pad required.
279 /// We cannot
add landing pads for absolute symbols.
282 /// PLT entries have BTI at start.
283 // CHECK-LABEL
: <via_plt@plt
>:
285 // CHECK-NEXT
: adrp x16
, 0x30000000
286 // CHECK-NEXT
: ldr x17
, [x16
, #0x198]
287 // CHECK-NEXT
: add x16
, x16
, #0x198
288 // CHECK-NEXT
: br x17
291 // CHECK
: <absolute@plt
>:
293 // CHECK-NEXT
: adrp x16
, 0x30000000
294 // CHECK-NEXT
: ldr x17
, [x16
, #0x1a0]
295 // CHECK-NEXT
: add x16
, x16
, #0x1a0
296 // CHECK-NEXT
: br x17
299 // CHECK-EXE-LABEL
: <via_plt@plt
>:
300 // CHECK-EXE-NEXT
: 18001080: bti c
301 // CHECK-EXE-NEXT
: adrp x16
, 0x30000000
302 // CHECK-EXE-NEXT
: ldr x17
, [x16
, #0x1e8]
303 // CHECK-EXE-NEXT
: add x16
, x16
, #0x1e8
304 // CHECK-EXE-NEXT
: br x17
305 // CHECK-EXE-NEXT
: nop
307 // CHECK-LABEL
: <long_calls
>:
308 // CHECK-NEXT
: 30000000: bl 0x3000003c <__AArch64ADRPThunk_
>
309 // CHECK-NEXT
: bl 0x30000048 <__AArch64ADRPThunk_
>
310 // CHECK-NEXT
: bl 0x30000054 <__AArch64ADRPThunk_
>
311 // CHECK-NEXT
: bl 0x30000060 <__AArch64ADRPThunk_
>
312 // CHECK-NEXT
: bl 0x3000006c <__AArch64ADRPThunk_
>
313 // CHECK-NEXT
: bl 0x30000078 <__AArch64ADRPThunk_
>
314 // CHECK-NEXT
: b 0x30000078 <__AArch64ADRPThunk_
>
315 // CHECK-NEXT
: bl 0x30000084 <__AArch64ADRPThunk_
>
316 // CHECK-NEXT
: b 0x30000084 <__AArch64ADRPThunk_
>
317 // CHECK-NEXT
: bl 0x30000090 <__AArch64ADRPThunk_
>
318 // CHECK-NEXT
: b 0x30000090 <__AArch64ADRPThunk_
>
319 // CHECK-NEXT
: bl 0x3000009c <__AArch64ADRPThunk_
>
320 // CHECK-NEXT
: b 0x3000009c <__AArch64ADRPThunk_
>
321 // CHECK-NEXT
: bl 0x300000a8 <__AArch64ADRPThunk_via_plt
>
322 // CHECK-NEXT
: bl 0x300000b4 <__AArch64ADRPThunk_absolute
>
325 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
326 // CHECK-NEXT
: 3000003c
: adrp x16
, 0x18001000 <bti_c_target
>
327 // CHECK-NEXT
: add x16
, x16
, #0x0
328 // CHECK-NEXT
: br x16
330 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
331 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
332 // CHECK-NEXT
: add x16
, x16
, #0x8
333 // CHECK-NEXT
: br x16
335 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
336 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
337 // CHECK-NEXT
: add x16
, x16
, #0x10
338 // CHECK-NEXT
: br x16
340 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
341 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
342 // CHECK-NEXT
: add x16
, x16
, #0x18
343 // CHECK-NEXT
: br x16
345 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
346 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
347 // CHECK-NEXT
: add x16
, x16
, #0x20
348 // CHECK-NEXT
: br x16
349 /// Landing pad for fn2.
350 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
351 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
352 // CHECK-NEXT
: add x16
, x16
, #0x28
353 // CHECK-NEXT
: br x16
354 /// Landing pad for fn1.
355 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
356 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
357 // CHECK-NEXT
: add x16
, x16
, #0x30
358 // CHECK-NEXT
: br x16
359 /// Landing pad for fn3.
360 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
361 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
362 // CHECK-NEXT
: add x16
, x16
, #0x3c
363 // CHECK-NEXT
: br x16
364 /// Landing pad for fn4.
365 // CHECK-LABEL
: <__AArch64ADRPThunk_
>:
366 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
367 // CHECK-NEXT
: add x16
, x16
, #0x44
368 // CHECK-NEXT
: br x16
370 // CHECK-LABEL
: <__AArch64ADRPThunk_via_plt
>:
371 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
372 // CHECK-NEXT
: add x16
, x16
, #0x80
373 // CHECK-NEXT
: br x16
375 // CHECK-LABEL
: <__AArch64ADRPThunk_absolute
>:
376 // CHECK-NEXT
: adrp x16
, 0x18001000 <bti_c_target
>
377 // CHECK-NEXT
: add x16
, x16
, #0x98
378 // CHECK-NEXT
: br x16
380 // CHECK-EXE-LABEL
: <long_calls
>:
381 // CHECK-EXE-NEXT
: 30000000: bl 0x3000003c <__AArch64AbsLongThunk_
>
382 // CHECK-EXE-NEXT
: bl 0x3000004c <__AArch64AbsLongThunk_
>
383 // CHECK-EXE-NEXT
: bl 0x3000005c <__AArch64AbsLongThunk_
>
384 // CHECK-EXE-NEXT
: bl 0x3000006c <__AArch64AbsLongThunk_
>
385 // CHECK-EXE-NEXT
: bl 0x3000007c <__AArch64AbsLongThunk_
>
386 // CHECK-EXE-NEXT
: bl 0x3000008c <__AArch64AbsLongThunk_
>
387 // CHECK-EXE-NEXT
: b 0x3000008c <__AArch64AbsLongThunk_
>
388 // CHECK-EXE-NEXT
: bl 0x3000009c <__AArch64AbsLongThunk_
>
389 // CHECK-EXE-NEXT
: b 0x3000009c <__AArch64AbsLongThunk_
>
390 // CHECK-EXE-NEXT
: bl 0x300000ac <__AArch64AbsLongThunk_
>
391 // CHECK-EXE-NEXT
: b 0x300000ac <__AArch64AbsLongThunk_
>
392 // CHECK-EXE-NEXT
: bl 0x300000bc <__AArch64AbsLongThunk_
>
393 // CHECK-EXE-NEXT
: b 0x300000bc <__AArch64AbsLongThunk_
>
394 // CHECK-EXE-NEXT
: bl 0x300000cc <__AArch64AbsLongThunk_via_plt
>
395 // CHECK-EXE-NEXT
: bl 0x300000dc <__AArch64AbsLongThunk_absolute
>
397 // CHECK-EXE-LABEL
: 000000003000003c
<__AArch64AbsLongThunk_
>:
398 // CHECK-EXE-NEXT
: 3000003c
: ldr x16
, 0x30000044 <__AArch64AbsLongThunk_+
0x8>
399 // CHECK-EXE-NEXT
: br x16
400 // CHECK-EXE-NEXT
: 00 10 00 18 .word 0x18001000
401 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
403 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
404 // CHECK-EXE-NEXT
: 3000004c
: ldr x16
, 0x30000054 <__AArch64AbsLongThunk_+
0x8>
405 // CHECK-EXE-NEXT
: br x16
406 // CHECK-EXE-NEXT
: 08 10 00 18 .word 0x18001008
407 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
409 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
410 // CHECK-EXE-NEXT
: 3000005c
: ldr x16
, 0x30000064 <__AArch64AbsLongThunk_+
0x8>
411 // CHECK-EXE-NEXT
: br x16
412 // CHECK-EXE-NEXT
: 10 10 00 18 .word 0x18001010
413 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
415 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
416 // CHECK-EXE-NEXT
: 3000006c
: ldr x16
, 0x30000074 <__AArch64AbsLongThunk_+
0x8>
417 // CHECK-EXE-NEXT
: br x16
418 // CHECK-EXE-NEXT
: 18 10 00 18 .word 0x18001018
419 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
421 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
422 // CHECK-EXE-NEXT
: 3000007c
: ldr x16
, 0x30000084 <__AArch64AbsLongThunk_+
0x8>
423 // CHECK-EXE-NEXT
: br x16
424 // CHECK-EXE-NEXT
: 20 10 00 18 .word 0x18001020
425 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
427 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
428 // CHECK-EXE-NEXT
: 3000008c
: ldr x16
, 0x30000094 <__AArch64AbsLongThunk_+
0x8>
429 // CHECK-EXE-NEXT
: br x16
430 // CHECK-EXE-NEXT
: 28 10 00 18 .word 0x18001028
431 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
433 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
434 // CHECK-EXE-NEXT
: 3000009c
: ldr x16
, 0x300000a4 <__AArch64AbsLongThunk_+
0x8>
435 // CHECK-EXE-NEXT
: br x16
436 // CHECK-EXE-NEXT
: 30 10 00 18 .word 0x18001030
437 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
439 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
440 // CHECK-EXE-NEXT
: 300000ac
: ldr x16
, 0x300000b4 <__AArch64AbsLongThunk_+
0x8>
441 // CHECK-EXE-NEXT
: br x16
442 // CHECK-EXE-NEXT
: 3c
10 00 18 .word 0x1800103c
443 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
445 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_
>:
446 // CHECK-EXE-NEXT
: 300000bc: ldr x16
, 0x300000c4 <__AArch64AbsLongThunk_+
0x8>
447 // CHECK-EXE-NEXT
: br x16
448 // CHECK-EXE-NEXT
: 44 10 00 18 .word 0x18001044
449 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
451 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_via_plt
>:
452 // CHECK-EXE-NEXT
: 300000cc
: ldr x16
, 0x300000d4 <__AArch64AbsLongThunk_via_plt+
0x8>
453 // CHECK-EXE-NEXT
: br x16
454 // CHECK-EXE-NEXT
: 80 10 00 18 .word 0x18001080
455 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
457 // CHECK-EXE-LABEL
: <__AArch64AbsLongThunk_absolute
>:
458 // CHECK-EXE-NEXT
: 300000dc
: ldr x16
, 0x300000e4 <__AArch64AbsLongThunk_absolute+
0x8>
459 // CHECK-EXE-NEXT
: br x16
460 // CHECK-EXE-NEXT
: 00 00 00 f0 .word 0xf0000000
461 // CHECK-EXE-NEXT
: 00 00 00 00 .word 0x00000000
465 low PT_LOAD FLAGS
(0x1 |
0x4);
466 mid PT_LOAD FLAGS
(0x1 |
0x4);
467 high PT_LOAD FLAGS
(0x1 |
0x4);
470 .rodata 0x10000000 : { *(.note.gnu.property) } :low
471 .text_low : { *(.text.0) } :low
472 .text 0x18001000 : { *(.text.*) } :mid
473 .plt : { *(.plt) } :mid
474 .text_high 0x30000000 : { *(.long_calls) } :high
480 .type via_plt, %function