Skip to content

A debug allocator which removes overalignment from align < 8 allocations#99074

Closed
saethlin wants to merge 1 commit intorust-lang:masterfrom
saethlin:debug-allocator
Closed

A debug allocator which removes overalignment from align < 8 allocations#99074
saethlin wants to merge 1 commit intorust-lang:masterfrom
saethlin:debug-allocator

Conversation

@saethlin
Copy link
Member

@saethlin saethlin commented Jul 9, 2022

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 a Vec<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-system System allocators pub(crate) but they're suggested outside of std I think? Help? resolved by #99091 ❤️

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants