[PATCH] D57753: [AArch64][Outliner] Don't outline BTI instructions

Oliver Stannard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 07:29:05 PST 2019


olista01 created this revision.
olista01 added reviewers: paquette, LukeCheeseman.
Herald added subscribers: kristof.beyls, javed.absar.
Herald added a project: LLVM.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D57753

Files:
  lib/Target/AArch64/AArch64InstrInfo.cpp
  test/CodeGen/AArch64/machine-outliner-outline-bti.ll


Index: test/CodeGen/AArch64/machine-outliner-outline-bti.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AArch64/machine-outliner-outline-bti.ll
@@ -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
+}
Index: lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- lib/Target/AArch64/AArch64InstrInfo.cpp
+++ lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -5369,6 +5369,14 @@
       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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57753.185308.patch
Type: text/x-patch
Size: 1516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190205/8ea08f0d/attachment.bin>


More information about the llvm-commits mailing list