-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang][CGObjC] Sign the v-table pointer in ObjC exception RTTI. #135562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ojhunt
wants to merge
1
commit into
main
Choose a base branch
from
users/ojhunt/objc-correct-typeinfo-ptrauth-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Oliver Hunt (ojhunt) ChangesIf clang is configured to apply pointer authentication to type_info's vtable pointer we Full diff: https://github.com/llvm/llvm-project/pull/135562.diff 5 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..67fef2fa0c37f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -191,6 +191,7 @@ Non-comprehensive list of changes in this release
- Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719).
- Added `__builtin_elementwise_exp10`.
- For AMDPGU targets, added `__builtin_v_cvt_off_f32_i4` that maps to the `v_cvt_off_f32_i4` instruction.
+- Support authenticated ``type_info`` vtable pointers in Objective-C++
New Compiler Flags
------------------
diff --git a/clang/include/clang/CodeGen/ConstantInitBuilder.h b/clang/include/clang/CodeGen/ConstantInitBuilder.h
index 28d4764b6d60b..a7424abbc07eb 100644
--- a/clang/include/clang/CodeGen/ConstantInitBuilder.h
+++ b/clang/include/clang/CodeGen/ConstantInitBuilder.h
@@ -206,6 +206,9 @@ class ConstantAggregateBuilderBase {
void addSignedPointer(llvm::Constant *Pointer,
const PointerAuthSchema &Schema, GlobalDecl CalleeDecl,
QualType CalleeType);
+ void addSignedPointer(llvm::Constant *Pointer, unsigned Key,
+ bool UseAddressDiscrimination,
+ llvm::ConstantInt *OtherDiscriminator);
/// Add a null pointer of a specific type.
void addNullPointer(llvm::PointerType *ptrTy) {
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 1f11347b81411..e854f6b5920c8 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -7676,10 +7676,26 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
}
llvm::Value *VTableIdx = llvm::ConstantInt::get(CGM.Int32Ty, 2);
+ llvm::Constant *VTablePtr = llvm::ConstantExpr::getInBoundsGetElementPtr(
+ VTableGV->getValueType(), VTableGV, VTableIdx);
+
ConstantInitBuilder builder(CGM);
auto values = builder.beginStruct(ObjCTypes.EHTypeTy);
- values.add(llvm::ConstantExpr::getInBoundsGetElementPtr(
- VTableGV->getValueType(), VTableGV, VTableIdx));
+
+ if (auto &Schema =
+ CGM.getCodeGenOpts().PointerAuth.CXXTypeInfoVTablePointer) {
+ uint32_t discrimination = 0;
+ if (Schema.hasOtherDiscrimination()) {
+ assert(Schema.getOtherDiscrimination() ==
+ PointerAuthSchema::Discrimination::Constant);
+ discrimination = Schema.getConstantDiscrimination();
+ }
+ values.addSignedPointer(
+ VTablePtr, Schema.getKey(), Schema.isAddressDiscriminated(),
+ llvm::ConstantInt::get(CGM.IntPtrTy, discrimination));
+ } else {
+ values.add(VTablePtr);
+ }
values.add(GetClassName(ClassName));
values.add(GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition));
diff --git a/clang/lib/CodeGen/ConstantInitBuilder.cpp b/clang/lib/CodeGen/ConstantInitBuilder.cpp
index ce1fe137c1919..c5b1ad3a07235 100644
--- a/clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ b/clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -314,3 +314,15 @@ void ConstantAggregateBuilderBase::addSignedPointer(
Pointer, Schema, StorageAddress, CalleeDecl, CalleeType);
add(SignedPointer);
}
+
+void ConstantAggregateBuilderBase::addSignedPointer(
+ llvm::Constant *Pointer, unsigned Key, bool UseAddressDiscrimination,
+ llvm::ConstantInt *OtherDiscriminator) {
+ llvm::Constant *StorageAddress = nullptr;
+ if (UseAddressDiscrimination)
+ StorageAddress = getAddrOfCurrentPosition(Pointer->getType());
+
+ llvm::Constant *SignedPointer = Builder.CGM.getConstantSignedPointer(
+ Pointer, Key, StorageAddress, OtherDiscriminator);
+ add(SignedPointer);
+}
diff --git a/clang/test/CodeGenObjC/ptrauth-attr-exception.m b/clang/test/CodeGenObjC/ptrauth-attr-exception.m
new file mode 100644
index 0000000000000..1a17828b927da
--- /dev/null
+++ b/clang/test/CodeGenObjC/ptrauth-attr-exception.m
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
+
+__attribute__((objc_root_class))
+@interface Root {
+ Class isa;
+}
+@end
+
+__attribute__((objc_exception))
+@interface A : Root
+@end
+
+@implementation A
+@end
+
+// CHECK: @"OBJC_EHTYPE_$_A" = global {{%.*}} { ptr ptrauth (ptr getelementptr inbounds (ptr, ptr @objc_ehtype_vtable, i32 2), i32 2),
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:codegen
IR generation bugs: mangling, exceptions, etc.
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If clang is configured to apply pointer authentication to type_info's vtable pointer we
ensure that the selected schema is applied to the RTTI objects generated for objc++.