[AArch64] Extend AArch64SLSHardeningPass to harden BLR instructions.
authorKristof Beyls <kristof.beyls@arm.com>
Thu, 11 Jun 2020 08:23:15 +0000 (09:23 +0100)
committerKristof Beyls <kristof.beyls@arm.com>
Fri, 12 Jun 2020 06:34:33 +0000 (07:34 +0100)
commitc35ed40f4f1bd8afd709c5342b36f33c7c5b0fbd
tree4d17d00a702435ea511a953f0b489be486beb2f2
parent6f0ce46873b609851634b2c77fc76bf8d580c3c6
[AArch64] Extend AArch64SLSHardeningPass to harden BLR instructions.

To make sure that no barrier gets placed on the architectural execution
path, each
  BLR x<N>
instruction gets transformed to a
  BL __llvm_slsblr_thunk_x<N>
instruction, with __llvm_slsblr_thunk_x<N> a thunk that contains
__llvm_slsblr_thunk_x<N>:
  BR x<N>
  <speculation barrier>

Therefore, the BLR instruction gets split into 2; one BL and one BR.
This transformation results in not inserting a speculation barrier on
the architectural execution path.

The mitigation is off by default and can be enabled by the
harden-sls-blr subtarget feature.

As a linker is allowed to clobber X16 and X17 on function calls, the
above code transformation would not be correct in case a linker does so
when N=16 or N=17. Therefore, when the mitigation is enabled, generation
of BLR x16 or BLR x17 is avoided.

As BLRA* indirect calls are not produced by LLVM currently, this does
not aim to implement support for those.

Differential Revision:  https://reviews.llvm.org/D81402
16 files changed:
llvm/lib/Target/AArch64/AArch64.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64FastISel.cpp
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.h
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AArch64/speculation-hardening-sls-blr.mir [new file with mode: 0644]
llvm/test/CodeGen/AArch64/speculation-hardening-sls.ll