Skip to content

Add LLVM AllocToken and Heap Partitioning Support to the Rust compiler. - #160298

Draft
rcvalle wants to merge 8 commits into
rust-lang:mainfrom
rcvalle:rust-heap-partitioning
Draft

Add LLVM AllocToken and Heap Partitioning Support to the Rust compiler.#160298
rcvalle wants to merge 8 commits into
rust-lang:mainfrom
rcvalle:rust-heap-partitioning

Conversation

@rcvalle

@rcvalle rcvalle commented Jul 31, 2026

Copy link
Copy Markdown
Member

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

rcvalle added 8 commits July 31, 2026 11:54
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.
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-compiletest Area: The compiletest test runner A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 31, 2026
@rcvalle rcvalle changed the title Add LVM AllocToken and Heap Partitioning Support to the Rust compiler. Add LLVM AllocToken and Heap Partitioning Support to the Rust compiler. Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-compiletest Area: The compiletest test runner A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

3 participants