[llvm] r353190 - [AArch64][Outliner] Don't outline BTI instructions

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 09:21:57 PST 2019


Author: olista01
Date: Tue Feb  5 09:21:57 2019
New Revision: 353190

URL: http://llvm.org/viewvc/llvm-project?rev=353190&view=rev
Log:
[AArch64][Outliner] Don't outline BTI instructions

We can't outline BTI instructions, because they need to be the very first
instruction executed after an indirect call or branch. If we outline them, then
an indirect call might go to the branch to the outlined function, which will
fault.

Differential revision: https://reviews.llvm.org/D57753


Added:
    llvm/trunk/test/CodeGen/AArch64/machine-outliner-outline-bti.ll
Modified:
    llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp

Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp?rev=353190&r1=353189&r2=353190&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp Tue Feb  5 09:21:57 2019
@@ -5330,6 +5330,14 @@ AArch64InstrInfo::getOutliningType(Machi
       MI.modifiesRegister(AArch64::W30, &getRegisterInfo()))
     return outliner::InstrType::Illegal;
 
+  // Don't outline BTI instructions, because that will prevent the outlining
+  // site from being indirectly callable.
+  if (MI.getOpcode() == AArch64::HINT) {
+    int64_t Imm = MI.getOperand(0).getImm();
+    if (Imm == 32 || Imm == 34 || Imm == 36 || Imm == 38)
+      return outliner::InstrType::Illegal;
+  }
+
   return outliner::InstrType::Legal;
 }
 

Added: llvm/trunk/test/CodeGen/AArch64/machine-outliner-outline-bti.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/machine-outliner-outline-bti.ll?rev=353190&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/machine-outliner-outline-bti.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/machine-outliner-outline-bti.ll Tue Feb  5 09:21:57 2019
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple aarch64--none-eabi < %s | FileCheck %s
+
+; The BTI instruction cannot be outlined, because it needs to be the very first
+; instruction executed after an indirect call.
+
+ at g = hidden global i32 0, align 4
+
+define hidden void @foo() minsize "branch-target-enforcement" {
+entry:
+; CHECK: hint #34
+; CHECK: b       OUTLINED_FUNCTION_0
+  store volatile i32 1, i32* @g, align 4
+  ret void
+}
+
+define hidden void @bar() minsize "branch-target-enforcement" {
+entry:
+; CHECK: hint #34
+; CHECK: b       OUTLINED_FUNCTION_0
+  store volatile i32 1, i32* @g, align 4
+  ret void
+}




More information about the llvm-commits mailing list