[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 |
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? compiler |
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>.
8b0e0ca to
67fd305
Compare
|
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. |
|
r? @davidtwco |
| @@ -0,0 +1,493 @@ | |||
| /*! | |||
There was a problem hiding this comment.
Use //! so that this is a documentation comment
| @@ -0,0 +1,142 @@ | |||
| // LLVM SipHash-2-4 | |||
There was a problem hiding this comment.
Why can't we just call LLVM's definitions of these over FFI from rustc_codegen_llvm? That let us avoid the need for this to remain identical to LLVM's definition
| /// This is not a full semantic translation of Rust types. It is a lossy mapping | ||
| /// that intentionally matches Clang's function pointer authentication encoding | ||
| /// rules where Rust has a direct language-level equivalent. |
There was a problem hiding this comment.
These lines are duplicated
| let ty = canonicalize_c_type(tcx, ty); | ||
| match ty.kind() { | ||
| // C void / Rust () | ||
| ty::Tuple(list) if list.is_empty() => ClangDiscTy::Void, |
There was a problem hiding this comment.
_ if ty.is_unit() is clearer
|
|
||
| loop { | ||
| match ty.kind() { | ||
| ty::Adt(def, args) if tcx.is_diagnostic_item(sym::Option, def.did()) => { |
There was a problem hiding this comment.
You should use the LangItem::Option, rather than the diagnostic item, given this isn't for a diagnostic.
|
|
||
| // Clang disc type. | ||
| #[derive(Debug)] | ||
| enum ClangDiscTy<'tcx> { |
There was a problem hiding this comment.
I'm not sure what we're gaining from having this intermediate representation - the mapping seems straightforward enough that you could just go direct from a Ty to a encoding
| All tests from `assembly-llvm`, `codegen-llvm`, `codegen-units`, `coverage`, | ||
| `crashes`, `incremental`, `library`, `mir-opt`, `run-make`, `ui` and | ||
| `ui-fulldeps` subsets are expected to pass. | ||
| `crashes`, `incremental`, `library`, `mir-opt`, `run-make`, `rust_middle` `ui` |
There was a problem hiding this comment.
| `crashes`, `incremental`, `library`, `mir-opt`, `run-make`, `rust_middle` `ui` | |
| `crashes`, `incremental`, `library`, `mir-opt`, `run-make`, `rust_middle`, `ui` |
|
Reminder, once the PR becomes ready for a review, use |
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