Skip to content

[WIP] 6 - Propagate discriminator logic through remaining get_fn_ptr calls sites#159084

Draft
jchlanda wants to merge 6 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_6
Draft

[WIP] 6 - Propagate discriminator logic through remaining get_fn_ptr calls sites#159084
jchlanda wants to merge 6 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_6

Conversation

@jchlanda

@jchlanda jchlanda commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Fill in function pointer type discriminators logic across remaining get_fn_addr call sites and explicitly avoid applying it where discrimination is not meaningful.

Some uses of get_fn_addr are intentionally left unsigned, including the EH personality function, entry wrappers, and compiler-generated Rust ABI shims.


This is part 6 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:

@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
@rust-bors

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_6 branch 2 times, most recently from 6f06f96 to 17ad6d3 Compare July 14, 2026 07:29
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_6 branch from 17ad6d3 to 9a55906 Compare July 14, 2026 08:54
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_6 branch from 9a55906 to b331394 Compare July 17, 2026 07:05
@rust-log-analyzer

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_6 branch from b331394 to d42d5cf Compare July 17, 2026 08:24
jchlanda added 6 commits July 17, 2026 09:45
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 patch introduces the following:

* Extends `FnAbi` (`callconv`) with a `ptrauth_type_discriminator`
  field. This field is only used when emitting pointer authentication
  call bundles. It is stored in `FnAbi` because the call site is not
  guaranteed to have access to an `Instance`, so the discriminator
  cannot always be computed on demand.
* Adds support for `llvm.ptrauth.resign`. This intrinsic will be used
  when support for semantic transmute is added.
* Performs a minor API redesign as groundwork for allowing call sites to
  modify schemas in place.
Also remove error messages/tests that used to guarded it.
The codegen now walks the layout of static initializer types to find extern "C"
function pointer fields, computes their type discriminators, and applies those
discriminators when emitting authenticated function pointer relocations.

Also make sure that type discrimination is never applied to init/fini
entries.
Implement pointer authentication domain handling for function pointer
transmutes. When function pointer type discrimination is enabled,
transmuting between function pointer types with different authentication
domains now re-signs the pointer using the appropriate discriminator.
…addr` call sites

Fill in function pointer type discriminators logic across remaining
`get_fn_addr` call sites and explicitly avoid applying it where
discrimination is not meaningful.

Some uses of `get_fn_addr` are intentionally left unsigned, including
the EH personality function, entry wrappers, and compiler-generated Rust
ABI shims.
@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_6 branch from d42d5cf to aa26645 Compare July 17, 2026 09:49
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.

3 participants