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

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

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 24, 2026
@jchlanda

Copy link
Copy Markdown
Contributor Author

r? compiler

@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 17 candidates

@rustbot rustbot assigned nnethercote and unassigned petrochenkov Jul 24, 2026
@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

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 2a29609 to a37eed3 Compare August 3, 2026 07:56
@rustbot

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

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. 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