A debug allocator which removes overalignment from align < 8 allocations#99074
Closed
saethlin wants to merge 1 commit intorust-lang:masterfrom
Closed
A debug allocator which removes overalignment from align < 8 allocations#99074saethlin wants to merge 1 commit intorust-lang:masterfrom
saethlin wants to merge 1 commit intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This reorganizes the implementation of the System allocator to permit adding various debuggig features. Currently, all that this implements is a scheme that allocates a little extra space for low-alignment allocations then returns a pointer into the actual allocation which is offset so that it is not over-aligned.
This is a huge aid in discovering accidental reliance on over-alignment. Allocators designed for C can be relied upon to produce over-aligned pointers, so alignment-related bugs can be latent for a long time. Currently I am aware of ~100 crates in the wild where Miri detects misaligned pointer access. Many of these take a
&[u8], sometimes from aVec<u8>and attempt to do reads by converting to a more-aligned type without checking if the access is aligned.On its own, this PR does basically nothing to detect bugs, but we already have debug assertions in a number of standard library APIs which are enabled along with this allocator in
-Zbuild-std. And if I ever finish #98112, we will be able to catch uses which just do misaligned pointer dereferences directly.This implementation is factored so accommodate other patches to the default allocator which can help in detecting other sources of UB.
@rustbot label +T-libs
This technique I'm trying to use breaks a UI test and I do not know why and I can't figure out how to fix it. I feel like this suggestion that's now coming out of a UI test doesn't even make sense. I made the per-systemresolved by #99091 ❤️Systemallocatorspub(crate)but they're suggested outside ofstdI think? Help?