brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · f470d83 Raw
130 lines · plain
1// REQUIRES: aarch642// RUN: rm -rf %t && split-file %s %t && cd %t3// RUN: llvm-mc -filetype=obj -triple=aarch64 asm -o a.o4// RUN: ld.lld --script=lds a.o -o out5// RUN: llvm-objdump -d --no-show-raw-insn out | FileCheck %s6 7/// Test that a thunk that at creation time does not need to use a BTI8/// compatible landing pad, but due to other thunk insertion ends up9/// out of short-branch range so a BTI thunk is required after all.10 11//--- asm12.section ".note.gnu.property", "a"13.p2align 314.long 415.long 0x1016.long 0x517.asciz "GNU"18 19/// Enable BTI.20.long 0xc0000000 // GNU_PROPERTY_AARCH64_FEATURE_1_AND.21.long 422.long 1          // GNU_PROPERTY_AARCH64_FEATURE_1_BTI.23.long 024 25.section .text.0, "ax", %progbits26.balign 0x100027.global _start28.type _start, %function29_start:30/// Call that requires a thunk.31 bl fn132 bl fn233/// padding so that the thunk for fn1 is placed after this section is34/// sufficiently close to the target to be within short range, but only35/// just so that a small displacement will mean a long thunk is needed.36 .space 0x100037/// Thunk for call to fn1 will be placed here. Initially it is in short Thunk38/// range of fn1, but due to a thunk added after a later section it won't be39/// and will need a long branch thunk, which in turn needs a BTI landing pad.40 41// CHECK-LABEL: <_start>:42// CHECK-NEXT: 10001000: bl  0x10002008 <__AArch64AbsLongThunk_fn1>43// CHECK-NEXT:           bl  0x10002018 <__AArch64AbsLongThunk_fn2>44 45// CHECK-LABEL: <__AArch64AbsLongThunk_fn1>:46// CHECK-NEXT: 10002008: ldr     x16, 0x10002010 <__AArch64AbsLongThunk_fn1+0x8>47// CHECK-NEXT:           br      x1648// CHECK-NEXT:           00 30 00 18    .word   0x1800300049// CHECK-NEXT:           00 00 00 00    .word   0x0000000050 51// CHECK-LABEL: <__AArch64AbsLongThunk_fn2>:52// CHECK-NEXT: 10002018: ldr     x16, 0x10002020 <__AArch64AbsLongThunk_fn2+0x8>53// CHECK-NEXT:           br      x1654// CHECK-NEXT:           04 40 00 18    .word   0x1800400455// CHECK-NEXT:           00 00 00 00    .word   0x0000000056 57.section .text.1, "ax", %progbits58.balign 0x100059.global farcall60.type farcall, %function61farcall:62/// Call that requires a thunk.63 bl far64/// Section is aligned to 0x1000 boundary with size multipe of 0x1000.65.space 0x1000 - (. - farcall)66/// Thunk for call to far will be placed here. This will force text.267/// on to the next alignment boundary, moving it further away from the68/// thunk inserted in the .text_low output section.69 70// CHECK-LABEL: <farcall>:71// CHECK-NEXT: 18001000: bl      0x18002000 <__AArch64AbsLongThunk_far>72 73// CHECK-LABEL: <__AArch64AbsLongThunk_far>:74// CHECK-NEXT: 18002000: ldr     x16, 0x18002008 <__AArch64AbsLongThunk_far+0x8>75// CHECK-NEXT:           br      x1676// CHECK-NEXT:           00 00 00 30   .word   0x3000000077// CHECK-NEXT:           00 00 00 00   .word   0x0000000078 79.section .text.2, "ax", %progbits80.balign 0x100081.global fn182.type fn1, %function83fn1:84 ret85 86.section .text.3, "ax", %progbits87.global fn288.type fn2, %function89fn2:90 ret91 92.section .text.far, "ax", %progbits93.type far, %function94.global far95far:96 ret97 98// CHECK-LABEL: <__AArch64BTIThunk_fn1>:99// CHECK-NEXT: 18003000: bti     c100// CHECK-NExT:           b       0x18004000 <fn1>101 102// CHECK-LABEL: <fn1>:103// CHECK-NEXT: 18004000: ret104 105// CHECK-LABEL: <__AArch64BTIThunk_fn2>:106// CHECK-NEXT: 18004004:       bti     c107 108// CHECK-LABEL: <fn2>:109// CHECK-NEXT: 18004008:       ret110 111// CHECK-LABEL: <__AArch64BTIThunk_far>:112// CHECK-NEXT: 30000000: bti     c113 114// CHECK-LABEL: <far>:115// CHECK-NEXT: 30000004: ret116 117//--- lds118PHDRS {119  low PT_LOAD FLAGS(0x1 | 0x4);120  mid PT_LOAD FLAGS(0x1 | 0x4);121  high PT_LOAD FLAGS(0x1 | 0x4);122}123SECTIONS {124  .rodata 0x10000000 : { *(.note.gnu.property) } :low125  .text_low : { *(.text.0) } :low126  .text 0x18001000 : { *(.text.1) } :mid127  .text_aligned : { *(.text.2) *(.text.3) } :mid128  .text_high 0x30000000 : { *(.text.far) } :high129}130