[PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) - #159074
[PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8)#159074jchlanda wants to merge 2 commits into
Conversation
8f37395 to
0792cdd
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0792cdd to
281565d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
281565d to
360a700
Compare
This comment has been minimized.
This comment has been minimized.
089232b to
d85aa6b
Compare
| let discriminator = if self.sess().pointer_authentication_fn_ptr_type_discrimination() { | ||
| fn_abi?.ptrauth_type_discriminator | ||
| } else { | ||
| 0 |
There was a problem hiding this comment.
Do we need this check here? As far as I can see, we already conditionally set ptrauth_type_discriminator to 0 if pointer_authentication_fn_ptr_type_discrimination() is false in compiler/rustc_ty_utils/src/abi.rs. Maybe we can even rename ptrauth_type_discriminator field in FnAbi to smth like just ptrauth_discriminator and assume it's storing the "effective" discriminator (either 0 or type discriminator)?
Just loudly thinking, I might easily miss smth - I would appreciate your explanation if I've got smth wrong
There was a problem hiding this comment.
You are right, we don't need it here, added comment about it though.
Also renaming to ptrauth_discriminator.
| ), | ||
| ptrauth_type_discriminator: if tcx.sess.pointer_authentication_fn_ptr_type_discrimination() | ||
| { | ||
| compute_fn_ptr_type_discriminator_for(tcx, sig).unwrap_or(0).into() |
There was a problem hiding this comment.
Just in case: do I get it correct that the sequence of PRs is not about "at each point we are expected to have a successful build", it's about ease of review only?
I'm just not seeing compute_fn_ptr_type_discriminator_for defined at this point - was it intentional or should PR content split decisions be reconsidered?
There was a problem hiding this comment.
No, you do not. It is intended to be buildable at each stage.
The split is twofold: logical, to show the progression of the implementation, and functional, since each commit is expected to be independently buildable. They are not exactly atomic in the sense that the functionality will not be complete, so if you check out a commit in the middle of the sequence, it should build, but the generated code might not be fully correct.
The function you are referring to was added in the first PR of the series:
https://github.com/rust-lang/rust/pull/159071/changes#diff-40f6b89998ba7d54d3f76fde93944eab9b8ba5a16eb1d763c598e2802a180af7R166
| /// Indicates if an unwind may happen across a call to this function. | ||
| pub can_unwind: bool, | ||
| /// Computed type discriminator for pointer authentication purpose. | ||
| pub ptrauth_type_discriminator: u64, |
There was a problem hiding this comment.
Just a future note: when submitting as final non-draft PR for mainline review, it might be worth to provide a summary why a new field in FnAbi is considered at this point the proper solution for our problem and why we really need that. The summary could be placed somewhere in the PR description/PR comments/elsewhere if a more appropriate place exists.
There was a problem hiding this comment.
Done, in the PR description.
d85aa6b to
7708e94
Compare
This comment has been minimized.
This comment has been minimized.
5d74d74 to
69e4d08
Compare
[PAC] Encoder and hash (1/8) This patch implements Rust's equivalent of Clang's function pointer type discriminator computation used for pointer authentication. Compatibility with Clang is a primary design goal. For a given extern "C" function type, the discriminator produced by Rust 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 implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang/rust#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang/rust#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang/rust#159075) 4. [Static allocs](rust-lang/rust#159081) 5. [Transmutes](rust-lang/rust#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang/rust#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang/rust#159086) 8. [Fn ptr type discrimination tests](rust-lang/rust#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang/rust#155722 * Library support follow up: rust-lang/rust#156548 * Config follow up: rust-lang/rust#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
|
This should be ready to land @davidtwco @JonathanBrouwer. Thank you! |
96a2710 to
5ebe84b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
5ebe84b to
1846500
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r+ |
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
| determined_fn_def_id, | ||
| sig.abi(), | ||
| ), | ||
| ptrauth_discriminator: if tcx.sess.pointer_authentication_fn_ptr_type_discrimination() { |
There was a problem hiding this comment.
From the PR description it sounds like this discriminator is fully a function of the argument/return types. Why does it need to be stored separately? That just risks having it somehow not be in sync with the actual argument/return types.
There was a problem hiding this comment.
Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on FnAbi's ArgAbi (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as FnAbi represents a lowered calling convention rather than the original function signature.
I don't follow the reasoning. The layout.ty in an ArgAbi reflects the actual source-level type. The layout.layout and the mode is lowered, additional information.
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
Rollup of 25 pull requests Successful merges: - #159074 ([PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8)) - #159792 (A more readable debug map for IndexMaps) - #161895 (std::sys::pal::sgx: fix mismatched alloc/free alignment) - #161900 (bootstrap: Include feature-gated items in bootstrap tool docs) - #161940 (Promote `wasm32-wasip3` to a tier 2 target) - #162072 (Add new Tier-3 target: `powerpc64-sony-ps3`) - #162179 (type system const items via direct rhs) - #162277 (Introduce `rustc_middle::middel::resolve`) - #162285 (box: fixup map/try_map deallocate calls) - #162286 (string: don't unwind prematurely) - #162289 (alloc: a bunch of safety comments) - #162292 (Update `askama` version to `0.16.1`) - #160509 (Remove `RegionExt`; move methods to `Region` in `rustc_type_ir`) - #160906 (Suggest usize instead of placeholder type for array length constants) - #160936 (traits: Represent live alias arguments as bitsets) - #161400 (Improve diagnostics for references to closures) - #161656 (Suggest mutable references for FnMut closure arguments) - #161711 (Add more splat fn type tests) - #161786 (Make `tcx.def_id_partial_cmp` public) - #161953 (sanitizers: Implicitly disable mutually exclusive sanitizers) - #162155 (add suggestion for `rustc_allowed_through_unstable_modules` attribute) - #162212 (Implement `Rng` for `Box`) - #162246 (Fix incorrect meta span) - #162266 (std: fix typo) - #162291 (Add regression test from 1.98.1)
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
Rollup of 25 pull requests Successful merges: - #159074 ([PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8)) - #159792 (A more readable debug map for IndexMaps) - #160745 (make closures act like MaybeDangling) - #161895 (std::sys::pal::sgx: fix mismatched alloc/free alignment) - #161940 (Promote `wasm32-wasip3` to a tier 2 target) - #162072 (Add new Tier-3 target: `powerpc64-sony-ps3`) - #162179 (type system const items via direct rhs) - #162277 (Introduce `rustc_middle::middel::resolve`) - #162285 (box: fixup map/try_map deallocate calls) - #162286 (string: don't unwind prematurely) - #162289 (alloc: a bunch of safety comments) - #162292 (Update `askama` version to `0.16.1`) - #160509 (Remove `RegionExt`; move methods to `Region` in `rustc_type_ir`) - #160906 (Suggest usize instead of placeholder type for array length constants) - #160936 (traits: Represent live alias arguments as bitsets) - #161400 (Improve diagnostics for references to closures) - #161656 (Suggest mutable references for FnMut closure arguments) - #161711 (Add more splat fn type tests) - #161786 (Make `tcx.def_id_partial_cmp` public) - #161953 (sanitizers: Implicitly disable mutually exclusive sanitizers) - #162155 (add suggestion for `rustc_allowed_through_unstable_modules` attribute) - #162212 (Implement `Rng` for `Box`) - #162246 (Fix incorrect meta span) - #162266 (std: fix typo) - #162291 (Add regression test from 1.98.1)
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
Rollup of 27 pull requests Successful merges: - #159074 ([PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8)) - #159792 (A more readable debug map for IndexMaps) - #160745 (make closures act like MaybeDangling) - #161940 (Promote `wasm32-wasip3` to a tier 2 target) - #162030 (Prevent `--test` to be used in `rustdoc-html` testsuite) - #162072 (Add new Tier-3 target: `powerpc64-sony-ps3`) - #162179 (type system const items via direct rhs) - #162262 (Avoid manually instantiating some binders in error reporting with `-Znext-solver`) - #162277 (Introduce `rustc_middle::middel::resolve`) - #162285 (box: fixup map/try_map deallocate calls) - #162286 (string: don't unwind prematurely) - #162289 (alloc: a bunch of safety comments) - #162290 (abby test DSL: AliasTyOutlivesViaEnv) - #162292 (Update `askama` version to `0.16.1`) - #160509 (Remove `RegionExt`; move methods to `Region` in `rustc_type_ir`) - #160906 (Suggest usize instead of placeholder type for array length constants) - #160936 (traits: Represent live alias arguments as bitsets) - #161400 (Improve diagnostics for references to closures) - #161656 (Suggest mutable references for FnMut closure arguments) - #161711 (Add more splat fn type tests) - #161786 (Make `tcx.def_id_partial_cmp` public) - #161953 (sanitizers: Implicitly disable mutually exclusive sanitizers) - #162155 (add suggestion for `rustc_allowed_through_unstable_modules` attribute) - #162212 (Implement `Rng` for `Box`) - #162246 (Fix incorrect meta span) - #162266 (std: fix typo) - #162291 (Add regression test from 1.98.1)
…=davidtwco [PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8) 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. The use of an extended `FnAbi` is dictated by the need to issue a ptrauth bundle for [call-like instructions](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/builder.rs#L1477). At that point, we only have access to the `FnAbi` struct (`Instance` is not guaranteed to be available). Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on `FnAbi`'s `ArgAbi` (for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), as `FnAbi` represents a lowered calling convention rather than the original function signature. Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact. --- This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination: 1. [Encoder and hash](rust-lang#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](rust-lang#159074) 3. [FPTR_TYPE_DISCR in ABI Version](rust-lang#159075) 4. [Static allocs](rust-lang#159081) 5. [Transmutes](rust-lang#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](rust-lang#159084) 7. [Minicore updates to support fn ptr type discriminator tests](rust-lang#159086) 8. [Fn ptr type discrimination tests](rust-lang#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: rust-lang#155722 * Library support follow up: rust-lang#156548 * Config follow up: rust-lang#156712 * [Project goal](https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html) and [tracking issue](rust-lang/goals#618) * Clang's implementation of [ASTContext::encodeTypeForFunctionPointerAuth](https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3) * LLVM's [SpiHash](https://github.com/llvm/llvm-project/blob/main/third-party/siphash/include/siphash/SipHash.h)
View all comments
This patch introduces the following:
FnAbi(callconv) with aptrauth_type_discriminatorfield. This field is only used when emitting pointer authentication call bundles. It is stored inFnAbibecause the call site is not guaranteed to have access to anInstance, so the discriminator cannot always be computed on demand.llvm.ptrauth.resign. This intrinsic will be used when support for semantic transmute is added.The use of an extended
FnAbiis dictated by the need to issue a ptrauth bundle for call-like instructions. At that point, we only have access to theFnAbistruct (Instanceis not guaranteed to be available).Fundamentally, the discriminator originates from the source-level function type. Deriving it at the codegen stage would introduce a layering violation: it would require relying on
FnAbi'sArgAbi(for both return values and arguments) to preserve source-level type information. This is not a guarantee provided by these abstractions (and in code comments), asFnAbirepresents a lowered calling convention rather than the original function signature.Computing the discriminator at this stage would therefore create a hard dependency on type information being available where it is not intended to be preserved. Carrying the value explicitly avoids reconstructing source-level information from lowered ABI data and keeps the abstraction boundaries intact.
This is part 2 of a sequence of 8 PRs that together implement support for function pointer type discrimination:
Useful links:
pauthtestintroduction: Introduce aarch64-unknown-linux-pauthtest target #155722