-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Fix PointerAuth semantics of cpp_trivially_relocatable #143969
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
Merged
ojhunt
merged 7 commits into
main
from
users/ojhunt/ptrauth-vs-trivial-relocation-sema-smol
Jun 16, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f476803
[clang] Fix PointerAuth semantics of cpp_trivially_relocatable
ojhunt 3190a52
Add comments and more tests
ojhunt 15b1a81
Address corentin comments
ojhunt 3ba1e39
__unused doesn't work on the linux and windows bots
ojhunt 6b5de16
Address discriminated __ptrauth should not be relocatable
ojhunt ea3af8a
sigh, formatting
ojhunt 54f93cb
remove extraneous check
ojhunt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// RUN: %clang_cc1 -triple arm64 -fptrauth-calls -fptrauth-intrinsics -std=c++26 -verify %s | ||
|
||
// This test intentionally does not enable the global address discrimination | ||
// of vtable pointers. This lets us configure them with different schemas | ||
// and verify that we're correctly tracking the existence of address discrimination | ||
|
||
// expected-no-diagnostics | ||
|
||
struct NonAddressDiscPtrauth { | ||
void * __ptrauth(1, 0, 1234) p; | ||
}; | ||
|
||
static_assert(__builtin_is_cpp_trivially_relocatable(NonAddressDiscPtrauth)); | ||
|
||
struct AddressDiscPtrauth { | ||
void * __ptrauth(1, 1, 1234) p; | ||
}; | ||
|
||
static_assert(!__builtin_is_cpp_trivially_relocatable(AddressDiscPtrauth)); | ||
|
||
struct MultipleBaseClasses : NonAddressDiscPtrauth, AddressDiscPtrauth { | ||
|
||
}; | ||
|
||
static_assert(!__builtin_is_cpp_trivially_relocatable(MultipleBaseClasses)); | ||
|
||
struct MultipleMembers1 { | ||
NonAddressDiscPtrauth field0; | ||
AddressDiscPtrauth field1; | ||
}; | ||
|
||
static_assert(!__builtin_is_cpp_trivially_relocatable(MultipleMembers1)); | ||
|
||
struct MultipleMembers2 { | ||
NonAddressDiscPtrauth field0; | ||
NonAddressDiscPtrauth field1; | ||
}; | ||
|
||
static_assert(__builtin_is_cpp_trivially_relocatable(MultipleMembers2)); | ||
|
||
struct UnionOfPtrauth { | ||
union { | ||
NonAddressDiscPtrauth field0; | ||
AddressDiscPtrauth field1; | ||
} u; | ||
}; | ||
|
||
static_assert(!__builtin_is_cpp_trivially_relocatable(UnionOfPtrauth)); | ||
|
||
struct [[clang::ptrauth_vtable_pointer(process_independent,address_discrimination,no_extra_discrimination)]] Polymorphic trivially_relocatable_if_eligible { | ||
virtual ~Polymorphic(); | ||
}; | ||
|
||
struct Foo : Polymorphic { | ||
Foo(const Foo&); | ||
~Foo(); | ||
}; | ||
|
||
|
||
static_assert(__builtin_is_cpp_trivially_relocatable(Polymorphic)); | ||
|
||
struct [[clang::ptrauth_vtable_pointer(process_independent,no_address_discrimination,no_extra_discrimination)]] NonAddressDiscriminatedPolymorphic trivially_relocatable_if_eligible { | ||
virtual ~NonAddressDiscriminatedPolymorphic(); | ||
}; | ||
|
||
static_assert(__builtin_is_cpp_trivially_relocatable(NonAddressDiscriminatedPolymorphic)); | ||
|
||
|
||
struct PolymorphicMembers { | ||
Polymorphic field; | ||
}; | ||
|
||
static_assert(__builtin_is_cpp_trivially_relocatable(PolymorphicMembers)); | ||
|
||
struct UnionOfPolymorphic { | ||
union trivially_relocatable_if_eligible { | ||
Polymorphic p; | ||
int i; | ||
} u; | ||
}; | ||
|
||
static_assert(!__builtin_is_cpp_trivially_relocatable(UnionOfPolymorphic)); | ||
|
||
|
||
struct UnionOfNonAddressDiscriminatedPolymorphic { | ||
union trivially_relocatable_if_eligible { | ||
NonAddressDiscriminatedPolymorphic p; | ||
int i; | ||
} u; | ||
}; | ||
static_assert(!__builtin_is_cpp_trivially_relocatable(UnionOfNonAddressDiscriminatedPolymorphic)); | ||
|
||
struct UnionOfNonAddressDiscriminatedPtrauth { | ||
union { | ||
NonAddressDiscPtrauth p; | ||
int i; | ||
} u; | ||
}; | ||
|
||
static_assert(__builtin_is_cpp_trivially_relocatable(UnionOfNonAddressDiscriminatedPtrauth)); | ||
|
||
struct UnionOfAddressDisriminatedPtrauth { | ||
union { | ||
AddressDiscPtrauth p; | ||
int i; | ||
} u; | ||
}; | ||
|
||
static_assert(!__builtin_is_cpp_trivially_relocatable(UnionOfAddressDisriminatedPtrauth)); |
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.
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.
Is that still used?
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.
Good question, it's possible I updated it without verifying it was needed.
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.
Ah right, this is used for the union check - in a union it does not matter what the source of the address discrimination is, a union containing anything address discriminated isn't valid. In principle with this change the only thing that would get here is a vtable pointer but it seems reasonable to be safe.