[clang] [PAC] Implement function pointer re-signing (PR #98847)

Daniil Kovalev via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 06:48:42 PDT 2024


================
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -emit-llvm -o-  -fptrauth-function-pointer-type-discrimination | FileCheck %s
+
+typedef void (*fptr_t)(void);
+
+char *cptr;
+void (*fptr)(void);
+
+// CHECK-LABEL: define void @test1
+void test1() {
+  // CHECK: [[LOAD:%.*]] = load ptr, ptr @cptr
+  // CHECK: [[TOINT:%.*]] = ptrtoint ptr [[LOAD]] to i64
+  // CHECK: call i64 @llvm.ptrauth.resign(i64 [[TOINT]], i32 0, i64 0, i32 0, i64 18983)
+  // CHECK: call void {{.*}}() [ "ptrauth"(i32 0, i64 18983) ]
+
+  (*(fptr_t)cptr)();
+}
+
+// CHECK-LABEL: define i8 @test2
+char test2() {
+  return *(char *)fptr;
+
+  // CHECK: [[LOAD:%.*]] = load ptr, ptr @fptr
+  // CHECK: [[CMP:%.*]] = icmp ne ptr [[LOAD]], null
+
+  // CHECK: [[TOINT:%.*]] = ptrtoint ptr [[LOAD]] to i64
----------------
kovdan01 wrote:

Here, you don't check the full function body, and only partially check instructions after `resign.nonnull:` label. The `resign.cont:` label is left unchecked. Was it done intentionally?

https://github.com/llvm/llvm-project/pull/98847


More information about the cfe-commits mailing list