https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/244800

Under the c++ relative vtable abi vtable slots are only 32 bits so cannot be 
signed.

>From a4cb98f0102174338a63c31aa3b37b9ecb93a834 Mon Sep 17 00:00:00 2001
From: Oliver Hunt <[email protected]>
Date: Wed, 18 Nov 2026 10:02:09 -0800
Subject: [PATCH] Don't set a signing schema for relative vfptrs

Under the c++ relative vtable abi vtable slots are only 32 bits so
cannot be signed.
---
 clang/lib/CodeGen/ItaniumCXXABI.cpp              |  1 +
 clang/lib/Frontend/CompilerInvocation.cpp        |  8 +++++---
 .../ptrauth-virtual-function-call.cpp            | 16 ++++++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/CodeGenCXX/RelativeVTablesABI/ptrauth-virtual-function-call.cpp

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 3fbee4dc6bb031..1bb3682c0c69b9 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2300,6 +2300,7 @@ CGCallee 
ItaniumCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
 
   CGPointerAuthInfo PointerAuth;
   if (Schema) {
+    assert(!CGM.getLangOpts().RelativeCXXABIVTables);
     assert(VTableSlotPtr && "virtual function pointer not set");
     GD = 
CGM.getItaniumVTableContext().findOriginalMethod(GD.getCanonicalDecl());
     PointerAuth = CGF.EmitPointerAuthInfo(Schema, VTableSlotPtr, GD, 
QualType());
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 9af6f6c41eb756..e4aa33ced0ded1 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1506,9 +1506,11 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
     else
       Opts.CXXVTTVTablePointers =
           PointerAuthSchema(Key::ASDA, false, Discrimination::None);
-
-    Opts.CXXVirtualFunctionPointers = Opts.CXXVirtualVariadicFunctionPointers =
-        PointerAuthSchema(Key::ASIA, true, Discrimination::Decl);
+    if (!LangOpts.RelativeCXXABIVTables) {
+      Opts.CXXVirtualFunctionPointers =
+        Opts.CXXVirtualVariadicFunctionPointers =
+          PointerAuthSchema(Key::ASIA, true, Discrimination::Decl);
+    }
     Opts.CXXMemberFunctionPointers =
         PointerAuthSchema(Key::ASIA, false, Discrimination::Type);
 
diff --git 
a/clang/test/CodeGenCXX/RelativeVTablesABI/ptrauth-virtual-function-call.cpp 
b/clang/test/CodeGenCXX/RelativeVTablesABI/ptrauth-virtual-function-call.cpp
new file mode 100644
index 00000000000000..a4dcf778df3c80
--- /dev/null
+++ b/clang/test/CodeGenCXX/RelativeVTablesABI/ptrauth-virtual-function-call.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple arm64-apple-ios -fptrauth-calls 
-fexperimental-relative-c++-abi-vtables -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: define{{.*}} void @_Z8call_fooP1A(
+// CHECK: [[THIS:%.*]] = load ptr, ptr %a.addr
+// CHECK: [[VTABLE:%.*]] = load ptr, ptr [[THIS]]
+// CHECK: [[VTABLE_INT:%.*]] = ptrtoint ptr [[VTABLE]] to i64
+// CHECK: [[AUTH:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[VTABLE_INT]], i32 
2, i64 0)
+// CHECK: [[VTABLE_AUTH:%.*]] = inttoptr i64 [[AUTH]] to ptr
+// CHECK: [[FN:%.*]] = call ptr @llvm.load.relative.i32(ptr [[VTABLE_AUTH]], 
i32 0)
+// CHECK: call void [[FN]](ptr {{.*}}[[THIS]]){{$}}
+
+struct A {
+  virtual void foo();
+};
+
+void call_foo(A *a) { a->foo(); }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to