Skip to content

[PAC] Minicore updates to support fn ptr type discriminator tests (7/8)#159086

Open
jchlanda wants to merge 8 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_7
Open

[PAC] Minicore updates to support fn ptr type discriminator tests (7/8)#159086
jchlanda wants to merge 8 commits into
rust-lang:mainfrom
jchlanda:jakub/pac_ty_disc_PR_7

Conversation

@jchlanda

@jchlanda jchlanda commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` 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_7 branch from 54447d2 to 6c09f27 Compare July 10, 2026 14:39
@rust-bors

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_7 branch 2 times, most recently from a762c6a to 71a56a5 Compare July 14, 2026 07:30
@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_7 branch from 71a56a5 to d4e180d Compare July 14, 2026 08:55
@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_7 branch from d4e180d to efa84d7 Compare July 17, 2026 07:06
@rust-log-analyzer

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_7 branch 2 times, most recently from f8bd7ba to d3e6fb9 Compare July 17, 2026 09:49

#[lang = "c_void"]
#[repr(u8)]
#[allow(non_camel_case_types)]

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

Why do we need this change? I see c_void used in tests, but I'm not sure why these naming changes are required (the enum elements do not look directly used in tests anyway)

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.

Without it tidy would fail (and it is run as part of PR CI tests).

7
}
}
impl Add for i32 {

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

I failed to find direct uses of Add trait or add function in tests. Could you please explain why we need this new implementation for i32 here?

View changes since the review

@jchlanda jchlanda Jul 21, 2026

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.

Because + operator is resolved to Add, so without the code above this will fail to compile for minicore:

extern "C" fn foo(x: i32) -> i32 {
    x + 1
}

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_7 branch 4 times, most recently from 6ed41f8 to b4ef371 Compare July 23, 2026 08:46
@rust-bors

This comment has been minimized.

@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_7 branch from b4ef371 to 6559148 Compare July 24, 2026 15:23
jchlanda added 8 commits July 24, 2026 15:24
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.
The codegen now walks the layout of static initializer types to find extern "C"
function pointer fields, computes their type discriminators, and applies those
discriminators when emitting authenticated function pointer relocations.

Also make sure that type discrimination is never applied to init/fini
entries.
Implement pointer authentication domain handling for function pointer
transmutes. When function pointer type discrimination is enabled,
transmuting between function pointer types with different authentication
domains now re-signs the pointer using the appropriate discriminator.
…addr` call sites

Fill in function pointer type discriminators logic across remaining
`get_fn_addr` call sites and explicitly avoid applying it where
discrimination is not meaningful.

Some uses of `get_fn_addr` are intentionally left unsigned, including
the EH personality function, entry wrappers, and compiler-generated Rust
ABI shims.
@jchlanda
jchlanda force-pushed the jakub/pac_ty_disc_PR_7 branch from 6559148 to c926f3d Compare July 24, 2026 16:07
@jchlanda jchlanda changed the title [WIP] 7 - Minicore updates to support fn ptr type discriminator tests [PAC] Minicore updates to support fn ptr type discriminator tests (7/8) Jul 24, 2026
@jchlanda
jchlanda marked this pull request as ready for review July 24, 2026 18:09
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

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

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

cc @Noratrieb

@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
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
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 16 candidates

@jchlanda

Copy link
Copy Markdown
Contributor Author

r? compiler

@rustbot rustbot assigned davidtwco and unassigned mu001999 Jul 24, 2026
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-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` 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.

6 participants