Skip to content

[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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Non-comprehensive list of changes in this release
``sizeof`` or ``typeof`` expression. (#GH138444)
- Deprecation warning is emitted for the deprecated ``__reference_binds_to_temporary`` intrinsic.
``__reference_constructs_from_temporary`` should be used instead. (#GH44056)
- Support pointer authentication for Objective-C exception `type_info` objects

New Compiler Flags
------------------
Expand Down
15 changes: 13 additions & 2 deletions clang/lib/CodeGen/CGObjCMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7676,10 +7676,21 @@ 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) {
assert(!Schema.hasOtherDiscrimination() ||
Schema.getOtherDiscrimination() ==
PointerAuthSchema::Discrimination::Constant);
values.addSignedPointer(VTablePtr, Schema, GlobalDecl(), QualType());
} else {
values.add(VTablePtr);
}
values.add(GetClassName(ClassName));
values.add(GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition));

Expand Down
18 changes: 18 additions & 0 deletions clang/test/CodeGenObjC/ptrauth-attr-exception.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-type-info-vtable-pointer-discrimination -fptrauth-calls -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck --check-prefix=TYPEDISC_TYPEINFO %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),
// TYPEDISC_TYPEINFO: @"OBJC_EHTYPE_$_A" = global {{%.*}} { ptr ptrauth (ptr getelementptr inbounds (ptr, ptr @objc_ehtype_vtable, i32 2), i32 2, i64 45546, ptr @"OBJC_EHTYPE_$_A"),