Skip to content
Snippets Groups Projects
Commit d938ec45 authored by Kristof Beyls's avatar Kristof Beyls
Browse files

[AArch64] Avoid incompatibility between SLSBLR mitigation and BTI codegen.

A "BTI c" instruction only allows jumping/calling to using a BLR* instruction.
However, the SLSBLR mitigation changes a BLR to a BR to implement the
function call. Therefore, a "BTI c" check that passed before could
trigger after the BLR->BL change done by the SLSBLR mitigation.
However, if the register used in BR is X16 or X17, this trigger will not
fire (see ArmARM for further details).

Therefore, this patch simply changes the function stubs for the SLSBLR
mitigation from
__llvm_slsblr_thunk_x<N>:
    br x<N>
    SpeculationBarrier
to
__llvm_slsblr_thunk_x<N>:
    mov x16, x<N>
    br  x16
    SpeculationBarrier

Differential Revision: https://reviews.llvm.org/D81405
parent 1a377055
No related branches found
No related tags found
No related merge requests found
...@@ -223,7 +223,12 @@ void SLSBLRThunkInserter::populateThunk(MachineFunction &MF) { ...@@ -223,7 +223,12 @@ void SLSBLRThunkInserter::populateThunk(MachineFunction &MF) {
// BR xN // BR xN
// barrierInsts // barrierInsts
Entry->addLiveIn(ThunkReg); Entry->addLiveIn(ThunkReg);
BuildMI(Entry, DebugLoc(), TII->get(AArch64::BR)).addReg(ThunkReg); // MOV X16, ThunkReg == ORR X16, XZR, ThunkReg, LSL #0
BuildMI(Entry, DebugLoc(), TII->get(AArch64::ORRXrs), AArch64::X16)
.addReg(AArch64::XZR)
.addReg(ThunkReg)
.addImm(0);
BuildMI(Entry, DebugLoc(), TII->get(AArch64::BR)).addReg(AArch64::X16);
// Make sure the thunks do not make use of the SB extension in case there is // Make sure the thunks do not make use of the SB extension in case there is
// a function somewhere that will call to it that for some reason disabled // a function somewhere that will call to it that for some reason disabled
// the SB extension locally on that function, even though it's enabled for // the SB extension locally on that function, even though it's enabled for
......
...@@ -203,14 +203,16 @@ entry: ...@@ -203,14 +203,16 @@ entry:
} }
; HARDEN-label: __llvm_slsblr_thunk_x0: ; HARDEN-label: __llvm_slsblr_thunk_x0:
; HARDEN: br x0 ; HARDEN: mov x16, x0
; HARDEN: br x16
; ISBDSB-NEXT: dsb sy ; ISBDSB-NEXT: dsb sy
; ISBDSB-NEXT: isb ; ISBDSB-NEXT: isb
; SB-NEXT: dsb sy ; SB-NEXT: dsb sy
; SB-NEXT: isb ; SB-NEXT: isb
; HARDEN-NEXT: .Lfunc_end ; HARDEN-NEXT: .Lfunc_end
; HARDEN-label: __llvm_slsblr_thunk_x19: ; HARDEN-label: __llvm_slsblr_thunk_x19:
; HARDEN: br x19 ; HARDEN: mov x16, x19
; HARDEN: br x16
; ISBDSB-NEXT: dsb sy ; ISBDSB-NEXT: dsb sy
; ISBDSB-NEXT: isb ; ISBDSB-NEXT: isb
; SB-NEXT: dsb sy ; SB-NEXT: dsb sy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment