Skip to content

[PAC] FPTR_TYPE_DISCR in ABI Version (3/8) - #159075

Open
jchlanda wants to merge 4 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_3
Open

jchlanda wants to merge 4 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_3

Conversation

@jchlanda

@jchlanda jchlanda commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This patch extends the ABI version to include FPTR_TYPE_DISCR. It also removes the diagnostics and tests that previously guarded the unsupported function pointer type discrimination feature, since that functionality is now implemented.


This is part 3 of a sequence of 8 PRs that together implement support for function pointer type discrimination:

  1. Encoder and hash
  2. FnAbi, llvm.ptrauth.resign and Session API change
  3. FPTR_TYPE_DISCR in ABI Version
  4. Static allocs
  1. Transmutes
  2. Propagate discriminator logic through remaining get_fn_ptr calls sites
  3. Minicore updates to support fn ptr type discriminator tests
  4. 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
@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch 2 times, most recently from d746518 to a098946 Compare July 14, 2026 07:27
@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_3 branch from a098946 to e1b80e7 Compare July 14, 2026 08:51
@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_3 branch from e1b80e7 to 7135bea Compare July 17, 2026 07:03
@rust-log-analyzer

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch 2 times, most recently from 66aaf1e to 951b670 Compare July 17, 2026 09:47
| (u32::from(self.indirect_gotos) << GOTOS)
| (u32::from(self.typeinfo_vt_ptr_discrimination) << TYPEINFO_VT_PTR_DISCR);
| (u32::from(self.typeinfo_vt_ptr_discrimination) << TYPEINFO_VT_PTR_DISCR)
| (u32::from(self.function_pointers.as_ref().is_some_and(|schema| {

@kovdan01 kovdan01 Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be beneficial to add some assertion ensuring that if function_pointers is some, it's kind must be only PointerAuthDiscrimination::Type?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not always true though,PointerAuthOption::Calls will result in default function pointer schema, which does not specify PointerAuthDiscrimination::Type (it uses: PointerAuthDiscrimination::None).

See here: https://github.com/jchlanda/rust/blob/951b6709c88f26ff7cf1848a553709478058d971/compiler/rustc_session/src/session.rs#L249

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from 951b670 to df46abe Compare July 20, 2026 12:52
@rust-log-analyzer

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch 3 times, most recently from af72799 to 06c9628 Compare July 24, 2026 15:41
@jchlanda jchlanda changed the title [WIP] 3 - FPTR_TYPE_DISCR in ABI Version [PAC] FPTR_TYPE_DISCR in ABI Version (3/8) Jul 24, 2026
@jchlanda
jchlanda marked this pull request as ready for review July 24, 2026 18:08
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/doc/rustc/src/platform-support

cc @Noratrieb

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

rust-bors Bot pushed a commit that referenced this pull request Aug 20, 2026
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)
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Aug 21, 2026
[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)
@jchlanda

Copy link
Copy Markdown
Contributor Author

Friendly ping on this one, the next one in the sequence @davidtwco. Thank you.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from 074005c to 465f7e2 Compare September 1, 2026 11:53
@rustbot

This comment has been minimized.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=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)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=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)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=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)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=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)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=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)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=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)
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 5, 2026
…=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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 5, 2026
…=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)
@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from 465f7e2 to 133ed3b Compare September 10, 2026 13:50
@rustbot

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch 2 times, most recently from b36b64f to a448c78 Compare September 16, 2026 07:40
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from b5a9f3c to 46e840b Compare September 23, 2026 09:28
@rustbot

This comment has been minimized.

@rust-bors

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.
Also remove error messages/tests that used to guarded it.
@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from 46e840b to dc27491 Compare September 24, 2026 10:22
@rustbot

rustbot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

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.

This branch has not been deployed

No deployments
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. A-meta Area: Issues & PRs about the rust-lang/rust repository itself S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

7 participants