[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


================
@@ -3126,3 +3137,57 @@ CodeGenFunction::EmitPointerAuthAuth(const CGPointerAuthInfo &PointerAuth,
   return EmitPointerAuthCommon(*this, PointerAuth, Pointer,
                                llvm::Intrinsic::ptrauth_auth);
 }
+
+llvm::Value *CodeGenFunction::EmitPointerAuthSign(QualType pointeeType,
+                                                  llvm::Value *pointer) {
+  CGPointerAuthInfo pointerAuth =
+      CGM.getPointerAuthInfoForPointeeType(pointeeType);
+  return EmitPointerAuthSign(pointerAuth, pointer);
+}
+
+llvm::Value *CodeGenFunction::EmitPointerAuthAuth(QualType pointeeType,
+                                                  llvm::Value *pointer) {
+  CGPointerAuthInfo pointerAuth =
+      CGM.getPointerAuthInfoForPointeeType(pointeeType);
+  return EmitPointerAuthAuth(pointerAuth, pointer);
+}
+
+llvm::Value *
+CodeGenFunction::EmitPointerAuthResignCall(llvm::Value *value,
+                                           const CGPointerAuthInfo &curAuth,
+                                           const CGPointerAuthInfo &newAuth) {
+  assert(curAuth && newAuth);
+
+  if (curAuth.getAuthenticationMode() !=
+          PointerAuthenticationMode::SignAndAuth ||
+      newAuth.getAuthenticationMode() !=
+          PointerAuthenticationMode::SignAndAuth) {
+    auto authedValue = EmitPointerAuthAuth(curAuth, value);
+    return EmitPointerAuthSign(newAuth, authedValue);
+  }
+  // Convert the pointer to intptr_t before signing it.
+  auto origType = value->getType();
----------------
kovdan01 wrote:

Nit
```suggestion
  auto *origType = value->getType();
```

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


More information about the cfe-commits mailing list