Skip to content

[WIP] 1 - Encoder and hash#159071

Draft
jchlanda wants to merge 5 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_1
Draft

[WIP] 1 - Encoder and hash#159071
jchlanda wants to merge 5 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_1

Conversation

@jchlanda

@jchlanda jchlanda commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This patch implements Rust's equivalent of Clang's function pointer type discriminator computation used in pointer authentication. Compatibility with Clang is a primary goal. The discriminator produced for a given external "C" function type must match the value computed by Clang so that function pointers can be exchanged safely between Rust and C code while preserving pointer authentication semantics.

The implementation mirrors Clang's behavior in ASTContext::encodeTypeForFunctionPointerAuth, ensuring that identical C-compatible function types produce identical discriminators. See: https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3.


This is part 1 of a sequence of 8 PRs, that together aim to bring function pointer type discrimination support:

  1. Encoder and hash
  2. FnAbi, llvm.ptrauth.resign and Session API change
  3. FPTR_TYPE_DISCR in ABI Version
  4. Static allocs
  5. Transmutes
  6. Propagate discriminator logic through remaining get_fn_ptr calls sites
  7. Minicore updates to support fn ptr type discriminator tests
  8. Fn ptr type discrimination tests

Useful links:

jchlanda added 5 commits July 9, 2026 11:37
This patch brings:
* unified handling of pointer authentication options through:
  `-Zpointer-authentication`, with possible values:
  `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`,
  `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`,
  `init-fini-address-discrimination`, `return-addresses`. Toggled with
  `+`/`-`.
* centralized handling of pointer authentication features. Session holds
  `pointer_auth_config: Option<PointerAuthConfig>`
* encapsulation of schema for function pointers and init/fini through
  `PointerAuthSchema`. This allowed for retiring of `PacMetadata`.
* refactor enabling of pointer authentication in code, instead of
  relying on the target (`pauthtest`) use the session
Also improve the API design of pointer_authentication_functions, by
making it return Option<&PointerAuthSchema>, rather than bool.
This patch implements Rust's equivalent of Clang's function pointer type
discriminator computation used in pointer authentication. Compatibility
with Clang is a primary goal. The discriminator produced for a given
external "C" function type must match the value computed by Clang so
that function pointers can be exchanged safely between Rust and C code
while preserving pointer authentication semantics.

The implementation mirrors Clang's behavior in
`ASTContext::encodeTypeForFunctionPointerAuth`, ensuring that identical
C-compatible function types produce identical discriminators. See:
<https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3>.
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants