-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb] Call FixUpPointer in WritePointerToMemory #152798
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
felipepiovezan
merged 1 commit into
llvm:main
from
felipepiovezan:felipe/cleanup_pointers_expr_eval
Aug 11, 2025
Merged
Changes from all commits
Commits
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
Oops, something went wrong.
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.
Why not put this deeper down, in WriteScalarToMemory or even WriteMemory ?
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.
Putting it here might fix tests but the other code paths might be lacking coverage.
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.
Only pointers need to be fixed though. I'm not sure I understand?
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.
OHHH, I see the confusion now: note that this is not fixing the "pointer where the data is written", but rather it is fixing the "pointer written to memory". (see the name of the method:
Write**Pointer**ToMemory
)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.
At least one thing in this method should be actually be called pointer, but that's not your fault.
I'm not 100% sure that all pointer values here do want to be fixed. Looking at the uses of this method inside of lldb I see:
Both of which should be ok with removing the current uses of non-address bits. If you remove pointer authentication bits from a function pointer, it should still authenticate, it's just unsigned. So if there was code that checked for that, that's a corner case that won't work.
It's not in the SB API so there's nothing to break there.
Probably some corner case here but short of a major rework of how we handle addresses, this is a good step. We can consider it a bug fix to the current strategy, whether that strategy is ultimately good or bad.
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 will make a note of that possibility and try to make things break when I get the chance, as this is the kind of corner case I want to explore too.
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.
Pointer authentication is probably ok unless your ABI specifically checks that there is a non-zero authentication code. I'm assuming a code of 0 will always authenticate.
For memory tagging if your memory allocator uses tags you would not be able to write to write via. a pointer to a heap allocation. The top byte would be removed and treated as tag 0 which is often used to mark unallocated areas (though you don't have to, some will randomise it).
(you can read/write a heap allocation with lldb's commands because debug APIs ignore tag mismatches)
I'm not sure how exactly you'd hit this from LLDB. And I wonder if you could work around it with some crafty casting in and out of uintptr_t.
I will make a note to try out memory tagging.
Istr Objective C using the top byte for something, you could look into that.
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.
In fact the more I think about it, debug APIs are allowed to ignore memory attributes but I'm not so sure expressions should.
But this still applies. Can't consider a change before we make the existing thing consistent.
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 think the crucial part of your observations is that we really need to delay cleaning those attributes until absolutely necessary (e.g. #150537), so that we then have the chance to decide whether/which bits to clean up. In that sense, the existing patches are a step in that direction.