WIP: [PAC] Add intrinsic based support for transmute_copy - #162121
Draft
jchlanda wants to merge 10 commits into
Draft
WIP: [PAC] Add intrinsic based support for transmute_copy#162121jchlanda wants to merge 10 commits into
jchlanda wants to merge 10 commits into
Conversation
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.
This covers standalone function pointer constants, promoted temporaries, immutable and mutable statics, arrays of function pointers, and mixed structs containing function pointers. Consult pauth-fn-ptr-type-discrimination-static-allocs.rs test for example uses. Revolves around threading PAC information through: * static_addr_of (StaticCodegenMethods) * from_const and from_const_alloc (both on rustc_codegen_ssa::mir::operand / OperandRef)
Implement pointer authentication resigning for function pointer transmutes that differ in their discriminators. Resigning only happens for function pointers (their transparent wrappers and Option<T>). Aggregates (even those containing function pointer members) are deliberately kept as opaque values with no resigning.
…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.
And update to the main pauthtest document: * list new tests * remove the need for patching `libc` as the changes to it already went in. Unfortunately `cc-rs` is held back by `compiler/rustc_llvm/Cargo.toml` which pins to an old version: `cc = "=1.2.16"`
This comment has been minimized.
This comment has been minimized.
jchlanda
force-pushed
the
jakub/pac_transmute_copy
branch
from
September 1, 2026 14:23
3b55b24 to
36f5b8e
Compare
This comment has been minimized.
This comment has been minimized.
Lower the intrinsic to a dedicated `TransmuteCopy` cast and, when available, insert the library precondition check requiring the source to contain at least `size_of::<Dst>()` bytes. Handle `TransmuteCopy` as a direct read of `Dst` from the source address, allowing shrinking transmutes and unsized sources. Use the source's known alignment together with the destination alignment to avoid emitting loads with stronger alignment requirements than the source can guarantee. Statically provable size violations are treated as unreachable during codegen, while dynamically-sized sources retain the runtime precondition check. For slices and `str`, known length metadata is used to prove that the source is too short; for `dyn Trait` no such support is provided (to avoid reading v-tables). Intrinsic-based implementation makes it possible for the codegen to provide support for function pointer type discrimination, in particular the need to resign function pointers when a transmute changes their discriminator.
jchlanda
force-pushed
the
jakub/pac_transmute_copy
branch
from
September 1, 2026 14:36
36f5b8e to
5df4c89
Compare
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
mejrs
requested changes
Sep 1, 2026
| /// [core::mem::transmute_copy]. It is intended for use by the standard | ||
| /// library and compiler and should not be called directly. | ||
| #[stable(feature = "transmute_copy", since = "1.0.0")] | ||
| #[rustc_allowed_through_unstable_modules = "import this function via std::mem instead"] |
Member
There was a problem hiding this comment.
Suggested change
| #[rustc_allowed_through_unstable_modules = "import this function via std::mem instead"] |
Please do not add more uses of this attribute. We are trying very hard to get rid of it entirely.
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
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.
Lower the intrinsic to a dedicated
TransmuteCopycast and, when available, insert the library precondition check requiring the source to contain at leastsize_of::<Dst>()bytes.Handle
TransmuteCopyas a direct read ofDstfrom the source address, allowing shrinking transmutes and unsized sources. Use the source's known alignment together with the destination alignment to avoid emitting loads with stronger alignment requirements than the source can guarantee.Statically provable size violations are treated as unreachable during codegen, while dynamically-sized sources retain the runtime precondition check. For slices and
str, known length metadata is used to prove that the source is too short; fordyn Traitno such support is provided (to avoid reading v-tables).Intrinsic-based implementation makes it possible for the codegen to provide support for function pointer type discrimination, in particular the need to resign function pointers when a transmute changes their discriminator.