Skip to content

Conversation

melver
Copy link
Contributor

@melver melver commented Sep 4, 2025

Introduce AllocToken, an instrumentation pass designed to provide
tokens to memory allocators enabling various heap organization
strategies, such as heap partitioning.

Initially, the pass instruments functions marked with a new attribute
sanitize_alloc_token by rewriting allocation calls to include a token
ID, appended as a function argument with the default ABI.

The design aims to provide a flexible framework for implementing
different token generation schemes. It currently supports the following
token modes:

  • TypeHash (default): token IDs based on a hash of the allocated type
  • Random: statically-assigned pseudo-random token IDs
  • Increment: incrementing token IDs per TU

For the TypeHash mode introduce support for !alloc_token_hint
metadata: the metadata can be attached to allocation calls to provide
richer semantic information to be consumed by the AllocToken pass.
Optimization remarks can be enabled to show where no metadata was
available.

An alternative "fast ABI" is provided, where instead of passing the
token ID as an argument (e.g., __alloc_token_malloc(size, id)), the
token ID is directly encoded into the name of the called function (e.g.,
__alloc_token_0_malloc(size)). Where the maximum tokens is small, this
offers more efficient instrumentation by avoiding the overhead of
passing an additional argument at each allocation site.

Link: https://discourse.llvm.org/t/rfc-a-framework-for-allocator-partitioning-hints/87434 [1]


This change is part of the following series:

  1. [AllocToken] Introduce AllocToken instrumentation pass #156838
  2. [Clang] Introduce -fsanitize=alloc-token #156839
  3. [AllocToken, Clang] Implement TypeHashPointerSplit mode #156840
  4. [AllocToken, Clang] Infer type hints from sizeof expressions and casts #156841
  5. [AllocToken, Clang] Implement __builtin_alloc_token_infer() and llvm.alloc.token.id #156842

Created using spr 1.3.8-beta.1
melver added a commit to melver/llvm-project that referenced this pull request Sep 5, 2025
Introduce `AllocToken`, an instrumentation pass designed to provide
tokens to memory allocators enabling various heap organization
strategies, such as heap partitioning.

Initially, the pass instruments functions marked with a new attribute
`sanitize_alloc_token` by rewriting allocation calls to include a token
ID, appended as a function argument with the default ABI.

The design aims to provide a flexible framework for implementing
different token generation schemes. It currently supports the following
token modes:

- TypeHash (default): token IDs based on a hash of the allocated type
- Random: statically-assigned pseudo-random token IDs
- Increment: incrementing token IDs per TU

For the `TypeHash` mode introduce support for `!alloc_token_hint`
metadata: the metadata can be attached to allocation calls to provide
richer semantic information to be consumed by the AllocToken pass.
Optimization remarks can be enabled to show where no metadata was
available.

An alternative "fast ABI" is provided, where instead of passing the
token ID as an argument (e.g., `__alloc_token_malloc(size, id)`), the
token ID is directly encoded into the name of the called function (e.g.,
`__alloc_token_0_malloc(size)`). Where the maximum tokens is small, this
offers more efficient instrumentation by avoiding the overhead of
passing an additional argument at each allocation site.

Link: https://discourse.llvm.org/t/rfc-a-framework-for-allocator-partitioning-hints/87434 [1]
Pull Request: llvm#156838
Created using spr 1.3.8-beta.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant