Skip to content

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

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

[PAC] FPTR_TYPE_DISCR in ABI Version (3/8)#159075
jchlanda wants to merge 6 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

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
  5. Transmutes
  6. Propagate discriminator logic through remaining get_fn_ptr calls sites
  7. Minicore updates to support fn ptr type discriminator tests
  8. Fn ptr type discrimination tests

Useful links:

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 10, 2026
@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

@nnethercote

Copy link
Copy Markdown
Contributor

rustbot has assigned @petrochenkov

followed immediately by:

@rustbot rustbot assigned nnethercote and unassigned petrochenkov

which is weird.

Anyway, I don't know the first thing about this stuff, so I'll try to find a better reviewer.

@rust-bors

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from 06c9628 to ca7b683 Compare July 27, 2026 09:54
@rustbot

This comment has been minimized.

@davidtwco

Copy link
Copy Markdown
Member

r? @davidtwco

@rustbot

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from a37eed3 to 7e2fc91 Compare August 10, 2026 08:08
@rustbot rustbot added the A-meta Area: Issues & PRs about the rust-lang/rust repository itself label Aug 10, 2026
@rustbot

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from 7e2fc91 to b17fc30 Compare August 12, 2026 06:23
@rustbot

This comment has been minimized.

This patch implements Rust's equivalent of Clang's function pointer type
discriminator computation used in pointer authentication. Compatibility
with Clang is a primary goal. The discriminator produced for a given
external "C" function type must match the value computed by Clang so
that function pointers can be exchanged safely between Rust and C code
while preserving pointer authentication semantics.

The implementation mirrors Clang's behavior in
`ASTContext::encodeTypeForFunctionPointerAuth`, ensuring that identical
C-compatible function types produce identical discriminators. See:
<https://clang.llvm.org/doxygen/ASTContext_8cpp.html#abb1375e068e807917527842d05cadea3>.
This patch introduces the following:

* Extends `FnAbi` (`callconv`) with a `ptrauth_type_discriminator`
  field. This field is only used when emitting pointer authentication
  call bundles. It is stored in `FnAbi` because the call site is not
  guaranteed to have access to an `Instance`, so the discriminator
  cannot always be computed on demand.
* Adds support for `llvm.ptrauth.resign`. This intrinsic will be used
  when support for semantic transmute is added.
* Performs a minor API redesign as groundwork for allowing call sites to
  modify schemas in place.
Also remove error messages/tests that used to guarded it.
@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_3 branch from b17fc30 to 8d33da6 Compare August 17, 2026 08:42
@rustbot

rustbot commented Aug 17, 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.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 19, 2026
…=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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 19, 2026
…=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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 19, 2026
…=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)
rust-bors Bot pushed a commit that referenced this pull request Aug 19, 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](#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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 19, 2026
…=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)
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