[clang] [PAC] Implement function pointer re-signing (PR #98847)
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 16 18:06:47 PDT 2024
================
@@ -165,6 +166,88 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) {
return ::getPointerAuthInfoForType(*this, T);
}
+static bool isZeroConstant(llvm::Value *value) {
+ if (auto ci = dyn_cast<llvm::ConstantInt>(value))
+ return ci->isZero();
+ return false;
+}
+
+static bool equalAuthPolicies(const CGPointerAuthInfo &left,
+ const CGPointerAuthInfo &right) {
+ if (left.isSigned() != right.isSigned())
+ return false;
+ assert(left.isSigned() && right.isSigned() &&
+ "should only be called with non-null auth policies");
+ return left.getKey() == right.getKey() &&
+ left.getAuthenticationMode() == right.getAuthenticationMode();
+}
+
+llvm::Value *CodeGenFunction::EmitPointerAuthResign(
+ llvm::Value *value, QualType type, const CGPointerAuthInfo &curAuthInfo,
+ const CGPointerAuthInfo &newAuthInfo, bool isKnownNonNull) {
+ // Fast path: if neither schema wants a signature, we're done.
+ if (!curAuthInfo && !newAuthInfo)
+ return value;
+
+ llvm::Value *null = nullptr;
+ // If the value is obviously null, we're done.
+ if (auto pointerValue = dyn_cast<llvm::PointerType>(value->getType())) {
+ null = CGM.getNullPointer(pointerValue, type);
+ } else {
+ assert(value->getType()->isIntegerTy());
+ null = llvm::ConstantInt::get(IntPtrTy, 0);
+ }
+ if (value == null) {
+ return value;
+ }
+
+ // If both schemas sign the same way, we're done.
+ if (equalAuthPolicies(curAuthInfo, newAuthInfo)) {
----------------
ahatanak wrote:
I don't think we can do that as the function shouldn't return here when different discriminators are used. Also we are going to add more stuff to `equalAuthPolicies` in the future, so I'll leave it as.
https://github.com/llvm/llvm-project/pull/98847
More information about the cfe-commits
mailing list