|
| 1 | +; RUN: llc -mtriple=aarch64-linux-gnu %s -o - | FileCheck %s --check-prefixes=CHECK,NOBTI |
| 2 | +; RUN: llc -mtriple=aarch64-none-elf %s -o - | FileCheck %s --check-prefixes=CHECK,NOBTI |
| 3 | +; RUN: llc -mtriple=aarch64-none-macho %s -o - | FileCheck %s --check-prefixes=CHECK,BTI |
| 4 | +; RUN: llc -mtriple=aarch64-windows-msvc %s -o - | FileCheck %s --check-prefixes=CHECK,BTI |
| 5 | + |
| 6 | +;; This function has internal linkage, and nothing in this translation unit |
| 7 | +;; calls it indirectly. So it doesn't need a BTI at the start ... except that |
| 8 | +;; it might, if at link time if the linker inserts a long-branch thunk using a |
| 9 | +;; BLR instruction. |
| 10 | +;; |
| 11 | +;; For ELF targets, both Linux and bare-metal, we expect no BTI instruction at |
| 12 | +;; the start of the function, because AAELF64 specifies that it's not needed: |
| 13 | +;; if the linker wants to do that then it's responsible for making a 'landing |
| 14 | +;; pad' near the target function which _does_ have a BTI, and pointing the |
| 15 | +;; indirect call at that. |
| 16 | +;; |
| 17 | +;; But this is specified in AAELF64, so non-ELF targets can't rely on that |
| 18 | +;; guarantee, and we expect LLVM to insert the BTI anyway. |
| 19 | +define internal void @internal_linkage() "branch-target-enforcement" { |
| 20 | +; CHECK-LABEL: internal_linkage: |
| 21 | +; BTI: hint #34 |
| 22 | +; NOBTI-NOT: hint #34 |
| 23 | +; CHECK: ret |
| 24 | +entry: |
| 25 | + ret void |
| 26 | +} |
| 27 | + |
| 28 | +;; This function has internal linkage but _is_ potentially called indirectly |
| 29 | +;; (its address escapes from the module via external_linkage() below), so it |
| 30 | +;; needs a BTI irrespective of target triple. |
| 31 | +define internal void @indirectly_called() "branch-target-enforcement" { |
| 32 | +; CHECK-LABEL: indirectly_called: |
| 33 | +; CHECK: hint #34 |
| 34 | +; CHECK: ret |
| 35 | +entry: |
| 36 | + ret void |
| 37 | +} |
| 38 | + |
| 39 | +;; This function has external linkage, so it needs a BTI in all circumstances. |
| 40 | +define ptr @external_linkage() "branch-target-enforcement" { |
| 41 | +; CHECK-LABEL: external_linkage: |
| 42 | +; CHECK: hint #34 |
| 43 | +; CHECK: ret |
| 44 | +entry: |
| 45 | + call void @internal_linkage() |
| 46 | + ret ptr @indirectly_called |
| 47 | +} |
0 commit comments