-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[PAC] Fix address discrimination for type info vtable pointers #102199
Changes from 1 commit
0c20bcd
e0beb3f
130ff55
969a877
55fc2c8
90d6355
b08172f
c9d26dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,12 +1056,18 @@ class ConstantPtrAuth final : public Constant { | |
return !getAddrDiscriminator()->isNullValue(); | ||
} | ||
|
||
/// A constant value for the address discriminator which has special | ||
/// significance to ctors/dtors lowering. Regular address discrimination can't | ||
/// be applied for them since uses of llvm.global_{c|d}tors are disallowed | ||
/// (see Verifier::visitGlobalVariable) and we can't emit getelementptr | ||
/// expressions referencing these special arrays. | ||
enum { AddrDiscriminator_CtorsDtors = 1 }; | ||
/// Constant values for the address discriminator which have special | ||
/// significance to lowering in some contexts. | ||
/// - For ctors/dtors, regular address discrimination can't | ||
/// be applied for them since uses of llvm.global_{c|d}tors are disallowed | ||
/// (see Verifier::visitGlobalVariable) and we can't emit getelementptr | ||
/// expressions referencing these special arrays. | ||
/// - For vtable pointers of std::type_info and classes derived from it, | ||
/// we do not know the storage address when emitting ptrauth constant. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it work to wire the storage address through Beyond that, for static ctors, as I mentioned before, I still don't think this should have ptrauth at the IR level, but rather should be a backend decision made when encoding the IR representation of "a list of static ctors/dtors" to some object file format encoding thereof. That would avoid needing this address discriminator placeholder dance here. But I suppose that's a separate problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@ahmedbougacha I was unable to find a straight-forward way to do that, but I might be missing smth (and it might be even smth obvious). I would be glad to see more detailed suggestions if you have some better implementation in mind - I agree that having an actual address instead of a placeholder is much better.
This sounds nice, it's an interesting suggestion. Anyway, init/fini stuff is out of scope of this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only caller of BuildVTablePointer is BuildTypeInfo... and BuildTypeInfo itself creates the global variable in question. So it shouldn't be that hard. Just move the call to BuildVTablePointer after we construct the global. Actually, that might be slightly trickier than I'm making it sound because we don't compute the type before we create the ConstantStruct, but it should be possible to separate computing the type from constructing the ConstantStruct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahmedbougacha @efriedma-quic Should be fixed in 0c20bcd |
||
enum { | ||
AddrDiscriminator_CtorsDtors = 1, | ||
AddrDiscriminator_CXXTypeInfoVTablePointer = 1 | ||
}; | ||
|
||
/// Whether the address uses a special address discriminator. | ||
/// These discriminators can't be used in real pointer-auth values; they | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
; RUN: llc -mtriple aarch64-linux-gnu -mattr=+pauth -filetype=asm -o - %s | FileCheck --check-prefix=ELF %s | ||
; RUN: llc -mtriple aarch64-apple-darwin -mattr=+pauth -filetype=asm -o - %s | FileCheck --check-prefix=MACHO %s | ||
|
||
; ELF-LABEL: _ZTI10Disc: | ||
; ELF-NEXT: .xword (_ZTVN10__cxxabiv117__class_type_infoE+16)@AUTH(da,45546,addr) | ||
; ELF-LABEL: _ZTI10NoDisc: | ||
; ELF-NEXT: .xword (_ZTVN10__cxxabiv117__class_type_infoE+16)@AUTH(da,45546) | ||
|
||
; MACHO-LABEL: __ZTI10Disc: | ||
; MACHO-NEXT: .quad (__ZTVN10__cxxabiv117__class_type_infoE+16)@AUTH(da,45546,addr) | ||
; MACHO-LABEL: __ZTI10NoDisc: | ||
; MACHO-NEXT: .quad (__ZTVN10__cxxabiv117__class_type_infoE+16)@AUTH(da,45546) | ||
|
||
@_ZTVN10__cxxabiv117__class_type_infoE = external global [0 x ptr] | ||
|
||
@_ZTS10Disc = constant [4 x i8] c"Disc", align 1 | ||
@_ZTI10Disc = constant { ptr, ptr } { ptr ptrauth (ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), i32 2, i64 45546, ptr inttoptr (i64 1 to ptr)), ptr @_ZTS10Disc }, align 8 | ||
|
||
@_ZTS10NoDisc = constant [6 x i8] c"NoDisc", align 1 | ||
@_ZTI10NoDisc = constant { ptr, ptr } { ptr ptrauth (ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), i32 2, i64 45546), ptr @_ZTS10NoDisc }, align 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this be structured rather than using ?:
llvm::Constant *StorageAddress = nullptr;
if (Schema.isAddressDescriminated()) {
StorageAddress = llvm::ConstantExpr::getIntToPtr(
llvm::ConstantInt::get(
CGM.IntPtrTy,
llvm::ConstantPtrAuth::
AddrDiscriminator_CXXTypeInfoVTablePointer),
PtrTy);
}
This bug does make me wonder if
getConstantSignedPointer(..)
etc should use a std::optional<&> rather than a pointer as that might have made it more obvious that the address was not being used in this code (obviously this is not a thing we should be changing in this PR)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corresponding piece of code was deleted in the latest commit 0c20bcd, so probably the comment could be resolved.