[PATCH] D134999: AArch64: PAC: Do not attempt ICP on authenticating calls.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 16:43:42 PDT 2022


pcc created this revision.
pcc added reviewers: ab, tejohnson.
Herald added subscribers: wenlei, hiraditya, kristof.beyls.
Herald added a project: All.
pcc requested review of this revision.
Herald added a project: LLVM.

Not only would the check that we would produce be incorrect since it
would not account for the fact that the function pointer would be signed,
we would also end up producing invalid IR as the call on the direct call
branch would have a ptrauth operand bundle. Therefore, do not ICP these
calls for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134999

Files:
  llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
  llvm/test/Transforms/SampleProfile/Inputs/indirect-call.prof
  llvm/test/Transforms/SampleProfile/indirect-call.ll


Index: llvm/test/Transforms/SampleProfile/indirect-call.ll
===================================================================
--- llvm/test/Transforms/SampleProfile/indirect-call.ll
+++ llvm/test/Transforms/SampleProfile/indirect-call.ll
@@ -134,6 +134,18 @@
   ret void
 }
 
+; CHECK-LABEL: @branch_prof_ptrauth
+; Make sure that we don't attempt ICP when the call includes an authentication
+; instruction.
+define void @branch_prof_ptrauth(ptr %t0) #0 !dbg !36 {
+  %t1 = alloca ptr
+  store ptr %t0, ptr %t1
+  %t2 = load ptr, ptr %t1
+  ; CHECK-NOT: br i1
+  call void %t2() [ "ptrauth"(i32 0, i64 0) ], !dbg !37
+  ret void
+}
+
 @x = global i32 0, align 4
 @y = global ptr null, align 8
 
@@ -234,3 +246,5 @@
 !33 = distinct !DISubprogram(name: "branch_prof_valid", scope: !1, file: !1, line: 25, unit: !0)
 !34 = !DILocation(line: 27, scope: !33)
 !35 = distinct !DISubprogram(name: "foo_inline3", scope: !1, file: !1, line: 29, unit: !0)
+!36 = distinct !DISubprogram(name: "branch_prof_ptrauth", scope: !1, file: !1, line: 30, unit: !0)
+!37 = !DILocation(line: 32, scope: !36)
Index: llvm/test/Transforms/SampleProfile/Inputs/indirect-call.prof
===================================================================
--- llvm/test/Transforms/SampleProfile/Inputs/indirect-call.prof
+++ llvm/test/Transforms/SampleProfile/Inputs/indirect-call.prof
@@ -34,3 +34,8 @@
  2: foo_inline3:3000
   1: 0
   2: 3000
+branch_prof_ptrauth:4000:0
+ 1: 1000
+ 2: foo_inline3:3000
+  1: 0
+  2: 3000
Index: llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -385,6 +385,12 @@
 
   auto &DL = Callee->getParent()->getDataLayout();
 
+  if (CB.countOperandBundlesOfType(LLVMContext::OB_ptrauth)) {
+    if (*FailureReason)
+      *FailureReason = "Authenticating calls are unsupported";
+    return false;
+  }
+
   // Check the return type. The callee's return value type must be bitcast
   // compatible with the call site's type.
   Type *CallRetTy = CB.getType();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134999.464437.patch
Type: text/x-patch
Size: 2134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220930/0b1f4616/attachment.bin>


More information about the llvm-commits mailing list