[llvm-branch-commits] [llvm] Add deactivation symbol operand to ConstantPtrAuth. (PR #133537)
Peter Collingbourne via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Sep 10 18:03:17 PDT 2025
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133537
>From e728f3444624a5f47f0af84c21fb3a584f3e05b7 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Fri, 1 Aug 2025 17:27:41 -0700
Subject: [PATCH 1/4] Add verifier check
Created using spr 1.3.6-beta.1
---
llvm/lib/IR/Verifier.cpp | 5 +++++
llvm/test/Verifier/ptrauth-constant.ll | 6 ++++++
2 files changed, 11 insertions(+)
create mode 100644 llvm/test/Verifier/ptrauth-constant.ll
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 3ff9895e161c4..3478c2c450ae7 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2627,6 +2627,11 @@ void Verifier::visitConstantPtrAuth(const ConstantPtrAuth *CPA) {
Check(CPA->getDiscriminator()->getBitWidth() == 64,
"signed ptrauth constant discriminator must be i64 constant integer");
+
+ Check(isa<GlobalValue>(CPA->getDeactivationSymbol()) ||
+ CPA->getDeactivationSymbol()->isNullValue(),
+ "signed ptrauth constant deactivation symbol must be a global value "
+ "or null");
}
bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) {
diff --git a/llvm/test/Verifier/ptrauth-constant.ll b/llvm/test/Verifier/ptrauth-constant.ll
new file mode 100644
index 0000000000000..fdd6352cf8469
--- /dev/null
+++ b/llvm/test/Verifier/ptrauth-constant.ll
@@ -0,0 +1,6 @@
+; RUN: not opt -passes=verify < %s 2>&1 | FileCheck %s
+
+ at g = external global i8
+
+; CHECK: signed ptrauth constant deactivation symbol must be a global variable or null
+ at ptr = global ptr ptrauth (ptr @g, i32 0, i64 65535, ptr null, ptr inttoptr (i64 16 to ptr))
>From 60e836e71bf9aabe9dade2bda1ca38107f76b599 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Mon, 8 Sep 2025 17:34:59 -0700
Subject: [PATCH 2/4] Address review comment
Created using spr 1.3.6-beta.1
---
llvm/lib/IR/Constants.cpp | 1 +
llvm/test/Assembler/invalid-ptrauth-const6.ll | 6 ++++++
2 files changed, 7 insertions(+)
create mode 100644 llvm/test/Assembler/invalid-ptrauth-const6.ll
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 5eacc7af1269b..53b292f90c03d 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2082,6 +2082,7 @@ ConstantPtrAuth::ConstantPtrAuth(Constant *Ptr, ConstantInt *Key,
assert(Key->getBitWidth() == 32);
assert(Disc->getBitWidth() == 64);
assert(AddrDisc->getType()->isPointerTy());
+ assert(DeactivationSymbol->getType()->isPointerTy());
setOperand(0, Ptr);
setOperand(1, Key);
setOperand(2, Disc);
diff --git a/llvm/test/Assembler/invalid-ptrauth-const6.ll b/llvm/test/Assembler/invalid-ptrauth-const6.ll
new file mode 100644
index 0000000000000..6e8e1d386acc8
--- /dev/null
+++ b/llvm/test/Assembler/invalid-ptrauth-const6.ll
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+ at var = global i32 0
+
+; CHECK: error: constant ptrauth deactivation symbol must be a pointer
+ at ptr = global ptr ptrauth (ptr @var, i32 0, i64 65535, ptr null, i64 0)
>From a780d181fa69236d5909759a24a1134b50313980 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Tue, 9 Sep 2025 17:18:49 -0700
Subject: [PATCH 3/4] Address review comment
Created using spr 1.3.6-beta.1
---
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 3 +++
llvm/lib/IR/Verifier.cpp | 3 +++
2 files changed, 6 insertions(+)
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 045ed204620fb..04fe4c57af6ed 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1613,6 +1613,9 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
ConstOps.size() > 4 ? ConstOps[4]
: ConstantPointerNull::get(cast<PointerType>(
ConstOps[3]->getType()));
+ if (DeactivationSymbol->getType()->isPointerTy())
+ return error(
+ "ptrauth deactivation symbol operand must be a pointer");
C = ConstantPtrAuth::get(ConstOps[0], Key, Disc, ConstOps[3],
DeactivationSymbol);
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 9e44dfb387615..a53ba17e26011 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2632,6 +2632,9 @@ void Verifier::visitConstantPtrAuth(const ConstantPtrAuth *CPA) {
Check(CPA->getDiscriminator()->getBitWidth() == 64,
"signed ptrauth constant discriminator must be i64 constant integer");
+ Check(CPA->getDeactivationSymbol()->getType()->isPointerTy(),
+ "signed ptrauth constant deactivation symbol must be a pointer");
+
Check(isa<GlobalValue>(CPA->getDeactivationSymbol()) ||
CPA->getDeactivationSymbol()->isNullValue(),
"signed ptrauth constant deactivation symbol must be a global value "
>From 51c353bbde24f940e3dfd7488aec0682dbef260b Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Tue, 9 Sep 2025 17:21:45 -0700
Subject: [PATCH 4/4] Fix
Created using spr 1.3.6-beta.1
---
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 04fe4c57af6ed..a7fce4f2d504c 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1613,7 +1613,7 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
ConstOps.size() > 4 ? ConstOps[4]
: ConstantPointerNull::get(cast<PointerType>(
ConstOps[3]->getType()));
- if (DeactivationSymbol->getType()->isPointerTy())
+ if (!DeactivationSymbol->getType()->isPointerTy())
return error(
"ptrauth deactivation symbol operand must be a pointer");
More information about the llvm-branch-commits
mailing list