-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[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
Changes from 1 commit
f476803
3190a52
15b1a81
3ba1e39
6b5de16
ea3af8a
54f93cb
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 |
|---|---|---|
|
|
@@ -629,25 +629,46 @@ class ASTContext : public RefCountedBase<ASTContext> { | |
| void setRelocationInfoForCXXRecord(const CXXRecordDecl *, | ||
| CXXRecordDeclRelocationInfo); | ||
|
|
||
| /// Examines a given type, and returns whether the T itself | ||
| /// Examines a given type, and returns whether the type itself | ||
| /// is address discriminated, or any transitively embedded types | ||
| /// contain data that is address discriminated. This includes | ||
| /// implicitly authenticated values like vtable pointers, as well as | ||
| /// explicitly qualified fields. | ||
| bool containsAddressDiscriminatedPointerAuth(QualType T); | ||
| // A simple helper function to short circuit pointer auth checks. | ||
| bool containsAddressDiscriminatedPointerAuth(QualType T) { | ||
| if (!isPointerAuthenticationAvailable()) | ||
| return false; | ||
| return findPointerAuthContent(T) != PointerAuthContent::None; | ||
| } | ||
|
|
||
| bool isPointerAuthenticationAvailable() const { | ||
| return LangOpts.PointerAuthCalls || LangOpts.PointerAuthIntrinsics || | ||
| LangOpts.PointerAuthVTPtrAddressDiscrimination; | ||
| /// Examines a given type, and returns whether the type itself | ||
| /// or any data it transitively contains has a pointer authentication | ||
| /// schema that is not safely relocatable. e.g. any data or fields | ||
| /// with address discrimination other than any otherwise similar | ||
| /// vtable pointers. | ||
| bool containsNonRelocatablePointerAuth(QualType T) { | ||
| if (!isPointerAuthenticationAvailable()) | ||
| return false; | ||
| return findPointerAuthContent(T) == PointerAuthContent::AddressDiscriminatedData; | ||
| } | ||
|
|
||
| private: | ||
| llvm::DenseMap<const CXXRecordDecl *, CXXRecordDeclRelocationInfo> | ||
| RelocatableClasses; | ||
|
|
||
| // FIXME: store in RecordDeclBitfields in future? | ||
| llvm::DenseMap<const RecordDecl *, bool> | ||
| enum class PointerAuthContent : uint8_t { | ||
| None, | ||
| AddressDiscriminatedVTable, | ||
| AddressDiscriminatedData | ||
| }; | ||
|
|
||
| // A simple helper function to short circuit pointer auth checks. | ||
| bool isPointerAuthenticationAvailable() const { | ||
| return LangOpts.PointerAuthCalls || LangOpts.PointerAuthIntrinsics || | ||
| LangOpts.PointerAuthVTPtrAddressDiscrimination; | ||
| } | ||
|
Contributor
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. 2 questions; Why do we have 3 options, and why do we care about anything but
Contributor
Author
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 first is historical sadness, we can probably make this better when I move the pointer auth options and similar into the target info rather than the obtuse combination of codegen and langopts we currently have. When we do that we can probably just have a single "the target supports pointer auth" flag which is what this is trying to approximate. The reason that That said as we discussed (for people following at home @cor3ntin and I are talking at wg21) if someone had |
||
| PointerAuthContent findPointerAuthContent(QualType T); | ||
| llvm::DenseMap<const RecordDecl *, PointerAuthContent> | ||
| RecordContainsAddressDiscriminatedPointerAuth; | ||
|
|
||
| ImportDecl *FirstLocalImport = nullptr; | ||
|
|
||
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.