[PAC] Encoder and hash (1/8) - #159071
Conversation
bca55be to
8cf67b9
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
8cf67b9 to
7ee3f2c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7ee3f2c to
fdd1189
Compare
This comment has been minimized.
This comment has been minimized.
d798449 to
4c1b0ac
Compare
Done in: 5e05159 |
03337eb to
8b0e0ca
Compare
|
Some changes occurred in src/doc/rustc/src/platform-support cc @Noratrieb |
…uwer Rollup of 16 pull requests Successful merges: - #159071 ([PAC] Encoder and hash (1/8)) - #161068 (Ensure TLS accesses don't call the global allocator through panic (part 3) ) - #161332 (Some `GlobalCtxt`/`Session` cleanups) - #161344 (Update the `rustc-perf` submodule) - #150931 (rustdoc: Always document `#[repr(transparent)]` if `#[rustc_pub_transparent]` is applied) - #160582 (Add `remove hidden_glob_reexports item breaks downstream` test) - #160876 (remove unwrap from write_mir_fn_graphviz) - #160927 (Enhance EII UI tests) - #161070 (fix arm homogeneous aggregate ABI) - #161236 (Download auto jobs in citool in parallel) - #161254 (Reserve capacity for 3% anon nodes) - #161283 (Tighten the language used for documenting `TargetOptions::llvm_abiname`) - #161291 (Rename `ProjectionPredicate` and `TraitPredicate`) - #161299 (Remove a bunch of unnecessary explicit lifetimes) - #161307 (make ARM maintainers pingable) - #161308 (Add regression test for rustc diagnostic to recognize variables in match guards)
This comment has been minimized.
This comment has been minimized.
[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](#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](#159074) 3. [FPTR_TYPE_DISCR in ABI Version](#159075) 4. [Static allocs](#159081) 5. [Transmutes](#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](#159084) 7. [Minicore updates to support fn ptr type discriminator tests](#159086) 8. [Fn ptr type discrimination tests](#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: #155722 * Library support follow up: #156548 * Config follow up: #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)
|
💔 Test for b088fd7 failed: CI. Failed job:
|
|
@bors retry |
…=davidtwco [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#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] 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#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)
…uwer Rollup of 26 pull requests Successful merges: - #161384 (Bust sccache's cache) - #161325 (Bump bootstrap to 1.99.0-beta.1) - #161344 (Update the `rustc-perf` submodule) - #161366 (Subtree sync for rustc_codegen_cranelift) - #159071 ([PAC] Encoder and hash (1/8)) - #160639 ([rustdoc] Only generate search DOM elements if the search is actually needed) - #161068 (Ensure TLS accesses don't call the global allocator through panic (part 3) ) - #161332 (Some `GlobalCtxt`/`Session` cleanups) - #150931 (rustdoc: Always document `#[repr(transparent)]` if `#[rustc_pub_transparent]` is applied) - #158999 (doc: list all remove_dir_all fallback targets) - #160582 (Add `remove hidden_glob_reexports item breaks downstream` test) - #160876 (remove unwrap from write_mir_fn_graphviz) - #160927 (Enhance EII UI tests) - #161070 (fix arm homogeneous aggregate ABI) - #161190 (fix crash in async-drop and async-gen) - #161236 (Download auto jobs in citool in parallel) - #161254 (Reserve capacity for 3% anon nodes) - #161283 (Tighten the language used for documenting `TargetOptions::llvm_abiname`) - #161291 (Rename `ProjectionPredicate` and `TraitPredicate`) - #161293 (add relnotes 1.98.0) - #161299 (Remove a bunch of unnecessary explicit lifetimes) - #161307 (make ARM maintainers pingable) - #161308 (Add regression test for rustc diagnostic to recognize variables in match guards) - #161346 (Don't rely on std traits not being const in tests) - #161360 (vec: fixup the name that i forgot) - #161367 (Reflect current PR title names for subtree syncs in triagebot no-merges)
Rollup merge of #159071 - jchlanda:jakub/pac_ty_disc_PR_1, r=davidtwco [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](#159071) 2. [FnAbi, llvm.ptrauth.resign and Session API change](#159074) 3. [FPTR_TYPE_DISCR in ABI Version](#159075) 4. [Static allocs](#159081) 5. [Transmutes](#159082) 6. [Propagate discriminator logic through remaining get_fn_ptr calls sites](#159084) 7. [Minicore updates to support fn ptr type discriminator tests](#159086) 8. [Fn ptr type discrimination tests](#159087) --- Useful links: * Previous PAC work: * `pauthtest` introduction: #155722 * Library support follow up: #156548 * Config follow up: #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)
[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)
…uwer Rollup of 26 pull requests Successful merges: - rust-lang/rust#161384 (Bust sccache's cache) - rust-lang/rust#161325 (Bump bootstrap to 1.99.0-beta.1) - rust-lang/rust#161344 (Update the `rustc-perf` submodule) - rust-lang/rust#161366 (Subtree sync for rustc_codegen_cranelift) - rust-lang/rust#159071 ([PAC] Encoder and hash (1/8)) - rust-lang/rust#160639 ([rustdoc] Only generate search DOM elements if the search is actually needed) - rust-lang/rust#161068 (Ensure TLS accesses don't call the global allocator through panic (part 3) ) - rust-lang/rust#161332 (Some `GlobalCtxt`/`Session` cleanups) - rust-lang/rust#150931 (rustdoc: Always document `#[repr(transparent)]` if `#[rustc_pub_transparent]` is applied) - rust-lang/rust#158999 (doc: list all remove_dir_all fallback targets) - rust-lang/rust#160582 (Add `remove hidden_glob_reexports item breaks downstream` test) - rust-lang/rust#160876 (remove unwrap from write_mir_fn_graphviz) - rust-lang/rust#160927 (Enhance EII UI tests) - rust-lang/rust#161070 (fix arm homogeneous aggregate ABI) - rust-lang/rust#161190 (fix crash in async-drop and async-gen) - rust-lang/rust#161236 (Download auto jobs in citool in parallel) - rust-lang/rust#161254 (Reserve capacity for 3% anon nodes) - rust-lang/rust#161283 (Tighten the language used for documenting `TargetOptions::llvm_abiname`) - rust-lang/rust#161291 (Rename `ProjectionPredicate` and `TraitPredicate`) - rust-lang/rust#161293 (add relnotes 1.98.0) - rust-lang/rust#161299 (Remove a bunch of unnecessary explicit lifetimes) - rust-lang/rust#161307 (make ARM maintainers pingable) - rust-lang/rust#161308 (Add regression test for rustc diagnostic to recognize variables in match guards) - rust-lang/rust#161346 (Don't rely on std traits not being const in tests) - rust-lang/rust#161360 (vec: fixup the name that i forgot) - rust-lang/rust#161367 (Reflect current PR title names for subtree syncs in triagebot no-merges)
…=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)
…=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)
…=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)
…=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)
| Void, | ||
| } | ||
|
|
||
| // Canonicalize Option-wrapped pointer types used to model C nullable pointers. |
There was a problem hiding this comment.
This is yet another copy of code that already exists multiple times in different forms in the compiler. (And it is wrong for multiple reasons: it does not take into account repr(transparent), and it mixes up raw pointers and references.)
I don't know when we should put our foot down and refuse to add more copies of the same code, insisting on a refactor instead. But I know that if we keep going like this, we'll end up with an unmaintainable buggy mess.
(Also see #119183.)
View all comments
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:
Useful links:
pauthtestintroduction: Introduce aarch64-unknown-linux-pauthtest target #155722