[AArch64][v8.5A] Restrict indirect tail calls to use x16/17 only when using BTI
When branch target identification is enabled, all indirectly-callable
functions start with a BTI C instruction. this instruction can only be
the target of certain indirect branches (direct branches and
fall-through are not affected):
- A BLR instruction, in either a protected or unprotected page.
- A BR instruction in a protected page, using x16 or x17.
- A BR instruction in an unprotected page, using any register.
Without BTI, we can use any non call-preserved register to hold the
address for an indirect tail call. However, when BTI is enabled, then
the code being compiled might be loaded into a BTI-protected page, where
only x16 and x17 can be used for indirect tail calls.
Legacy code withiout this restriction can still indirectly tail-call
BTI-protected functions, because they will be loaded into an unprotected
page, so any register is allowed.
Differential revision: https://reviews.llvm.org/D52868
llvm-svn: 343968
2018-10-08 22:09:15 +08:00
|
|
|
; RUN: llc -mtriple aarch64--none-eabi -mattr=+bti < %s | FileCheck %s
|
2019-09-06 04:18:34 +08:00
|
|
|
; RUN: llc -mtriple aarch64--none-eabi -global-isel -global-isel-abort=2 -pass-remarks-missed=gisel* -mattr=+bti %s -verify-machineinstrs -o - 2>&1 | FileCheck %s --check-prefixes=CHECK,FALLBACK
|
|
|
|
|
|
|
|
; FALLBACK: remark: <unknown>:0:0: unable to translate instruction: call: ' tail call void %p()' (in function: bti_enabled)
|
[AArch64][v8.5A] Restrict indirect tail calls to use x16/17 only when using BTI
When branch target identification is enabled, all indirectly-callable
functions start with a BTI C instruction. this instruction can only be
the target of certain indirect branches (direct branches and
fall-through are not affected):
- A BLR instruction, in either a protected or unprotected page.
- A BR instruction in a protected page, using x16 or x17.
- A BR instruction in an unprotected page, using any register.
Without BTI, we can use any non call-preserved register to hold the
address for an indirect tail call. However, when BTI is enabled, then
the code being compiled might be loaded into a BTI-protected page, where
only x16 and x17 can be used for indirect tail calls.
Legacy code withiout this restriction can still indirectly tail-call
BTI-protected functions, because they will be loaded into an unprotected
page, so any register is allowed.
Differential revision: https://reviews.llvm.org/D52868
llvm-svn: 343968
2018-10-08 22:09:15 +08:00
|
|
|
|
|
|
|
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
|
|
|
|
target triple = "aarch64-arm-none-eabi"
|
|
|
|
|
|
|
|
; When BTI is enabled, all indirect tail-calls must use x16 or x17 (the intra
|
|
|
|
; procedure call scratch registers) to hold the address, as these instructions
|
|
|
|
; are allowed to target the "BTI c" instruction at the start of the target
|
|
|
|
; function. The alternative to this would be to start functions with "BTI jc",
|
|
|
|
; which increases the number of potential ways they could be called, and
|
|
|
|
; weakens the security protections.
|
|
|
|
|
|
|
|
define void @bti_disabled(void ()* %p) {
|
|
|
|
entry:
|
|
|
|
tail call void %p()
|
|
|
|
; CHECK: br x0
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @bti_enabled(void ()* %p) "branch-target-enforcement" {
|
|
|
|
entry:
|
|
|
|
tail call void %p()
|
|
|
|
; CHECK: br {{x16|x17}}
|
|
|
|
ret void
|
|
|
|
}
|