Add LLVM AllocToken and Heap Partitioning Support to the Rust compiler. - #160298
Draft
rcvalle wants to merge 8 commits into
Draft
Add LLVM AllocToken and Heap Partitioning Support to the Rust compiler.#160298rcvalle wants to merge 8 commits into
rcvalle wants to merge 8 commits into
Conversation
Add the `-Zsanitizer=alloc-token` sanitizer option, including target support specification (i.e., `supported_sanitizers` in target specifications), and the accompanying `-Zsanitizer-alloc-token-scheme`, `-Zsanitizer-alloc-token-max`, `-Zsanitizer-alloc-token-extended`, and `-Zsanitizer-alloc-token-fast-abi` options.
Add the `#[alloc_token_hint(contains_pointers = ..., type_name = "...")]` attribute to allow the user to define the allocation token hint (i.e., the contains-pointer classification and type name encoding) for user-defined types, and the internal `#[rustc_alloc_token_hint]` attribute to annotate typed allocation functions whose type parameter identifies the allocated type.
…ning schemes Add the `rustc_sanitizers::alloc_token` module, organized and structured similarly to `rustc_sanitizers::cfi::typeid` (i.e., the `hint` module provides the interface for computing allocation token hints for a given `Ty` and dispatches to the selected heap partitioning scheme implementation, such as `type_hash_pointer_split`).
…nt it for LLVM backend Add the `set_alloc_token_hint` and `get_alloc_token_id` methods to the backend-agnostic `BuilderMethods` trait, and implement them for the LLVM backend; and add the `SanitizeAllocToken` LLVM function attribute, and the `alloc-token-mode`, `alloc-token-max`, `alloc-token-extended`, and `alloc-token-fast-abi` module flags.
Add `alloc_typed` and `alloc_array_typed`, internal, unstable, generic allocation functions annotated with `#[rustc_alloc_token_hint]`. Route `Box::new` and `RawVec::<T, Global>::with_capacity` through them when LLVM AllocToken and heap partitioning support is enabled, so the allocation call within them is annotated with the allocation token hint (i.e., the contents of the `!alloc_token` metadata) for its type parameter `T`.
…brary Extend the Rust compiler allocator shim generation to also generate the token-enabled versions of the allocation functions, forwarding to token-enabled methods of the `GlobalAlloc` trait (i.e., `alloc_with_token`, `alloc_zeroed_with_token`, and`realloc_with_token`), with default implementations that ignore the token identifier and call the non-token-enabled methods, for backward compatibility with existing allocators, and the token-enabled C allocator interface (i.e., `__alloc_token_malloc`, `__alloc_token_calloc`, and `__alloc_token_realloc`) in the `System` allocator implementation, so that programs using the default allocator can use a token-enabled C memory allocator for the whole program, including foreign code, in mixed binaries.
Add the `alloc_token_infer` intrinsic (i.e., the Rust equivalent of the Clang `__builtin_infer_alloc_token` builtin, lowered to the `llvm.alloc.token.id` intrinsic) for allocator and arena implementers to query the token identifier for a given type at compile time (e.g., `core::intrinsics::alloc_token_infer::<T>() -> usize`), so it can be passed to a token-enabled allocator interface directly.
Add documentation for the LLVM AllocToken and heap partitioning support in the Rust compiler.
10 tasks
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
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.
Add LLVM AllocToken and heap partitioning support to the Rust compiler.
For more information about LLVM AllocToken and heap partitioning support for the Rust compiler, see the design document in the tracking issue #159111.
r? @bjorn3