From b578845d6200dd0d202449f92510fc6227e95fed Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Wed, 4 Nov 2026 13:31:37 +0000 Subject: [PATCH 1/6] [PAC] Minicore updates to support fn ptr type discriminator tests --- tests/auxiliary/minicore.rs | 53 +++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index aca69642057ab..2a0fc33513761 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -165,6 +165,8 @@ pub mod arch { pub struct PhantomData; impl Copy for PhantomData {} +#[rustc_diagnostic_item = "Option"] +#[lang = "Option"] pub enum Option { None, Some(T), @@ -302,11 +304,18 @@ pub trait Add { fn add(self, _: Rhs) -> Self::Output; } +// Avoid needing to add all of the overflow handling and panic language items impl Add for isize { type Output = isize; fn add(self, other: isize) -> isize { - 7 // avoid needing to add all of the overflow handling and panic language items + 7 + } +} +impl Add for i32 { + type Output = i32; + fn add(self, rhs: i32) -> i32 { + 7 } } @@ -353,18 +362,30 @@ impl_marker_trait!( ); impl Sync for () {} - impl Sync for [T; N] {} +impl Sync for Option {} +impl Sync for &T {} + // Function pointers are treated as `Sync` to match real `core` behavior. // // Minicore provides only the minimal set of impls required by tests. Rather // than exhaustively covering all possible function pointer signatures, -// additional impls should be added as needed. -impl Sync for fn() -> R {} -impl Sync for extern "C" fn() -> R {} -impl Sync for unsafe extern "C" fn() -> R {} -impl Sync for extern "C" fn(A) -> R {} -impl Sync for unsafe extern "C" fn(A) -> R {} +// additional arities should be added as needed. +macro_rules! impl_sync_for_fn_ptrs { + ($(($($T:ident),*)),* $(,)?) => { + $( + impl<$($T,)* R> Sync for fn($($T),*) -> R {} + + impl<$($T,)* R> Sync for extern "C" fn($($T),*) -> R {} + impl<$($T,)* R> Sync for unsafe extern "C" fn($($T),*) -> R {} + + impl<$($T,)* R> Sync for extern "C" fn($($T,)* ...) -> R {} + impl<$($T,)* R> Sync for unsafe extern "C" fn($($T,)* ...) -> R {} + )* + }; +} + +impl_sync_for_fn_ptrs!((), (A), (A, B), (A, B, C), (A, B, C, D),); #[lang = "drop_glue"] fn drop_glue(_: &mut T) {} @@ -401,7 +422,7 @@ pub trait CoerceUnsized {} impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {} #[lang = "drop"] -trait Drop { +pub trait Drop { fn drop(&mut self); } @@ -458,6 +479,15 @@ pub mod ptr { unsafe { volatile_store(dst, src) }; } + + #[inline] + #[rustc_diagnostic_item = "ptr_read_volatile"] + pub unsafe fn read_volatile(src: *const T) -> T { + #[rustc_intrinsic] + pub unsafe fn volatile_load(src: *const T) -> T; + + unsafe { volatile_load(src) } + } } pub mod hint { @@ -518,9 +548,10 @@ pub mod num { #[lang = "c_void"] #[repr(u8)] +#[allow(non_camel_case_types)] pub enum c_void { - __variant1, - __variant2, + Variant1, + Variant2, } #[allow_internal_unstable(internal_syntax)] From 4d8e7c21ccc4ea349fb3f271c08bab14ed7ee0d9 Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Wed, 4 Nov 2026 15:05:39 +0000 Subject: [PATCH 2/6] [PAC] Include the pointer authentication discriminator in `FnAbi` This patch brings: * adds `FnAbi::ptrauth_discriminator` * `is_ptrauth_signed_abi` unified point of control for pauth-supported ABIs * `ptrauth_signing_discriminator_for` - discriminator for given pointer under the schema (None - not supported ABI, constant, or calculated for pointer type) --- compiler/rustc_codegen_gcc/src/int.rs | 1 + compiler/rustc_codegen_llvm/src/builder.rs | 15 +-- compiler/rustc_codegen_llvm/src/common.rs | 8 +- .../rustc_middle/src/ptrauth/discriminator.rs | 127 +++++++----------- compiler/rustc_middle/src/ptrauth/mod.rs | 4 +- compiler/rustc_target/src/callconv/mod.rs | 11 +- compiler/rustc_ty_utils/src/abi.rs | 5 + .../aarch64-unknown-linux-pauthtest.md | 2 + tests/codegen-llvm/pauth/pauth-signed-abi.rs | 55 ++++++++ tests/ui/abi/c-zst.aarch64-darwin.stderr | 1 + tests/ui/abi/c-zst.powerpc-linux.stderr | 1 + tests/ui/abi/c-zst.s390x-linux.stderr | 1 + tests/ui/abi/c-zst.sparc-linux.stderr | 1 + tests/ui/abi/c-zst.sparc-none.stderr | 1 + tests/ui/abi/c-zst.sparc64-linux.stderr | 1 + tests/ui/abi/c-zst.x86_64-linux.stderr | 1 + .../ui/abi/c-zst.x86_64-pc-windows-gnu.stderr | 1 + tests/ui/abi/debug.generic.stderr | 13 ++ tests/ui/abi/debug.loongarch64.stderr | 13 ++ tests/ui/abi/debug.riscv64.stderr | 13 ++ .../x86-64-sysv64-arg-ext.apple.stderr | 6 + .../x86-64-sysv64-arg-ext.other.stderr | 6 + tests/ui/abi/pass-indirectly-attr.rs | 3 + tests/ui/abi/pass-indirectly-attr.stderr | 8 +- tests/ui/abi/rust-zst.aarch64-darwin.stderr | 1 + tests/ui/abi/rust-zst.powerpc-linux.stderr | 1 + tests/ui/abi/rust-zst.s390x-linux.stderr | 1 + tests/ui/abi/rust-zst.sparc-linux.stderr | 1 + tests/ui/abi/rust-zst.sparc-none.stderr | 1 + tests/ui/abi/rust-zst.sparc64-linux.stderr | 1 + tests/ui/abi/rust-zst.x86_64-linux.stderr | 1 + .../abi/rust-zst.x86_64-pc-windows-gnu.stderr | 1 + tests/ui/abi/sysv64-zst.stderr | 1 + .../pass-by-value-abi.aarch64.stderr | 3 +- tests/ui/c-variadic/pass-by-value-abi.rs | 3 + .../c-variadic/pass-by-value-abi.win.stderr | 3 +- .../pass-by-value-abi.x86_64.stderr | 9 +- 37 files changed, 222 insertions(+), 103 deletions(-) create mode 100644 tests/codegen-llvm/pauth/pauth-signed-abi.rs diff --git a/compiler/rustc_codegen_gcc/src/int.rs b/compiler/rustc_codegen_gcc/src/int.rs index bef1af78c6a7a..3b0189432fa03 100644 --- a/compiler/rustc_codegen_gcc/src/int.rs +++ b/compiler/rustc_codegen_gcc/src/int.rs @@ -425,6 +425,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { fixed_count: 3, conv: CanonAbi::C, can_unwind: false, + ptrauth_discriminator: None, }; fn_abi.adjust_for_foreign_abi(self.cx, ExternAbi::C { unwind: false }); diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 2f57ecdaa6f19..cdc817fe95540 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -7,7 +7,7 @@ pub(crate) mod autodiff; pub(crate) mod gpu_offload; use libc::{c_char, c_uint}; -use rustc_abi::{self as abi, Align, CanonAbi, Float, Size, WrappingRange}; +use rustc_abi::{self as abi, Align, Float, Size, WrappingRange}; use rustc_attr_ir::UnrollAttr; use rustc_codegen_ssa::MemFlags; use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope}; @@ -2156,11 +2156,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { ) -> Option> { let schema = self.sess().pointer_authentication_functions()?; - // Pointer authentication support is currently limited to extern "C" calls; filter out other - // ABIs. - if fn_abi?.conv != CanonAbi::C { - return None; - } + // `ptrauth_discriminator` is only Some for ABIs that support pointer authentication (None + // by default) - see `is_ptrauth_signed_abi`. + let discriminator = fn_abi?.ptrauth_discriminator?; // Filter out LLVM intrinsics. if llvm::get_value_name(llfn).starts_with(b"llvm.") { return None; @@ -2175,10 +2173,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { // discussion in the rust-lang issue: Some(llvm::OperandBundleBox::new( "ptrauth", - &[ - self.const_u32(schema.key as u32), - self.const_u64(schema.constant_discriminator as u64), - ], + &[self.const_u32(schema.key as u32), self.const_u64(discriminator)], )) } diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index c6f2ea0f82ab3..0c358c469120a 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -4,7 +4,7 @@ use std::borrow::Borrow; use libc::c_uint; use rustc_abi::Primitive::Pointer; -use rustc_abi::{self as abi, ExternAbi, HasDataLayout as _}; +use rustc_abi::{self as abi, HasDataLayout as _}; use rustc_ast::Mutability; use rustc_codegen_ssa::traits::*; use rustc_crate_store::DllImport; @@ -13,6 +13,7 @@ use rustc_hashes::Hash128; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar}; +use rustc_middle::ptrauth::is_ptrauth_signed_abi; use rustc_middle::ty::{Instance, TyCtxt}; use rustc_session::{PointerAuthAddressDiscriminator, PointerAuthSchema}; use rustc_span::bug; @@ -40,9 +41,8 @@ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>( if !matches!(cx.tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn) { return llfn; } - // Only C ABI - let abi = cx.tcx.fn_sig(def_id).skip_binder().abi(); - if !matches!(abi, ExternAbi::C { .. } | ExternAbi::System { .. }) { + // Only supported ABIs + if !is_ptrauth_signed_abi(cx.tcx.fn_sig(def_id).skip_binder().abi()) { return llfn; } // Ignore LLVM intrinsics diff --git a/compiler/rustc_middle/src/ptrauth/discriminator.rs b/compiler/rustc_middle/src/ptrauth/discriminator.rs index d44ecafb775ef..4e10eeb224663 100644 --- a/compiler/rustc_middle/src/ptrauth/discriminator.rs +++ b/compiler/rustc_middle/src/ptrauth/discriminator.rs @@ -48,15 +48,15 @@ //! - High-level API //! - `FnPtrDiscriminatorSource` //! - `ptrauth_compute_fn_ptr_type_discriminator_for` -//! - `ptrauth_clone_discriminated_schema_for` +//! - `is_ptrauth_signed_abi` +//! - `ptrauth_signing_discriminator_for` //! //! - Low-level API -//! - `FnPtrTypeDiscriminatorInput` +//! - `FnPtrTypeDiscriminatorInput` - canonical function signature input for +//! discriminator calculation (as a convenience it exposes the function ABI +//! through `abi()`) //! - `compute_fn_ptr_type_discriminator` //! -//! - Signature extraction -//! - `extract_fn_ptr_type` -//! //! - Clang-compatible type model //! - `ClangDiscTy` //! - `canonicalize_c_type` @@ -72,12 +72,13 @@ //! discriminator computation. Divergence from Clang will result in incompatible //! pointer authentication values across language boundaries. //! -//! This implementation intentionally approximates Clang's behavior for extern "C" -//! function types only. It does NOT attempt to model full type system rules. +//! This implementation intentionally approximates Clang's behavior for +//! `extern "C"` and `extern "system"` function types only. It does NOT attempt +//! to model full Rust type system rules. use rustc_abi::ExternAbi; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, Unnormalized}; -use rustc_session::PointerAuthSchema; +use rustc_session::{PointerAuthDiscrimination, PointerAuthSchema}; use rustc_span::sym; use crate::ptrauth::llvm_siphash::llvm_pointer_auth_stable_siphash; @@ -96,30 +97,20 @@ pub trait FnPtrDiscriminatorSource<'tcx>: Sized { fn discriminator_input(self, tcx: TyCtxt<'tcx>) -> Option>; } -/// Enables discriminator computation directly from Rust function types. -/// -/// Accepts both: -/// - `FnPtr`: actual function pointer types -/// - `FnDef`: function items +/// Enables discriminator computation for function pointer types. /// -/// FnDef is only accepted for convenience; the discriminator is still computed -/// from the instantiated function signature. +/// Only `FnPtr` is accepted: function items (`FnDef`) have no runtime code +/// address, and wrappers such as `Option` must be handled separately. impl<'tcx> FnPtrDiscriminatorSource<'tcx> for Ty<'tcx> { fn discriminator_input(self, tcx: TyCtxt<'tcx>) -> Option> { - let ty = extract_fn_ptr_type(tcx, self)?; - + let ty = tcx.normalize_erasing_regions( + ty::TypingEnv::fully_monomorphized(), + Unnormalized::new(self), + ); match ty.kind() { ty::FnPtr(sig, header) => { - let sig = sig.skip_binder(); - Some(FnPtrTypeDiscriminatorInput::from_sig_tys(sig, header)) - } - - ty::FnDef(def_id, args) => { - let sig = tcx.fn_sig(*def_id).instantiate(tcx, args.skip_binder()).skip_binder(); - - Some(FnPtrTypeDiscriminatorInput::from_sig(sig)) + Some(FnPtrTypeDiscriminatorInput::from_sig_tys(sig.skip_binder(), header)) } - _ => None, } } @@ -169,37 +160,37 @@ where S: FnPtrDiscriminatorSource<'tcx>, { let input = source.discriminator_input(tcx)?; - Some(compute_fn_ptr_type_discriminator(tcx, &input)) + compute_fn_ptr_type_discriminator(tcx, &input) } -/// Clones a pointer authentication schema and updates its constant -/// discriminator. -/// -/// If `schema` is `Some`, the function computes a function pointer type -/// discriminator from `source` and stores it in the cloned schema's -/// `constant_discriminator` field. -/// -/// If no discriminator can be computed (for example, because `source` does not -/// represent a function pointer type), the schema is returned unchanged. +/// Return true if a function pointer with this ABI is signed under pointer +/// authentication and calls through them authenticated. +pub fn is_ptrauth_signed_abi(abi: ExternAbi) -> bool { + matches!(abi, ExternAbi::C { .. } | ExternAbi::System { .. }) +} + +/// Returns a discriminator for function pointer in `source` that is used for +/// signing and authentication under given `schema`. None if the function ABI +/// does not support function pointer authentication. /// -/// This is intended as a convenience helper for code generation sites that need -/// to attach function pointer type discrimination to a generic schema before -/// calling `get_fn_addr`. -pub fn ptrauth_clone_discriminated_schema_for<'tcx, S>( +/// With function pointer type discrimination this is the discriminator +/// calculated for the `source`, otherwise `schema`'s constant discriminator. +pub fn ptrauth_signing_discriminator_for<'tcx, S>( tcx: TyCtxt<'tcx>, - mut schema: Option, + schema: &PointerAuthSchema, source: S, -) -> Option +) -> Option where S: FnPtrDiscriminatorSource<'tcx>, { - if let Some(ref mut s) = schema { - if let Some(disc) = ptrauth_compute_fn_ptr_type_discriminator_for(tcx, source) { - s.constant_discriminator = disc; - } + let input = source.discriminator_input(tcx)?; + if !is_ptrauth_signed_abi(input.abi()) { + return None; + } + match schema.discrimination_kind { + PointerAuthDiscrimination::Type => compute_fn_ptr_type_discriminator(tcx, &input), + _ => Some(schema.constant_discriminator), } - - schema } /// Canonical representation of a function signature used for pointer @@ -213,6 +204,10 @@ pub struct FnPtrTypeDiscriminatorInput<'tcx> { } impl<'tcx> FnPtrTypeDiscriminatorInput<'tcx> { + pub fn abi(&self) -> ExternAbi { + self.abi + } + fn from_sig(sig: ty::FnSig<'tcx>) -> Self { FnPtrTypeDiscriminatorInput { inputs: sig.inputs(), @@ -232,39 +227,17 @@ impl<'tcx> FnPtrTypeDiscriminatorInput<'tcx> { } } -/// Unwraps optional function pointers and normalizes the type. -/// -/// Only `Option` is supported for nullability modeling, matching C ABI -/// null pointer conventions. -fn extract_fn_ptr_type<'tcx>(tcx: TyCtxt<'tcx>, mut ty: Ty<'tcx>) -> Option> { - ty = tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), Unnormalized::new(ty)); - - loop { - match ty.kind() { - ty::Adt(def, args) if tcx.lang_items().option_type() == Some(def.did()) => { - ty = args.type_at(0); - continue; - } - - ty::FnPtr(..) | ty::FnDef(..) => { - return Some(ty); - } - - _ => return None, - } - } -} - /// Computes the Clang-compatible function pointer type discriminator. /// -/// This is the low-level discriminator computation routine operating on an -/// already constructed `FnPtrTypeDiscriminatorInput`. +/// This is the low-level discriminator calculation function operating on +/// `FnPtrTypeDiscriminatorInput`. Returns `None` for unsupported ABIs (see +/// `is_ptrauth_signed_abi`). fn compute_fn_ptr_type_discriminator<'tcx>( tcx: TyCtxt<'tcx>, input: &FnPtrTypeDiscriminatorInput<'tcx>, -) -> u16 { - if !matches!(input.abi, ExternAbi::C { .. } | ExternAbi::System { .. }) { - return 0; +) -> Option { + if !is_ptrauth_signed_abi(input.abi) { + return None; } let mut enc = PtrauthEncoder::new(); @@ -282,7 +255,7 @@ fn compute_fn_ptr_type_discriminator<'tcx>( enc.push(b'E'); - enc.finish() + Some(enc.finish()) } // Clang disc type. diff --git a/compiler/rustc_middle/src/ptrauth/mod.rs b/compiler/rustc_middle/src/ptrauth/mod.rs index 0eeef5e07f61c..d98e45eb4e07b 100644 --- a/compiler/rustc_middle/src/ptrauth/mod.rs +++ b/compiler/rustc_middle/src/ptrauth/mod.rs @@ -2,6 +2,6 @@ pub mod discriminator; pub mod llvm_siphash; pub use discriminator::{ - FnPtrDiscriminatorSource, FnPtrTypeDiscriminatorInput, ptrauth_clone_discriminated_schema_for, - ptrauth_compute_fn_ptr_type_discriminator_for, + FnPtrDiscriminatorSource, FnPtrTypeDiscriminatorInput, is_ptrauth_signed_abi, + ptrauth_compute_fn_ptr_type_discriminator_for, ptrauth_signing_discriminator_for, }; diff --git a/compiler/rustc_target/src/callconv/mod.rs b/compiler/rustc_target/src/callconv/mod.rs index 79ced518115cf..64b6bb105c1da 100644 --- a/compiler/rustc_target/src/callconv/mod.rs +++ b/compiler/rustc_target/src/callconv/mod.rs @@ -664,12 +664,18 @@ pub struct FnAbi<'a, Ty> { pub conv: CanonAbi, /// Indicates if an unwind may happen across a call to this function. pub can_unwind: bool, + /// The function pointer discriminator that a call using this `FnAbi` uses to create a call + /// bundle. + /// When type discrimination is on, contains per type discriminator otherwise a schema defined + /// constant discriminator. None, if this ABI doesn't participate in pointer authentication. + pub ptrauth_discriminator: Option, } // Needs to be a custom impl because of the bounds on the `TyAndLayout` debug impl. impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let FnAbi { args, ret, c_variadic, fixed_count, conv, can_unwind } = self; + let FnAbi { args, ret, c_variadic, fixed_count, conv, can_unwind, ptrauth_discriminator } = + self; f.debug_struct("FnAbi") .field("args", args) .field("ret", ret) @@ -677,6 +683,7 @@ impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> { .field("fixed_count", fixed_count) .field("conv", conv) .field("can_unwind", can_unwind) + .field("ptrauth_discriminator", ptrauth_discriminator) .finish() } } @@ -1007,6 +1014,6 @@ mod size_asserts { use super::*; // tidy-alphabetical-start static_assert_size!(ArgAbi<'_, usize>, 56); - static_assert_size!(FnAbi<'_, usize>, 80); + static_assert_size!(FnAbi<'_, usize>, 96); // tidy-alphabetical-end } diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 5c72f6cba3989..04f33051e7902 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -6,6 +6,7 @@ use rustc_attr_ir::find_attr; use rustc_attr_ir::lang_items::LangItem; use rustc_hir as hir; use rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs; +use rustc_middle::ptrauth::ptrauth_signing_discriminator_for; use rustc_middle::query::Providers; use rustc_middle::ty::layout::{ FnAbiError, HasTyCtxt, HasTypingEnv, LayoutCx, LayoutOf, TyAndLayout, fn_can_unwind, @@ -613,6 +614,10 @@ fn fn_abi_new_uncached<'tcx>( }), sig.abi(), ), + ptrauth_discriminator: tcx + .sess + .pointer_authentication_functions() + .and_then(|schema| ptrauth_signing_discriminator_for(tcx, schema, sig).map(Into::into)), }; fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi()); debug!("fn_abi_new_uncached = {:?}", fn_abi); diff --git a/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md b/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md index 1118145a2097c..a7b36bf9a15f7 100644 --- a/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md +++ b/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md @@ -462,6 +462,7 @@ The following categories are supported (all present in tree): * pauth-extern-c.rs * pauth-extern-c-direct-indirect-call.rs * pauth-extern-weak-global.rs + * pauth-signed-abi.rs * pauth-init-fini.rs * pauth-attr-special-funcs.rs * End-to-end execution tests @@ -494,6 +495,7 @@ x.py test --target aarch64-unknown-linux-pauthtest --force-rerun assembly-llvm \ tests/codegen-llvm/pauth/pauth-extern-c.rs \ tests/codegen-llvm/pauth/pauth-extern-c-direct-indirect-call.rs \ tests/codegen-llvm/pauth/pauth-extern-weak-global.rs \ + tests/codegen-llvm/pauth/pauth-signed-abi.rs \ tests/codegen-llvm/pauth/pauth-init-fini.rs \ tests/run-make/pauth-quicksort-rust-driver \ tests/run-make/pauth-quicksort-c-driver \ diff --git a/tests/codegen-llvm/pauth/pauth-signed-abi.rs b/tests/codegen-llvm/pauth/pauth-signed-abi.rs new file mode 100644 index 0000000000000..eafe7ee57acff --- /dev/null +++ b/tests/codegen-llvm/pauth/pauth-signed-abi.rs @@ -0,0 +1,55 @@ +// ignore-tidy-file-linelength +//@ add-minicore +//@ needs-llvm-components: aarch64 +// Run it at O0, so that the compiler doesn't optimise the calls away. +//@ compile-flags: --target=aarch64-unknown-linux-pauthtest --crate-type=lib -C opt-level=0 + +// Function pointers are signed, and calls through them authenticated, for the same set of ABIs: +// `extern "C"` and `extern "system"` (see `is_ptrauth_signed_abi`). +// +// Discriminators: `extern "C" fn(i32)` = 2712. + +// FIXME: jchlanda - decide if `efiapi` should also participate in pointer authentication. + +#![feature(no_core, lang_items)] +#![no_std] +#![no_core] + +extern crate minicore; +use minicore::*; + +extern "C" fn c_fn(_: i32) {} + +extern "efiapi" fn efi_fn(_: i32) {} + +// CHECK-LABEL: @reify_c( +#[no_mangle] +pub fn reify_c() -> extern "C" fn(i32) { + // CHECK: ret ptr ptrauth (ptr @{{.*}}c_fn{{.*}}, i32 0) + c_fn +} + +// CHECK-LABEL: @reify_efiapi( +#[no_mangle] +pub fn reify_efiapi() -> extern "efiapi" fn(i32) { + // CHECK-NOT: ptrauth + // CHECK: ret ptr @{{.*}}efi_fn + efi_fn +} + +// CHECK-LABEL: @call_c( +#[no_mangle] +pub fn call_c(f: extern "C" fn(i32)) { + // CHECK: call void %{{.*}}(i32 1) {{.*}}[ "ptrauth"(i32 0, i64 0) ] + f(1) +} + +// CHECK-LABEL: @call_efiapi( +#[no_mangle] +pub fn call_efiapi(f: extern "efiapi" fn(i32)) { + // CHECK-NOT: "ptrauth" + // CHECK: call void %{{.*}}(i32 1) + // CHECK-NOT: "ptrauth" + // CHECK: ret void + f(1) +} diff --git a/tests/ui/abi/c-zst.aarch64-darwin.stderr b/tests/ui/abi/c-zst.aarch64-darwin.stderr index ea764cb2cc71e..c7fb8ef24ec49 100644 --- a/tests/ui/abi/c-zst.aarch64-darwin.stderr +++ b/tests/ui/abi/c-zst.aarch64-darwin.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.powerpc-linux.stderr b/tests/ui/abi/c-zst.powerpc-linux.stderr index 8598792e93815..48e20c478edfa 100644 --- a/tests/ui/abi/c-zst.powerpc-linux.stderr +++ b/tests/ui/abi/c-zst.powerpc-linux.stderr @@ -68,6 +68,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.s390x-linux.stderr b/tests/ui/abi/c-zst.s390x-linux.stderr index 8598792e93815..48e20c478edfa 100644 --- a/tests/ui/abi/c-zst.s390x-linux.stderr +++ b/tests/ui/abi/c-zst.s390x-linux.stderr @@ -68,6 +68,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.sparc-linux.stderr b/tests/ui/abi/c-zst.sparc-linux.stderr index 8598792e93815..48e20c478edfa 100644 --- a/tests/ui/abi/c-zst.sparc-linux.stderr +++ b/tests/ui/abi/c-zst.sparc-linux.stderr @@ -68,6 +68,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.sparc-none.stderr b/tests/ui/abi/c-zst.sparc-none.stderr index 8598792e93815..48e20c478edfa 100644 --- a/tests/ui/abi/c-zst.sparc-none.stderr +++ b/tests/ui/abi/c-zst.sparc-none.stderr @@ -68,6 +68,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.sparc64-linux.stderr b/tests/ui/abi/c-zst.sparc64-linux.stderr index 8598792e93815..48e20c478edfa 100644 --- a/tests/ui/abi/c-zst.sparc64-linux.stderr +++ b/tests/ui/abi/c-zst.sparc64-linux.stderr @@ -68,6 +68,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.x86_64-linux.stderr b/tests/ui/abi/c-zst.x86_64-linux.stderr index ea764cb2cc71e..c7fb8ef24ec49 100644 --- a/tests/ui/abi/c-zst.x86_64-linux.stderr +++ b/tests/ui/abi/c-zst.x86_64-linux.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr b/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr index efc74aab224a9..9149bd40f89da 100644 --- a/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr +++ b/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr @@ -79,6 +79,7 @@ error: fn_abi_of(pass_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/c-zst.rs:74:1 | diff --git a/tests/ui/abi/debug.generic.stderr b/tests/ui/abi/debug.generic.stderr index f973e774cdc18..d3087b2ec4af9 100644 --- a/tests/ui/abi/debug.generic.stderr +++ b/tests/ui/abi/debug.generic.stderr @@ -106,6 +106,7 @@ error: fn_abi_of(test) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:31:1 | @@ -196,6 +197,7 @@ error: fn_abi_of(test_unsized) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:37:1 | @@ -275,6 +277,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:43:1 | @@ -344,6 +347,7 @@ error: fn_abi_of(test_generic) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:46:1 | @@ -420,6 +424,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -484,6 +489,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:65:1 | @@ -561,6 +567,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -632,6 +639,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:68:1 | @@ -702,6 +710,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -766,6 +775,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:71:1 | @@ -836,6 +846,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -900,6 +911,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:75:1 | @@ -992,6 +1004,7 @@ error: fn_abi_of(assoc_test) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:58:5 | diff --git a/tests/ui/abi/debug.loongarch64.stderr b/tests/ui/abi/debug.loongarch64.stderr index 65425ab57e171..43498c3b852d4 100644 --- a/tests/ui/abi/debug.loongarch64.stderr +++ b/tests/ui/abi/debug.loongarch64.stderr @@ -106,6 +106,7 @@ error: fn_abi_of(test) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:31:1 | @@ -196,6 +197,7 @@ error: fn_abi_of(test_unsized) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:37:1 | @@ -275,6 +277,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:43:1 | @@ -344,6 +347,7 @@ error: fn_abi_of(test_generic) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:46:1 | @@ -420,6 +424,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -484,6 +489,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:65:1 | @@ -561,6 +567,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -632,6 +639,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:68:1 | @@ -702,6 +710,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -766,6 +775,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:71:1 | @@ -836,6 +846,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -900,6 +911,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:75:1 | @@ -992,6 +1004,7 @@ error: fn_abi_of(assoc_test) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:58:5 | diff --git a/tests/ui/abi/debug.riscv64.stderr b/tests/ui/abi/debug.riscv64.stderr index 65425ab57e171..43498c3b852d4 100644 --- a/tests/ui/abi/debug.riscv64.stderr +++ b/tests/ui/abi/debug.riscv64.stderr @@ -106,6 +106,7 @@ error: fn_abi_of(test) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:31:1 | @@ -196,6 +197,7 @@ error: fn_abi_of(test_unsized) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:37:1 | @@ -275,6 +277,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:43:1 | @@ -344,6 +347,7 @@ error: fn_abi_of(test_generic) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:46:1 | @@ -420,6 +424,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -484,6 +489,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:65:1 | @@ -561,6 +567,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -632,6 +639,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:68:1 | @@ -702,6 +710,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -766,6 +775,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:71:1 | @@ -836,6 +846,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } right ABI = FnAbi { args: [ @@ -900,6 +911,7 @@ error: ABIs are not compatible fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:75:1 | @@ -992,6 +1004,7 @@ error: fn_abi_of(assoc_test) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: $SOME_BOOL, + ptrauth_discriminator: None, } --> $DIR/debug.rs:58:5 | diff --git a/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.apple.stderr b/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.apple.stderr index 683428514e4db..e92b519bfb395 100644 --- a/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.apple.stderr +++ b/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.apple.stderr @@ -67,6 +67,7 @@ error: fn_abi_of(i8) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:13:1 | @@ -142,6 +143,7 @@ error: fn_abi_of(u8) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:19:1 | @@ -217,6 +219,7 @@ error: fn_abi_of(i16) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:25:1 | @@ -292,6 +295,7 @@ error: fn_abi_of(u16) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:31:1 | @@ -367,6 +371,7 @@ error: fn_abi_of(i32) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:37:1 | @@ -442,6 +447,7 @@ error: fn_abi_of(u32) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:43:1 | diff --git a/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.other.stderr b/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.other.stderr index 2fc0528149667..58c9568514c18 100644 --- a/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.other.stderr +++ b/tests/ui/abi/numbers-arithmetic/x86-64-sysv64-arg-ext.other.stderr @@ -67,6 +67,7 @@ error: fn_abi_of(i8) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:13:1 | @@ -142,6 +143,7 @@ error: fn_abi_of(u8) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:19:1 | @@ -217,6 +219,7 @@ error: fn_abi_of(i16) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:25:1 | @@ -292,6 +295,7 @@ error: fn_abi_of(u16) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:31:1 | @@ -367,6 +371,7 @@ error: fn_abi_of(i32) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:37:1 | @@ -442,6 +447,7 @@ error: fn_abi_of(u32) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/x86-64-sysv64-arg-ext.rs:43:1 | diff --git a/tests/ui/abi/pass-indirectly-attr.rs b/tests/ui/abi/pass-indirectly-attr.rs index 72a5678b91753..bd6464087c2cd 100644 --- a/tests/ui/abi/pass-indirectly-attr.rs +++ b/tests/ui/abi/pass-indirectly-attr.rs @@ -1,6 +1,9 @@ //@ add-minicore //@ check-fail //@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED" +// The pointer authentication discriminator depends on the target's pointer authentication +// configuration, not on the calling convention. +//@ normalize-stderr: "ptrauth_discriminator: (None|Some\(\s+\d+,\s+\))" -> "ptrauth_discriminator: $$PTRAUTH_DISCRIMINATOR" #![feature(rustc_attrs)] #![crate_type = "lib"] diff --git a/tests/ui/abi/pass-indirectly-attr.stderr b/tests/ui/abi/pass-indirectly-attr.stderr index 25589665cf91d..aeedbbb77227b 100644 --- a/tests/ui/abi/pass-indirectly-attr.stderr +++ b/tests/ui/abi/pass-indirectly-attr.stderr @@ -1,5 +1,5 @@ error[E0692]: transparent struct cannot have other repr hints - --> $DIR/pass-indirectly-attr.rs:34:1 + --> $DIR/pass-indirectly-attr.rs:37:1 | LL | #[rustc_pass_indirectly_in_non_rustic_abis] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,8 +81,9 @@ error: fn_abi_of(extern_c) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-indirectly-attr.rs:19:1 + --> $DIR/pass-indirectly-attr.rs:22:1 | LL | pub extern "C" fn extern_c(_: Type) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -171,8 +172,9 @@ error: fn_abi_of(extern_rust) = FnAbi { fixed_count: 1, conv: Rust, can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-indirectly-attr.rs:26:1 + --> $DIR/pass-indirectly-attr.rs:29:1 | LL | pub extern "Rust" fn extern_rust(_: Type) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/abi/rust-zst.aarch64-darwin.stderr b/tests/ui/abi/rust-zst.aarch64-darwin.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.aarch64-darwin.stderr +++ b/tests/ui/abi/rust-zst.aarch64-darwin.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.powerpc-linux.stderr b/tests/ui/abi/rust-zst.powerpc-linux.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.powerpc-linux.stderr +++ b/tests/ui/abi/rust-zst.powerpc-linux.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.s390x-linux.stderr b/tests/ui/abi/rust-zst.s390x-linux.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.s390x-linux.stderr +++ b/tests/ui/abi/rust-zst.s390x-linux.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.sparc-linux.stderr b/tests/ui/abi/rust-zst.sparc-linux.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.sparc-linux.stderr +++ b/tests/ui/abi/rust-zst.sparc-linux.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.sparc-none.stderr b/tests/ui/abi/rust-zst.sparc-none.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.sparc-none.stderr +++ b/tests/ui/abi/rust-zst.sparc-none.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.sparc64-linux.stderr b/tests/ui/abi/rust-zst.sparc64-linux.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.sparc64-linux.stderr +++ b/tests/ui/abi/rust-zst.sparc64-linux.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.x86_64-linux.stderr b/tests/ui/abi/rust-zst.x86_64-linux.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.x86_64-linux.stderr +++ b/tests/ui/abi/rust-zst.x86_64-linux.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/rust-zst.x86_64-pc-windows-gnu.stderr b/tests/ui/abi/rust-zst.x86_64-pc-windows-gnu.stderr index f4a3338ca287d..7a5a68dc459d3 100644 --- a/tests/ui/abi/rust-zst.x86_64-pc-windows-gnu.stderr +++ b/tests/ui/abi/rust-zst.x86_64-pc-windows-gnu.stderr @@ -57,6 +57,7 @@ error: fn_abi_of(pass_rust_zst) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/rust-zst.rs:64:1 | diff --git a/tests/ui/abi/sysv64-zst.stderr b/tests/ui/abi/sysv64-zst.stderr index f644f32fe86f9..87feeec2c12d6 100644 --- a/tests/ui/abi/sysv64-zst.stderr +++ b/tests/ui/abi/sysv64-zst.stderr @@ -59,6 +59,7 @@ error: fn_abi_of(pass_zst) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: None, } --> $DIR/sysv64-zst.rs:8:1 | diff --git a/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr b/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr index 22d1739a78ab3..47fca33c6b1c4 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr +++ b/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr @@ -68,8 +68,9 @@ error: fn_abi_of(take_va_list) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-by-value-abi.rs:27:1 + --> $DIR/pass-by-value-abi.rs:30:1 | LL | pub extern "C" fn take_va_list(_: VaList<'_>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/c-variadic/pass-by-value-abi.rs b/tests/ui/c-variadic/pass-by-value-abi.rs index 317840601c050..90763b60d5672 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.rs +++ b/tests/ui/c-variadic/pass-by-value-abi.rs @@ -1,5 +1,8 @@ //@ check-fail //@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED" +// The pointer authentication discriminator depends on the target's pointer authentication +// configuration, not on the calling convention. +//@ normalize-stderr: "ptrauth_discriminator: (None|Some\(\s+\d+,\s+\))" -> "ptrauth_discriminator: $$PTRAUTH_DISCRIMINATOR" //@ normalize-stderr: "pointer is 0\.\.=\d+" -> "pointer is 0..=$$MAX" //@ normalize-stderr: "in_memory_order: \[[^\]]+\]" -> "in_memory_order: $$MEMORY_INDEX" //@ normalize-stderr: "offsets: \[[^\]]+\]" -> "offsets: $$OFFSETS" diff --git a/tests/ui/c-variadic/pass-by-value-abi.win.stderr b/tests/ui/c-variadic/pass-by-value-abi.win.stderr index ffbfa5f146eba..ef2326cf5043b 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.win.stderr +++ b/tests/ui/c-variadic/pass-by-value-abi.win.stderr @@ -64,8 +64,9 @@ error: fn_abi_of(take_va_list) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-by-value-abi.rs:27:1 + --> $DIR/pass-by-value-abi.rs:30:1 | LL | pub extern "C" fn take_va_list(_: VaList<'_>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr b/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr index e8b17cd9001e3..c302b6b9badcb 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr +++ b/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr @@ -68,8 +68,9 @@ error: fn_abi_of(take_va_list) = FnAbi { fixed_count: 1, conv: C, can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-by-value-abi.rs:27:1 + --> $DIR/pass-by-value-abi.rs:30:1 | LL | pub extern "C" fn take_va_list(_: VaList<'_>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -146,8 +147,9 @@ error: fn_abi_of(take_va_list_sysv64) = FnAbi { SysV64, ), can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-by-value-abi.rs:37:1 + --> $DIR/pass-by-value-abi.rs:40:1 | LL | pub extern "sysv64" fn take_va_list_sysv64(_: VaList<'_>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -224,8 +226,9 @@ error: fn_abi_of(take_va_list_win64) = FnAbi { Win64, ), can_unwind: false, + ptrauth_discriminator: $PTRAUTH_DISCRIMINATOR, } - --> $DIR/pass-by-value-abi.rs:44:1 + --> $DIR/pass-by-value-abi.rs:47:1 | LL | pub extern "win64" fn take_va_list_win64(_: VaList<'_>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From d3718437fdcab912d6278c8a175171b5ca022639 Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Wed, 4 Nov 2026 15:15:43 +0000 Subject: [PATCH 3/6] [PAC] Add `rustc_dump_ptrauth_discriminator` attribute And a test for it. `compute_fn_ptr_type_discriminator` was split into the encoding and the hash (both public) for the test use. --- compiler/rustc_attr_ir/src/attribute_docs.rs | 15 ++++++ compiler/rustc_attr_ir/src/data_structures.rs | 9 ++++ .../rustc_attr_ir/src/encode_cross_crate.rs | 2 + .../src/attributes/rustc_dump.rs | 54 ++++++++++++++++++- compiler/rustc_attr_parsing/src/context.rs | 1 + compiler/rustc_feature/src/builtin_attrs.rs | 1 + compiler/rustc_interface/src/passes.rs | 3 +- .../rustc_middle/src/ptrauth/discriminator.rs | 46 ++++++++++++---- compiler/rustc_passes/src/check_attr.rs | 1 + compiler/rustc_passes/src/lib.rs | 1 + compiler/rustc_passes/src/ptrauth_test.rs | 46 ++++++++++++++++ compiler/rustc_span/src/symbol.rs | 3 ++ .../rustc_dump_ptrauth_discriminator.rs | 7 +++ .../rustc_dump_ptrauth_discriminator.stderr | 14 +++++ 14 files changed, 192 insertions(+), 11 deletions(-) create mode 100644 compiler/rustc_passes/src/ptrauth_test.rs create mode 100644 tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.rs create mode 100644 tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.stderr diff --git a/compiler/rustc_attr_ir/src/attribute_docs.rs b/compiler/rustc_attr_ir/src/attribute_docs.rs index cb42c7a7bd742..5b1c1c9687d5d 100644 --- a/compiler/rustc_attr_ir/src/attribute_docs.rs +++ b/compiler/rustc_attr_ir/src/attribute_docs.rs @@ -167,6 +167,21 @@ const _: () = (); /// [`object_lifetime_default`]: ../rustc_middle/ty/struct.TyCtxt.html#method.object_lifetime_default const _: () = (); +#[cfg_attr(not(bootstrap), doc(attribute = "rustc_dump_ptrauth_discriminator"))] +/// Dumps the function pointer type discriminator of the annotated function. +/// +/// The discriminator is computed from an encoding of the function's signature (function type). The +/// `ptrauth_encoding` argument prints this encoding, while the `ptrauth_hash` argument prints the +/// resulting discriminator hash. +/// +/// See [`AttributeKind::RustcDumpPtrauthDiscriminator`] for the internal representation of this +/// attribute. +/// +/// # Example +/// +#[doc = include_example!("rustc_dump_ptrauth_discriminator")] +const _: () = (); + #[doc(attribute = "rustc_dump_symbol_name")] /// Dumps the symbol name of the annotated item, also demangling it if necessary. /// diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 26db9819bb7ca..f742a9f739438 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -626,6 +626,12 @@ pub enum RustcDumpLayoutKind { Size, } +#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)] +pub enum RustcDumpPtrauthDiscriminatorKind { + Encoding, + Hash, +} + #[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute, PartialEq, Eq)] pub enum RustcMirKind { PrettyLiveLocals, @@ -1329,6 +1335,9 @@ pub enum AttributeKind { /// Represents the [`rustc_dump_object_lifetime_defaults`](./attribute.rustc_dump_object_lifetime_defaults.html) attribute. RustcDumpObjectLifetimeDefaults, + /// Represents the [`rustc_dump_ptrauth_discriminator`](./attribute.rustc_dump_ptrauth_discriminator.html) attribute. + RustcDumpPtrauthDiscriminator(ThinVec), + /// Represents the [`rustc_dump_symbol_name`](./attribute.rustc_dump_symbol_name.html) attribute. RustcDumpSymbolName(Span), diff --git a/compiler/rustc_attr_ir/src/encode_cross_crate.rs b/compiler/rustc_attr_ir/src/encode_cross_crate.rs index ca9b79ccc8a51..031c6c183af3e 100644 --- a/compiler/rustc_attr_ir/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_ir/src/encode_cross_crate.rs @@ -144,6 +144,7 @@ impl AttributeKind { RustcDumpItemBounds => No, RustcDumpLayout(..) => No, RustcDumpObjectLifetimeDefaults => No, + RustcDumpPtrauthDiscriminator(..) => No, RustcDumpSymbolName(..) => Yes, RustcDumpUserArgs => No, RustcDumpVariances => No, @@ -363,6 +364,7 @@ impl AttributeKind { RustcDumpItemBounds => false, RustcDumpLayout(..) => false, RustcDumpObjectLifetimeDefaults => false, + RustcDumpPtrauthDiscriminator(..) => false, RustcDumpSymbolName(..) => false, RustcDumpUserArgs => false, RustcDumpVariances => false, diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs index 9a2a9681f78ea..729890e84cb47 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs @@ -1,5 +1,7 @@ use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; -use rustc_attr_ir::{AttributeKind, RustcDumpLayoutKind, RustcShowSpansKind}; +use rustc_attr_ir::{ + AttributeKind, RustcDumpLayoutKind, RustcDumpPtrauthDiscriminatorKind, RustcShowSpansKind, +}; use rustc_feature::AttributeStability; use rustc_span::{Span, Symbol, sym}; @@ -178,6 +180,56 @@ impl CombineAttributeParser for RustcDumpLayoutParser { } } +pub(crate) struct RustcDumpPtrauthDiscriminatorParser; + +impl CombineAttributeParser for RustcDumpPtrauthDiscriminatorParser { + const PATH: &[Symbol] = &[sym::rustc_dump_ptrauth_discriminator]; + + type Item = RustcDumpPtrauthDiscriminatorKind; + + const CONVERT: ConvertFn = + |items, _| AttributeKind::RustcDumpPtrauthDiscriminator(items); + + const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Fn)]); + + const TEMPLATE: AttributeTemplate = template!(List: &["encoding", "hash"]); + const STABILITY: AttributeStability = unstable!(rustc_attrs); + + fn extend( + cx: &mut AcceptContext<'_, '_>, + args: &ArgParser, + ) -> impl IntoIterator { + let Some(items) = cx.expect_list(args, cx.attr_span) else { + return vec![]; + }; + + let mut result = Vec::new(); + for item in items.mixed() { + let Some(arg) = item.meta_item_no_args() else { + cx.adcx().expected_not_literal(item.span()); + continue; + }; + let Some(ident) = arg.ident() else { + cx.adcx().expected_identifier(arg.span()); + return vec![]; + }; + let kind = match ident.name { + sym::ptrauth_encoding => RustcDumpPtrauthDiscriminatorKind::Encoding, + sym::ptrauth_hash => RustcDumpPtrauthDiscriminatorKind::Hash, + _ => { + cx.adcx().expected_specific_argument( + ident.span, + &[sym::ptrauth_encoding, sym::ptrauth_hash], + ); + continue; + } + }; + result.push(kind); + } + result + } +} + pub(crate) struct RustcDumpObjectLifetimeDefaultsParser; impl NoArgsAttributeParser for RustcDumpObjectLifetimeDefaultsParser { diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 59c583d4eb435..b8addb6d61d1d 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -197,6 +197,7 @@ attribute_parsers!( Combine, Combine, Combine, + Combine, Combine, Combine, Combine, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index c431e4aa2ba9b..1279dbdcfd3ec 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -203,6 +203,7 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ sym::rustc_dump_item_bounds, sym::rustc_dump_layout, sym::rustc_dump_object_lifetime_defaults, + sym::rustc_dump_ptrauth_discriminator, sym::rustc_dump_symbol_name, sym::rustc_dump_user_args, sym::rustc_dump_variances, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 7b881f99fb8d7..364aead2e5ba0 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -34,7 +34,7 @@ use rustc_middle::ty::{self, RegisteredTools, TyCtxt}; use rustc_middle::util::Providers; use rustc_parse::lexer::StripTokens; use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal}; -use rustc_passes::{abi_test, input_stats, layout_test}; +use rustc_passes::{abi_test, input_stats, layout_test, ptrauth_test}; use rustc_resolve::{Resolver, ResolverOutputs}; use rustc_session::config::{Input, Offload, OutFileName, OutputFilenames, OutputType}; use rustc_session::diagnostics::feature_err; @@ -1222,6 +1222,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { }); sess.time("layout_testing", || layout_test::test_layout(tcx)); + sess.time("ptrauth_testing", || ptrauth_test::test_ptrauth_discriminator(tcx)); sess.time("abi_testing", || abi_test::test_abi(tcx)); } diff --git a/compiler/rustc_middle/src/ptrauth/discriminator.rs b/compiler/rustc_middle/src/ptrauth/discriminator.rs index 4e10eeb224663..d0310d1e35e2a 100644 --- a/compiler/rustc_middle/src/ptrauth/discriminator.rs +++ b/compiler/rustc_middle/src/ptrauth/discriminator.rs @@ -31,12 +31,14 @@ //! encoding. //! //! ### 2. Type encoding +//! //! The lowered representation is serialized into a byte stream using rules //! intended to match Clang's implementation in: //! `encodeTypeForFunctionPointerAuth`. The resulting encoding describes the //! function signature in a target-independent form suitable for hashing. //! //! ### 3. Discriminator hashing +//! //! The encoded byte stream is hashed using LLVM's stable SipHash-2-4 based //! discriminator algorithm. The implementation here is a direct translation //! of LLVM/Clang's logic and must remain bit-for-bit compatible. See: @@ -208,7 +210,7 @@ impl<'tcx> FnPtrTypeDiscriminatorInput<'tcx> { self.abi } - fn from_sig(sig: ty::FnSig<'tcx>) -> Self { + pub fn from_sig(sig: ty::FnSig<'tcx>) -> Self { FnPtrTypeDiscriminatorInput { inputs: sig.inputs(), output: sig.output(), @@ -227,15 +229,13 @@ impl<'tcx> FnPtrTypeDiscriminatorInput<'tcx> { } } -/// Computes the Clang-compatible function pointer type discriminator. -/// -/// This is the low-level discriminator calculation function operating on -/// `FnPtrTypeDiscriminatorInput`. Returns `None` for unsupported ABIs (see -/// `is_ptrauth_signed_abi`). -fn compute_fn_ptr_type_discriminator<'tcx>( +/// Encodes the signature described by `input` the way Clang's +/// `encodeTypeForFunctionPointerAuth` does, as the input to the discriminator +/// hash. Returns `None` for unsupported ABIs (see `is_ptrauth_signed_abi`). +fn encode_fn_ptr_type_discriminator<'tcx>( tcx: TyCtxt<'tcx>, input: &FnPtrTypeDiscriminatorInput<'tcx>, -) -> Option { +) -> Option { if !is_ptrauth_signed_abi(input.abi) { return None; } @@ -255,7 +255,31 @@ fn compute_fn_ptr_type_discriminator<'tcx>( enc.push(b'E'); - Some(enc.finish()) + Some(enc) +} + +/// Computes the Clang-compatible function pointer type discriminator. +/// +/// This is the low-level discriminator calculation function operating on +/// `FnPtrTypeDiscriminatorInput`. Returns `None` for unsupported ABIs (see +/// `is_ptrauth_signed_abi`). +pub fn compute_fn_ptr_type_discriminator<'tcx>( + tcx: TyCtxt<'tcx>, + input: &FnPtrTypeDiscriminatorInput<'tcx>, +) -> Option { + encode_fn_ptr_type_discriminator(tcx, input).map(|enc| enc.finish()) +} + +/// Returns the raw Clang-compatible type encoding used as input to the +/// discriminator hash. +/// +/// This is primarily used for debugging and comparing Rust's encoding against +/// Clang's `encodeTypeForFunctionPointerAuth`. +pub fn debug_encode_fn_ptr_type<'tcx>( + tcx: TyCtxt<'tcx>, + input: &FnPtrTypeDiscriminatorInput<'tcx>, +) -> String { + encode_fn_ptr_type_discriminator(tcx, input).map(|enc| enc.debug_string()).unwrap_or_default() } // Clang disc type. @@ -411,6 +435,10 @@ impl PtrauthEncoder { fn finish(&self) -> u16 { llvm_pointer_auth_stable_siphash(&self.buf) } + + fn debug_string(&self) -> String { + String::from_utf8_lossy(&self.buf).into_owned() + } } /// Encodes a ClangDiscTy into the discriminator byte stream. diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 5dd1718d68d49..037dbc9eca194 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -333,6 +333,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcDumpItemBounds => (), AttributeKind::RustcDumpLayout(..) => (), AttributeKind::RustcDumpObjectLifetimeDefaults => (), + AttributeKind::RustcDumpPtrauthDiscriminator(..) => (), AttributeKind::RustcDumpSymbolName(..) => (), AttributeKind::RustcDumpUserArgs => (), AttributeKind::RustcDumpVariances => (), diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index d37d1bea932fe..25cba5ab47b1a 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -27,6 +27,7 @@ pub mod hir_id_validator; pub mod input_stats; pub mod layout_test; mod lib_features; +pub mod ptrauth_test; mod reachable; pub mod stability; mod upvars; diff --git a/compiler/rustc_passes/src/ptrauth_test.rs b/compiler/rustc_passes/src/ptrauth_test.rs new file mode 100644 index 0000000000000..d7328a72f4c45 --- /dev/null +++ b/compiler/rustc_passes/src/ptrauth_test.rs @@ -0,0 +1,46 @@ +use rustc_attr_ir::{RustcDumpPtrauthDiscriminatorKind, find_attr}; +use rustc_hir::def::DefKind; +use rustc_middle::ptrauth::FnPtrTypeDiscriminatorInput; +use rustc_middle::ptrauth::discriminator::{ + compute_fn_ptr_type_discriminator, debug_encode_fn_ptr_type, +}; +use rustc_middle::ty::TyCtxt; + +pub fn test_ptrauth_discriminator(tcx: TyCtxt<'_>) { + if !tcx.features().rustc_attrs() { + return; + } + for def_id in tcx.hir_crate_items(()).definitions() { + if tcx.def_kind(def_id) != DefKind::Fn { + continue; + } + let Some(kinds) = find_attr!(tcx, def_id, RustcDumpPtrauthDiscriminator(kinds) => kinds) + else { + continue; + }; + + let sig = tcx.fn_sig(def_id).instantiate_identity().skip_binder(); + let input = FnPtrTypeDiscriminatorInput::from_sig(sig); + let span = tcx.def_span(def_id); + + for kind in kinds { + let message = match kind { + RustcDumpPtrauthDiscriminatorKind::Encoding => { + format!( + "ptrauth discriminator encoding: \"{}\"", + debug_encode_fn_ptr_type(tcx, &input) + ) + } + RustcDumpPtrauthDiscriminatorKind::Hash => { + match compute_fn_ptr_type_discriminator(tcx, &input) { + Some(res) => { + format!("ptrauth discriminator hash: {} (0x{:x})", res, res) + } + None => "ptrauth discriminator hash: unavailable".to_string(), + } + } + }; + tcx.dcx().span_err(span, message); + } + } +} diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 70adbf6d7fee5..4c2333c6b6232 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1688,6 +1688,8 @@ symbols! { ptr_write_bytes, ptr_write_unaligned, ptr_write_volatile, + ptrauth_encoding, + ptrauth_hash, pub_macro_rules, pub_restricted, public, @@ -1840,6 +1842,7 @@ symbols! { rustc_dump_item_bounds, rustc_dump_layout, rustc_dump_object_lifetime_defaults, + rustc_dump_ptrauth_discriminator, rustc_dump_symbol_name, rustc_dump_user_args, rustc_dump_variances, diff --git a/tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.rs b/tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.rs new file mode 100644 index 0000000000000..48b0976d3e006 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.rs @@ -0,0 +1,7 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no + +#![feature(rustc_attrs)] + +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn foo(_: i32) {} diff --git a/tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.stderr b/tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.stderr new file mode 100644 index 0000000000000..1273d7b29e324 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dump_ptrauth_discriminator.stderr @@ -0,0 +1,14 @@ +error: ptrauth discriminator encoding: "FviE" + --> $DIR/rustc_dump_ptrauth_discriminator.rs:7:1 + | +7 | extern "C" fn foo(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/rustc_dump_ptrauth_discriminator.rs:7:1 + | +7 | extern "C" fn foo(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + From a46009b5a6e4d02c257cbf3bc00900b7be9a1c00 Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Wed, 4 Nov 2026 15:41:02 +0000 Subject: [PATCH 4/6] [PAC] Make the discriminator encoder follow Rust's ABI-compatibility rules Under type discrimination a fn pointer is signed with a discriminator of a pointee and authenticated with a discriminator of the function pointer that it is called through. In order to make a call through ABI-compatible function pointers work we must make sure that they produce the same discriminator. ABI-compatible types must generate the same discriminator. In order to do that this patch canonicalizes types by their ABI representation before encoding: * `repr(transparent)` wrappers as their non-1-ZST field; * two-variant niche enums (`Option<&T>`, `Option>`, `Option`) as the payload; * size-0, alignment-1 types as `()` (C's void); * `Box` as a pointer, and pattern types as their base type; * `!` as `()`. `discriminator-abi-compat.rs` checks three groups of signatures: * ABI-compatible types, must have the same discriminator (a failure is a soundness bug) * types that are not ABI-compatible but share the discriminator because Clang's encoding is coarser (a failure breaks C interoperability) * distinct types - distinct discriminators --- .../rustc_middle/src/ptrauth/discriminator.rs | 124 +- .../aarch64-unknown-linux-pauthtest.md | 2 + .../discriminator-abi-compat.rs | 506 ++++++++ .../discriminator-abi-compat.stderr | 1022 +++++++++++++++++ 4 files changed, 1614 insertions(+), 40 deletions(-) create mode 100644 tests/ui/pointer_authentication/discriminator-abi-compat.rs create mode 100644 tests/ui/pointer_authentication/discriminator-abi-compat.stderr diff --git a/compiler/rustc_middle/src/ptrauth/discriminator.rs b/compiler/rustc_middle/src/ptrauth/discriminator.rs index d0310d1e35e2a..3509c34bc66ae 100644 --- a/compiler/rustc_middle/src/ptrauth/discriminator.rs +++ b/compiler/rustc_middle/src/ptrauth/discriminator.rs @@ -18,11 +18,14 @@ //! The computation is structured into three conceptual stages: //! //! ### 1. Type normalization and lowering -//! Rust types are converted into a language-independent representation -//! (`ClangDiscTy`) that mirrors the type categories used by Clang when computing -//! function pointer discriminators. This includes canonicalization such as -//! treating all pointer-like types uniformly and mapping Rust constructs onto -//! their closest C equivalents. +//! +//! Rust types are first canonicalized according to ABI representation +//! (treating ABI-equivalent wrappers and niche representations as their +//! underlying representation, and treating pointer-like types uniformly), +//! then converted into a language-independent representation (`ClangDiscTy`) +//! that mirrors the type categories used by Clang when computing function +//! pointer discriminators. +//! //! One notable exception is C `_Complex`. Rust has no corresponding native type, //! so there is no canonical Rust representation to map onto Clang's `_Complex` //! type category. Rather than infer one (for example, by treating `(f32, f32)` @@ -61,7 +64,7 @@ //! //! - Clang-compatible type model //! - `ClangDiscTy` -//! - `canonicalize_c_type` +//! - `canonicalize_abi_compatible_type` //! - `to_clang_disc_ty` //! //! - Encoding @@ -78,12 +81,12 @@ //! `extern "C"` and `extern "system"` function types only. It does NOT attempt //! to model full Rust type system rules. -use rustc_abi::ExternAbi; +use rustc_abi::{ExternAbi, TagEncoding, Variants}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, Unnormalized}; use rustc_session::{PointerAuthDiscrimination, PointerAuthSchema}; -use rustc_span::sym; use crate::ptrauth::llvm_siphash::llvm_pointer_auth_stable_siphash; +use crate::ty::layout::LayoutCx; /// Types that can serve as a source for function pointer type discrimination. /// @@ -295,6 +298,9 @@ enum ClangDiscTy<'tcx> { // - raw pointers (`*const T`, `*mut T`) // - Rust references (`&T`, `&mut T`) // - function pointers + // - `Box` (canonicalized to a raw pointer) + // - `NonNull` (canonicalized through its transparent representation) + // - DST pointer-like types (`dyn Trait`, slices, `str`) // All collapse to a single Clang-compatible 'P' node. Pointer, @@ -312,35 +318,67 @@ enum ClangDiscTy<'tcx> { Void, } -// Canonicalize Option-wrapped pointer types used to model C nullable pointers. -// -// Rust and Clang should compute identical discriminators for equivalent C APIs. -// Clang does not distinguish nullable from non-nullable pointer types when -// computing function pointer authentication discriminators, so -// `Option` and `Option<*mut T>` are encoded identically to their -// underlying pointer types. -// -// Although `Option<*mut T>` is not considered FFI-safe by Rust and triggers the -// `improper_ctypes`/`improper_ctypes_definitions` lints, this is a warning -// rather than a hard error. Canonicalizing it here preserves Clang-compatible -// discriminator computation. -// -// Please see the following tests for sample use cases: -// pauth-fn-ptr-type-discrimination-option-callback.rs, -// pauth-fn-ptr-type-discrimination-option-return.rs and pauth-fn-ptr-type-discrimination-option.rs -fn canonicalize_c_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Adt(def, args) = ty.kind() - && tcx.is_diagnostic_item(sym::Option, def.did()) - { - let inner = args.type_at(0); - - match inner.kind() { - ty::FnPtr(..) | ty::RawPtr(..) => return inner, - _ => {} +/// Canonicalizes Rust types that have the same ABI representation as a simpler +/// C-compatible type for discriminator purposes. +/// +/// As a result ABI-compatible types get the same discriminator: +/// - a pattern type becomes its base type; +/// - `Box` becomes `*const T`; +/// - a size-0, alignment-1 type becomes `()`; +/// - a `repr(transparent)` wrapper becomes its non-1-ZST field; +/// - a two-variant enum with a niche becomes its payload. +/// +/// The work is done on layouts, so it also merges some types that Rust does not +/// guarantee to be ABI-compatible, for example: `Option` and `bool`. That +/// only makes discriminators coarser, while still correct. +/// +/// The steps repeat until nothing changes, as one can enable another: +/// `Option>` becomes `Box`, then `*const T`. +fn canonicalize_abi_compatible_type<'tcx>(tcx: TyCtxt<'tcx>, mut ty: Ty<'tcx>) -> Ty<'tcx> { + let typing_env = ty::TypingEnv::fully_monomorphized(); + + loop { + let before = ty; + + if let ty::Pat(base, _) = ty.kind() { + ty = *base; + } + + if ty.is_box_global(tcx) { + ty = Ty::new_imm_ptr( + tcx, + ty.boxed_ty().expect("is_box_global() returned true, so this must be a Box"), + ); } - } - ty + if let Ok(layout) = tcx.layout_of(typing_env.as_query_input(ty)) { + if layout.is_zst() && layout.align.bytes() == 1 { + ty = tcx.types.unit; + } else if matches!(ty.kind(), ty::Adt(..)) { + let cx = LayoutCx::new(tcx, typing_env); + ty = layout.peel_transparent_wrappers_from_non_1zst(&cx).ty; + } + } + + if let ty::Adt(def, args) = ty.kind() + && def.is_enum() + && def.variants().len() == 2 + && let Ok(layout) = tcx.layout_of(typing_env.as_query_input(ty)) + && let Variants::Multiple { + tag_encoding: TagEncoding::Niche { untagged_variant, .. }, + .. + } = layout.variants + { + let variant = def.variant(untagged_variant); + if let [field] = &variant.fields.raw[..] { + ty = tcx.normalize_erasing_regions(typing_env, field.ty(tcx, *args)); + } + } + + if ty == before { + return ty; + } + } } /// Lowers a Rust type into a Clang-compatible discriminator type. @@ -363,10 +401,10 @@ fn canonicalize_c_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { /// `_Complex` types. /// This must remain in sync with Clang's `encodeTypeForFunctionPointerAuth`. fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx> { - let ty = canonicalize_c_type(tcx, ty); + let ty = canonicalize_abi_compatible_type(tcx, ty); match ty.kind() { // C void / Rust () - _ if ty.is_unit() => ClangDiscTy::Void, + _ if ty.is_unit() || ty.is_never() => ClangDiscTy::Void, // scalars ty::Bool => ClangDiscTy::Bool, @@ -375,7 +413,8 @@ fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx> ty::Int(_) | ty::Uint(_) => ClangDiscTy::Int, ty::Float(f) => ClangDiscTy::Float(f), - // everything pointer-like collapses + // Pointer-like types form a discriminator boundary: the pointee type + // does not participate in the encoding. ty::RawPtr(..) | ty::Ref(..) | ty::FnPtr(..) | ty::Dynamic(..) | ty::Slice(_) | ty::Str => { ClangDiscTy::Pointer } @@ -383,8 +422,13 @@ fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx> // arrays ignore size ty::Array(elem, _) => ClangDiscTy::Array { elem: *elem }, - // enums to integer collapse - ty::Adt(def, _) if def.is_enum() => ClangDiscTy::EnumLikeInt, + // enums to integer collapse - mirrors Clang's Type::Enum handling, + // which recurses into the enum's underlying integer type. + // A non-niche, data-carrying enum (e.g. Option<*mut T>) is not an + // "enumerated type" in the C11 sense, such enums fall through to the + // general Adt(_) => AdtName(..) arm below instead. + ty::Adt(def, _) if def.is_enum() && def.is_payloadfree() => ClangDiscTy::EnumLikeInt, + // simd vectors ty::Adt(def, args) if def.repr().simd() => { // Clang encodes SIMD vectors by their total size diff --git a/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md b/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md index a7b36bf9a15f7..12be74b319584 100644 --- a/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md +++ b/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md @@ -474,6 +474,7 @@ The following categories are supported (all present in tree): * enable_pointer_authentication_validation.rs * invalid_target_pointer_authentication.rs * type_discrimination_not_supported_pointer_authentication.rs + * discriminator-abi-compat.rs * incompatible_pauth.rs * Unit tests for siphash function: * compiler/rustc_middle/src/ptrauth/llvm_siphash/tests.rs @@ -504,6 +505,7 @@ x.py test --target aarch64-unknown-linux-pauthtest --force-rerun assembly-llvm \ tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs \ tests/ui/pointer_authentication/invalid_target_pointer_authentication.rs \ tests/ui/pointer_authentication/type_discrimination_not_supported_pointer_authentication.rs \ + tests/ui/pointer_authentication/discriminator-abi-compat.rs \ tests/ui/target_modifiers/incompatible_pauth.rs ``` diff --git a/tests/ui/pointer_authentication/discriminator-abi-compat.rs b/tests/ui/pointer_authentication/discriminator-abi-compat.rs new file mode 100644 index 0000000000000..89a97d42aa00f --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-abi-compat.rs @@ -0,0 +1,506 @@ +// Test how function pointer type discriminator calculation interacts with function pointer ABI +// compatibility rules (https://doc.rust-lang.org/std/primitive.fn.html#abi-compatibility). +// +// Function pointers are signed with the discriminator of the function they point to, and a call +// authenticates with the discriminator of the type it is made through. +// +// The test is grouped into 3 sections, based on the type compatibility (marked by comments in +// code): +// +// 1. Types that are ABI-compatible , so the discriminators MUST match. A failure here is a +// soundness bug. +// 2. Not ABI-compatible types, but with equal discriminators, because the Clang encoding is coarser +// than Rust's rules, for example: every integer type encodes as `i`. These MUST match to match +// Clang. A failure here breaks interoperability with C. +// 3. Types that are not ABI-compatible, and distinct. Calls through these signatures are UB; +// distinct discriminators are what makes such a call trap. +// +// Each function's encoding and hash are checked by its annotations +// (#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)]). +// +// In sections 1 and 2, every function in a group has the same encoding; in section 3, each +// function differs from the group it resembles. +// +// On the rule that "any two fn (function pointer) types are ABI-compatible with each other": it is +// about function pointers passed as values, and is honoured, as every function pointer argument +// encodes as `P` (group 1.7). It does not make a call through a different signature valid: calling +// a `fn(i32)` through `fn()` is still UB, so the two signatures get distinct discriminators +// (group 3.1). + +#![crate_type = "lib"] +#![feature(rustc_attrs)] +#![feature(allocator_ext)] +#![allow(dead_code)] +#![allow(improper_ctypes_definitions)] + +use std::alloc::{AllocError, Allocator, Global, Layout}; +use std::marker::PhantomData; +use std::num::NonZero; +use std::ptr::NonNull; + +struct SomeStruct { + _x: i32, +} + +struct Unit; + +enum OneVariant { + A, +} + +#[repr(transparent)] +struct TrivialWrapper(()); + +#[repr(transparent)] +struct Wrapper(i32); + +#[repr(transparent)] +struct WrapperWithZst(i32, PhantomData); + +enum MyOption { + None, + Some(T), +} + +mod m1 { + pub struct S(pub i32); +} + +mod m2 { + pub struct S(pub u8); +} + +struct MyAlloc; + +unsafe impl Allocator for MyAlloc { + fn allocate(&self, layout: Layout) -> Result, AllocError> { + Global.allocate(layout) + } + unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { + unsafe { Global.deallocate(ptr, layout) } + } +} + +#[repr(align(4))] +struct AlignedMarker; + +struct NotTransparent(i32); + +enum WithExtraField { + A(NonZero, i32), + B, +} + +enum ThreeVariants { + A(bool), + B, + C, +} + +// 1. Types that are ABI-compatible , so the discriminators MUST match. A failure here is a +// soundness bug. + +// 1.1 "*const T, *mut T, &T, &mut T, Box (specifically, only Box), and NonNull +// are all ABI-compatible with each other for all T. They are also ABI-compatible with each other +// for different T if they have the same metadata type." Here thin pointers (metadata `()`). +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_a(_: *const i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_b(_: *mut i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_c(_: &i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_d(_: &mut i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_e(_: Box) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_f(_: NonNull) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p1_g(_: *const SomeStruct) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) + +// 1.2 The same, for pointers whose metadata is `usize` (slices and `str`). +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p2_a(_: *const [i32]) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p2_b(_: &[u8]) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p2_c(_: *const str) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn p2_d(_: Box<[u16]>) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) + +// 1.3 "usize is ABI-compatible with the uN integer type of the same size, and likewise isize is +// ABI-compatible with the iN integer type of the same size." and "char is ABI-compatible with +// u32." +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn i1_a(_: usize) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn i1_b(_: u64) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn i1_c(_: isize) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn i1_d(_: i64) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn i1_e(_: char) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn i1_f(_: u32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) + +// 1.4 "Any two types with size 0 and alignment 1 are ABI-compatible.", including tuples and +// arrays of them, `repr(transparent)` wrappers of them, and `!`. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_a(_: ()) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_b(_: Unit) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_c(_: PhantomData) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_d(_: [u8; 0]) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_e(_: OneVariant) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_f(_: ((), PhantomData)) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_g(_: [(); 3]) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_h(_: TrivialWrapper) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn z1_i(_: !) {} +//~^ ERROR encoding: "FvvE" +//~| ERROR hash: 61000 (0xee48) + +// 1.5 "A repr(transparent) type T is ABI-compatible with its unique non-trivial field", and +// "i32 is ABI-compatible with NonZero, and similar for all other integer types." +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn w1_a(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn w1_b(_: Wrapper) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn w1_c(_: WrapperWithZst) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn w1_d(_: NonZero) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) + +// 1.6 "If T is guaranteed to be subject to the null pointer optimization, and E is an enum +// satisfying the following requirements, then T and E are ABI-compatible." (option-like enums) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o1_a(_: Option<&i32>) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o1_b(_: Option>) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o1_c(_: MyOption>) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o1_d(_: Option>) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o1_e(_: Option) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) + +// 1.6 (continued) The same for an integer `T`. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o2_a(_: NonZero) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn o2_b(_: Option>) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) + +// 1.7 "Any two fn (function pointer) types are ABI-compatible with each other if they have the +// same ABI string or the ABI string only differs in a trailing -unwind, independent of the rest of +// their signature." This is about passing function pointers as values. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn f1_a(_: fn()) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn f1_b(_: fn(i32) -> i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn f1_c(_: extern "C" fn()) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn f1_d(_: extern "C-unwind" fn(i32)) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) + +// 1.8 Return position: trivial-ABI return types, including `!`, are ABI-compatible with `()`. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r1_a() {} +//~^ ERROR encoding: "FvE" +//~| ERROR hash: 18983 (0x4a27) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r1_b() -> () {} +//~^ ERROR encoding: "FvE" +//~| ERROR hash: 18983 (0x4a27) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r1_c() -> ! { loop {} } +//~^ ERROR encoding: "FvE" +//~| ERROR hash: 18983 (0x4a27) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r1_d() -> Unit { Unit } +//~^ ERROR encoding: "FvE" +//~| ERROR hash: 18983 (0x4a27) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r1_e() -> PhantomData { PhantomData } +//~^ ERROR encoding: "FvE" +//~| ERROR hash: 18983 (0x4a27) + +// 1.8 (continued) Pointer-like return types. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r2_a() -> *const i32 { std::ptr::null() } +//~^ ERROR encoding: "FPE" +//~| ERROR hash: 34128 (0x8550) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r2_b() -> Option<&'static i32> { None } +//~^ ERROR encoding: "FPE" +//~| ERROR hash: 34128 (0x8550) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r2_c() -> Option> { None } +//~^ ERROR encoding: "FPE" +//~| ERROR hash: 34128 (0x8550) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r2_d() -> Option> { None } +//~^ ERROR encoding: "FPE" +//~| ERROR hash: 34128 (0x8550) + +// 1.8 (continued) Integer-like return types. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r3_a() -> u32 { 0 } +//~^ ERROR encoding: "FiE" +//~| ERROR hash: 42271 (0xa51f) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r3_b() -> char { 'a' } +//~^ ERROR encoding: "FiE" +//~| ERROR hash: 42271 (0xa51f) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn r3_c() -> NonZero { NonZero::new(1).unwrap() } +//~^ ERROR encoding: "FiE" +//~| ERROR hash: 42271 (0xa51f) + +// 1.9 ABI strings: a trailing `-unwind` does not matter. `"system"` is `"C"` on this target. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn a1_a(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C-unwind" fn a1_b(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "system" fn a1_c(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "system-unwind" fn a1_d(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) + +// 1.10 `unsafe` is not part of the ABI. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn s1_a(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +unsafe extern "C" fn s1_b(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) + +// 2. Not ABI-compatible types, but with equal discriminators, because the Clang encoding is coarser +// than Rust's rules, for example: every integer type encodes as `i`. These MUST match to match +// Clang. A failure here breaks interoperability with C. + +// 2.1 Clang encodes every integer type, `bool` and `char` as `i`, whatever its size. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c1_a(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c1_b(_: bool) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c1_c(_: u8) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c1_d(_: i16) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c1_e(_: NonZero) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) + +// 2.2 Every pointer-like type encodes as `P`, whatever its metadata: C has no wide pointers. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c2_a(_: *const i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c2_b(_: *const [i32]) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) + +// 2.3 Arrays are encoded without their length. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c3_a(_: [i32; 4]) {} +//~^ ERROR encoding: "FvAiE" +//~| ERROR hash: 35183 (0x896f) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c3_b(_: [i32; 8]) {} +//~^ ERROR encoding: "FvAiE" +//~| ERROR hash: 35183 (0x896f) + +// 2.4 Structs are encoded by name only, so two different structs with the same name collide. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c4_a(_: m1::S) {} +//~^ ERROR encoding: "Fv1SE" +//~| ERROR hash: 61901 (0xf1cd) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn c4_b(_: m2::S) {} +//~^ ERROR encoding: "Fv1SE" +//~| ERROR hash: 61901 (0xf1cd) + +// 3. Types that are not ABI-compatible, and distinct. Calls through these signatures are UB; +// distinct discriminators are what makes such a call trap. + +// 3.1 Different signatures. In particular, a `fn(i32)` called through `fn()` traps. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn d1_a() {} +//~^ ERROR encoding: "FvE" +//~| ERROR hash: 18983 (0x4a27) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn d1_b(_: i32) {} +//~^ ERROR encoding: "FviE" +//~| ERROR hash: 2712 (0xa98) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn d1_c() -> i32 { 0 } +//~^ ERROR encoding: "FiE" +//~| ERROR hash: 42271 (0xa51f) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn d1_d(_: *const i32) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn d1_e(_: f32) {} +//~^ ERROR encoding: "FvfE" +//~| ERROR hash: 21613 (0x546d) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn d1_f(_: f64) {} +//~^ ERROR encoding: "FvdE" +//~| ERROR hash: 7718 (0x1e26) + +// 3.2 Near misses of the rules in section 1. Each is distinct from the group it resembles: +// * `Box` with an allocator other than `Global` (1.1); +// * a ZST with alignment 4 (1.4); +// * a non-transparent wrapper (1.5); +// * `Option`, which has no niche (1.6); +// * `Option<*mut T>`, as a raw pointer has no niche (1.6) +// * an enum whose niche variant has a second field (1.6); +// * an enum with more than two variants (1.6). +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_a(_: Box) {} +//~^ ERROR encoding: "Fv3BoxE" +//~| ERROR hash: 3916 (0xf4c) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_b(_: AlignedMarker) {} +//~^ ERROR encoding: "Fv13AlignedMarkerE" +//~| ERROR hash: 49590 (0xc1b6) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_c(_: NotTransparent) {} +//~^ ERROR encoding: "Fv14NotTransparentE" +//~| ERROR hash: 37756 (0x937c) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_d(_: Option) {} +//~^ ERROR encoding: "Fv6OptionE" +//~| ERROR hash: 20395 (0x4fab) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_e(_: Option<*mut i32>) {} +//~^ ERROR encoding: "Fv6OptionE" +//~| ERROR hash: 20395 (0x4fab) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_f(_: WithExtraField) {} +//~^ ERROR encoding: "Fv14WithExtraFieldE" +//~| ERROR hash: 34575 (0x870f) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn n1_g(_: ThreeVariants) {} +//~^ ERROR encoding: "Fv13ThreeVariantsE" +//~| ERROR hash: 9871 (0x268f) + +// 3.3 Only an `Option` with the layout of its payload is peeled. `Option` has the layout of +// `fn()` (group 1.6), but it uses up the niche of the function pointer, so `Option>` +// needs a tag. It is not ABI-compatible with `fn()`. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn q1_a(_: Option) {} +//~^ ERROR encoding: "FvPE" +//~| ERROR hash: 10942 (0x2abe) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding, ptrauth_hash)] +extern "C" fn q1_b(_: Option>) {} +//~^ ERROR encoding: "Fv6OptionE" +//~| ERROR hash: 20395 (0x4fab) diff --git a/tests/ui/pointer_authentication/discriminator-abi-compat.stderr b/tests/ui/pointer_authentication/discriminator-abi-compat.stderr new file mode 100644 index 0000000000000..c590bac62e4bd --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-abi-compat.stderr @@ -0,0 +1,1022 @@ +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:107:1 + | +LL | extern "C" fn p1_a(_: *const i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:107:1 + | +LL | extern "C" fn p1_a(_: *const i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:111:1 + | +LL | extern "C" fn p1_b(_: *mut i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:111:1 + | +LL | extern "C" fn p1_b(_: *mut i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:115:1 + | +LL | extern "C" fn p1_c(_: &i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:115:1 + | +LL | extern "C" fn p1_c(_: &i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:119:1 + | +LL | extern "C" fn p1_d(_: &mut i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:119:1 + | +LL | extern "C" fn p1_d(_: &mut i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:123:1 + | +LL | extern "C" fn p1_e(_: Box) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:123:1 + | +LL | extern "C" fn p1_e(_: Box) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:127:1 + | +LL | extern "C" fn p1_f(_: NonNull) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:127:1 + | +LL | extern "C" fn p1_f(_: NonNull) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:131:1 + | +LL | extern "C" fn p1_g(_: *const SomeStruct) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:131:1 + | +LL | extern "C" fn p1_g(_: *const SomeStruct) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:137:1 + | +LL | extern "C" fn p2_a(_: *const [i32]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:137:1 + | +LL | extern "C" fn p2_a(_: *const [i32]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:141:1 + | +LL | extern "C" fn p2_b(_: &[u8]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:141:1 + | +LL | extern "C" fn p2_b(_: &[u8]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:145:1 + | +LL | extern "C" fn p2_c(_: *const str) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:145:1 + | +LL | extern "C" fn p2_c(_: *const str) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:149:1 + | +LL | extern "C" fn p2_d(_: Box<[u16]>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:149:1 + | +LL | extern "C" fn p2_d(_: Box<[u16]>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:157:1 + | +LL | extern "C" fn i1_a(_: usize) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:157:1 + | +LL | extern "C" fn i1_a(_: usize) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:161:1 + | +LL | extern "C" fn i1_b(_: u64) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:161:1 + | +LL | extern "C" fn i1_b(_: u64) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:165:1 + | +LL | extern "C" fn i1_c(_: isize) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:165:1 + | +LL | extern "C" fn i1_c(_: isize) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:169:1 + | +LL | extern "C" fn i1_d(_: i64) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:169:1 + | +LL | extern "C" fn i1_d(_: i64) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:173:1 + | +LL | extern "C" fn i1_e(_: char) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:173:1 + | +LL | extern "C" fn i1_e(_: char) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:177:1 + | +LL | extern "C" fn i1_f(_: u32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:177:1 + | +LL | extern "C" fn i1_f(_: u32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:184:1 + | +LL | extern "C" fn z1_a(_: ()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:184:1 + | +LL | extern "C" fn z1_a(_: ()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:188:1 + | +LL | extern "C" fn z1_b(_: Unit) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:188:1 + | +LL | extern "C" fn z1_b(_: Unit) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:192:1 + | +LL | extern "C" fn z1_c(_: PhantomData) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:192:1 + | +LL | extern "C" fn z1_c(_: PhantomData) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:196:1 + | +LL | extern "C" fn z1_d(_: [u8; 0]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:196:1 + | +LL | extern "C" fn z1_d(_: [u8; 0]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:200:1 + | +LL | extern "C" fn z1_e(_: OneVariant) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:200:1 + | +LL | extern "C" fn z1_e(_: OneVariant) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:204:1 + | +LL | extern "C" fn z1_f(_: ((), PhantomData)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:204:1 + | +LL | extern "C" fn z1_f(_: ((), PhantomData)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:208:1 + | +LL | extern "C" fn z1_g(_: [(); 3]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:208:1 + | +LL | extern "C" fn z1_g(_: [(); 3]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:212:1 + | +LL | extern "C" fn z1_h(_: TrivialWrapper) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:212:1 + | +LL | extern "C" fn z1_h(_: TrivialWrapper) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvvE" + --> $DIR/discriminator-abi-compat.rs:216:1 + | +LL | extern "C" fn z1_i(_: !) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61000 (0xee48) + --> $DIR/discriminator-abi-compat.rs:216:1 + | +LL | extern "C" fn z1_i(_: !) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:223:1 + | +LL | extern "C" fn w1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:223:1 + | +LL | extern "C" fn w1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:227:1 + | +LL | extern "C" fn w1_b(_: Wrapper) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:227:1 + | +LL | extern "C" fn w1_b(_: Wrapper) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:231:1 + | +LL | extern "C" fn w1_c(_: WrapperWithZst) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:231:1 + | +LL | extern "C" fn w1_c(_: WrapperWithZst) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:235:1 + | +LL | extern "C" fn w1_d(_: NonZero) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:235:1 + | +LL | extern "C" fn w1_d(_: NonZero) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:242:1 + | +LL | extern "C" fn o1_a(_: Option<&i32>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:242:1 + | +LL | extern "C" fn o1_a(_: Option<&i32>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:246:1 + | +LL | extern "C" fn o1_b(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:246:1 + | +LL | extern "C" fn o1_b(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:250:1 + | +LL | extern "C" fn o1_c(_: MyOption>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:250:1 + | +LL | extern "C" fn o1_c(_: MyOption>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:254:1 + | +LL | extern "C" fn o1_d(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:254:1 + | +LL | extern "C" fn o1_d(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:258:1 + | +LL | extern "C" fn o1_e(_: Option) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:258:1 + | +LL | extern "C" fn o1_e(_: Option) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:264:1 + | +LL | extern "C" fn o2_a(_: NonZero) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:264:1 + | +LL | extern "C" fn o2_a(_: NonZero) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:268:1 + | +LL | extern "C" fn o2_b(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:268:1 + | +LL | extern "C" fn o2_b(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:276:1 + | +LL | extern "C" fn f1_a(_: fn()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:276:1 + | +LL | extern "C" fn f1_a(_: fn()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:280:1 + | +LL | extern "C" fn f1_b(_: fn(i32) -> i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:280:1 + | +LL | extern "C" fn f1_b(_: fn(i32) -> i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:284:1 + | +LL | extern "C" fn f1_c(_: extern "C" fn()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:284:1 + | +LL | extern "C" fn f1_c(_: extern "C" fn()) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:288:1 + | +LL | extern "C" fn f1_d(_: extern "C-unwind" fn(i32)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:288:1 + | +LL | extern "C" fn f1_d(_: extern "C-unwind" fn(i32)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvE" + --> $DIR/discriminator-abi-compat.rs:294:1 + | +LL | extern "C" fn r1_a() {} + | ^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 18983 (0x4a27) + --> $DIR/discriminator-abi-compat.rs:294:1 + | +LL | extern "C" fn r1_a() {} + | ^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvE" + --> $DIR/discriminator-abi-compat.rs:298:1 + | +LL | extern "C" fn r1_b() -> () {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 18983 (0x4a27) + --> $DIR/discriminator-abi-compat.rs:298:1 + | +LL | extern "C" fn r1_b() -> () {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvE" + --> $DIR/discriminator-abi-compat.rs:302:1 + | +LL | extern "C" fn r1_c() -> ! { loop {} } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 18983 (0x4a27) + --> $DIR/discriminator-abi-compat.rs:302:1 + | +LL | extern "C" fn r1_c() -> ! { loop {} } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvE" + --> $DIR/discriminator-abi-compat.rs:306:1 + | +LL | extern "C" fn r1_d() -> Unit { Unit } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 18983 (0x4a27) + --> $DIR/discriminator-abi-compat.rs:306:1 + | +LL | extern "C" fn r1_d() -> Unit { Unit } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvE" + --> $DIR/discriminator-abi-compat.rs:310:1 + | +LL | extern "C" fn r1_e() -> PhantomData { PhantomData } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 18983 (0x4a27) + --> $DIR/discriminator-abi-compat.rs:310:1 + | +LL | extern "C" fn r1_e() -> PhantomData { PhantomData } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FPE" + --> $DIR/discriminator-abi-compat.rs:316:1 + | +LL | extern "C" fn r2_a() -> *const i32 { std::ptr::null() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 34128 (0x8550) + --> $DIR/discriminator-abi-compat.rs:316:1 + | +LL | extern "C" fn r2_a() -> *const i32 { std::ptr::null() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FPE" + --> $DIR/discriminator-abi-compat.rs:320:1 + | +LL | extern "C" fn r2_b() -> Option<&'static i32> { None } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 34128 (0x8550) + --> $DIR/discriminator-abi-compat.rs:320:1 + | +LL | extern "C" fn r2_b() -> Option<&'static i32> { None } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FPE" + --> $DIR/discriminator-abi-compat.rs:324:1 + | +LL | extern "C" fn r2_c() -> Option> { None } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 34128 (0x8550) + --> $DIR/discriminator-abi-compat.rs:324:1 + | +LL | extern "C" fn r2_c() -> Option> { None } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FPE" + --> $DIR/discriminator-abi-compat.rs:328:1 + | +LL | extern "C" fn r2_d() -> Option> { None } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 34128 (0x8550) + --> $DIR/discriminator-abi-compat.rs:328:1 + | +LL | extern "C" fn r2_d() -> Option> { None } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FiE" + --> $DIR/discriminator-abi-compat.rs:334:1 + | +LL | extern "C" fn r3_a() -> u32 { 0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 42271 (0xa51f) + --> $DIR/discriminator-abi-compat.rs:334:1 + | +LL | extern "C" fn r3_a() -> u32 { 0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FiE" + --> $DIR/discriminator-abi-compat.rs:338:1 + | +LL | extern "C" fn r3_b() -> char { 'a' } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 42271 (0xa51f) + --> $DIR/discriminator-abi-compat.rs:338:1 + | +LL | extern "C" fn r3_b() -> char { 'a' } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FiE" + --> $DIR/discriminator-abi-compat.rs:342:1 + | +LL | extern "C" fn r3_c() -> NonZero { NonZero::new(1).unwrap() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 42271 (0xa51f) + --> $DIR/discriminator-abi-compat.rs:342:1 + | +LL | extern "C" fn r3_c() -> NonZero { NonZero::new(1).unwrap() } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:348:1 + | +LL | extern "C" fn a1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:348:1 + | +LL | extern "C" fn a1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:352:1 + | +LL | extern "C-unwind" fn a1_b(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:352:1 + | +LL | extern "C-unwind" fn a1_b(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:356:1 + | +LL | extern "system" fn a1_c(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:356:1 + | +LL | extern "system" fn a1_c(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:360:1 + | +LL | extern "system-unwind" fn a1_d(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:360:1 + | +LL | extern "system-unwind" fn a1_d(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:366:1 + | +LL | extern "C" fn s1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:366:1 + | +LL | extern "C" fn s1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:370:1 + | +LL | unsafe extern "C" fn s1_b(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:370:1 + | +LL | unsafe extern "C" fn s1_b(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:380:1 + | +LL | extern "C" fn c1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:380:1 + | +LL | extern "C" fn c1_a(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:384:1 + | +LL | extern "C" fn c1_b(_: bool) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:384:1 + | +LL | extern "C" fn c1_b(_: bool) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:388:1 + | +LL | extern "C" fn c1_c(_: u8) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:388:1 + | +LL | extern "C" fn c1_c(_: u8) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:392:1 + | +LL | extern "C" fn c1_d(_: i16) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:392:1 + | +LL | extern "C" fn c1_d(_: i16) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:396:1 + | +LL | extern "C" fn c1_e(_: NonZero) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:396:1 + | +LL | extern "C" fn c1_e(_: NonZero) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:402:1 + | +LL | extern "C" fn c2_a(_: *const i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:402:1 + | +LL | extern "C" fn c2_a(_: *const i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:406:1 + | +LL | extern "C" fn c2_b(_: *const [i32]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:406:1 + | +LL | extern "C" fn c2_b(_: *const [i32]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvAiE" + --> $DIR/discriminator-abi-compat.rs:412:1 + | +LL | extern "C" fn c3_a(_: [i32; 4]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 35183 (0x896f) + --> $DIR/discriminator-abi-compat.rs:412:1 + | +LL | extern "C" fn c3_a(_: [i32; 4]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvAiE" + --> $DIR/discriminator-abi-compat.rs:416:1 + | +LL | extern "C" fn c3_b(_: [i32; 8]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 35183 (0x896f) + --> $DIR/discriminator-abi-compat.rs:416:1 + | +LL | extern "C" fn c3_b(_: [i32; 8]) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv1SE" + --> $DIR/discriminator-abi-compat.rs:422:1 + | +LL | extern "C" fn c4_a(_: m1::S) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61901 (0xf1cd) + --> $DIR/discriminator-abi-compat.rs:422:1 + | +LL | extern "C" fn c4_a(_: m1::S) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv1SE" + --> $DIR/discriminator-abi-compat.rs:426:1 + | +LL | extern "C" fn c4_b(_: m2::S) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 61901 (0xf1cd) + --> $DIR/discriminator-abi-compat.rs:426:1 + | +LL | extern "C" fn c4_b(_: m2::S) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvE" + --> $DIR/discriminator-abi-compat.rs:435:1 + | +LL | extern "C" fn d1_a() {} + | ^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 18983 (0x4a27) + --> $DIR/discriminator-abi-compat.rs:435:1 + | +LL | extern "C" fn d1_a() {} + | ^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FviE" + --> $DIR/discriminator-abi-compat.rs:439:1 + | +LL | extern "C" fn d1_b(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 2712 (0xa98) + --> $DIR/discriminator-abi-compat.rs:439:1 + | +LL | extern "C" fn d1_b(_: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FiE" + --> $DIR/discriminator-abi-compat.rs:443:1 + | +LL | extern "C" fn d1_c() -> i32 { 0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 42271 (0xa51f) + --> $DIR/discriminator-abi-compat.rs:443:1 + | +LL | extern "C" fn d1_c() -> i32 { 0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:447:1 + | +LL | extern "C" fn d1_d(_: *const i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:447:1 + | +LL | extern "C" fn d1_d(_: *const i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvfE" + --> $DIR/discriminator-abi-compat.rs:451:1 + | +LL | extern "C" fn d1_e(_: f32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 21613 (0x546d) + --> $DIR/discriminator-abi-compat.rs:451:1 + | +LL | extern "C" fn d1_e(_: f32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvdE" + --> $DIR/discriminator-abi-compat.rs:455:1 + | +LL | extern "C" fn d1_f(_: f64) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 7718 (0x1e26) + --> $DIR/discriminator-abi-compat.rs:455:1 + | +LL | extern "C" fn d1_f(_: f64) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv3BoxE" + --> $DIR/discriminator-abi-compat.rs:468:1 + | +LL | extern "C" fn n1_a(_: Box) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 3916 (0xf4c) + --> $DIR/discriminator-abi-compat.rs:468:1 + | +LL | extern "C" fn n1_a(_: Box) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv13AlignedMarkerE" + --> $DIR/discriminator-abi-compat.rs:472:1 + | +LL | extern "C" fn n1_b(_: AlignedMarker) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 49590 (0xc1b6) + --> $DIR/discriminator-abi-compat.rs:472:1 + | +LL | extern "C" fn n1_b(_: AlignedMarker) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv14NotTransparentE" + --> $DIR/discriminator-abi-compat.rs:476:1 + | +LL | extern "C" fn n1_c(_: NotTransparent) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 37756 (0x937c) + --> $DIR/discriminator-abi-compat.rs:476:1 + | +LL | extern "C" fn n1_c(_: NotTransparent) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv6OptionE" + --> $DIR/discriminator-abi-compat.rs:480:1 + | +LL | extern "C" fn n1_d(_: Option) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 20395 (0x4fab) + --> $DIR/discriminator-abi-compat.rs:480:1 + | +LL | extern "C" fn n1_d(_: Option) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv6OptionE" + --> $DIR/discriminator-abi-compat.rs:484:1 + | +LL | extern "C" fn n1_e(_: Option<*mut i32>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 20395 (0x4fab) + --> $DIR/discriminator-abi-compat.rs:484:1 + | +LL | extern "C" fn n1_e(_: Option<*mut i32>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv14WithExtraFieldE" + --> $DIR/discriminator-abi-compat.rs:488:1 + | +LL | extern "C" fn n1_f(_: WithExtraField) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 34575 (0x870f) + --> $DIR/discriminator-abi-compat.rs:488:1 + | +LL | extern "C" fn n1_f(_: WithExtraField) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv13ThreeVariantsE" + --> $DIR/discriminator-abi-compat.rs:492:1 + | +LL | extern "C" fn n1_g(_: ThreeVariants) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 9871 (0x268f) + --> $DIR/discriminator-abi-compat.rs:492:1 + | +LL | extern "C" fn n1_g(_: ThreeVariants) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvPE" + --> $DIR/discriminator-abi-compat.rs:500:1 + | +LL | extern "C" fn q1_a(_: Option) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 10942 (0x2abe) + --> $DIR/discriminator-abi-compat.rs:500:1 + | +LL | extern "C" fn q1_a(_: Option) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv6OptionE" + --> $DIR/discriminator-abi-compat.rs:504:1 + | +LL | extern "C" fn q1_b(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator hash: 20395 (0x4fab) + --> $DIR/discriminator-abi-compat.rs:504:1 + | +LL | extern "C" fn q1_b(_: Option>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 170 previous errors + From e2264818d2233e5300d75ab9d84bcb23f0f70e44 Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Thu, 5 Nov 2026 09:00:56 +0000 Subject: [PATCH 5/6] [PAC] Encode `f16` and `f128` as Clang does Clang's `encodeTypeForFunctionPointerAuth` uses Itanium type codes: * `_Float16` is `DF16_` * `f128` is the C type with its representation: `long double` (`e`) on AArch64 Linux, where `long double` is IEEE quad precision, and `__float128` (`g`) elsewhere. --- .../rustc_middle/src/ptrauth/discriminator.rs | 12 +++++-- .../aarch64-unknown-linux-pauthtest.md | 2 ++ ...nator-float-encoding.aarch64_darwin.stderr | 14 ++++++++ ...inator-float-encoding.aarch64_linux.stderr | 14 ++++++++ .../discriminator-float-encoding.rs | 34 +++++++++++++++++++ ...minator-float-encoding.x86_64_linux.stderr | 14 ++++++++ 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_darwin.stderr create mode 100644 tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_linux.stderr create mode 100644 tests/ui/pointer_authentication/discriminator-float-encoding.rs create mode 100644 tests/ui/pointer_authentication/discriminator-float-encoding.x86_64_linux.stderr diff --git a/compiler/rustc_middle/src/ptrauth/discriminator.rs b/compiler/rustc_middle/src/ptrauth/discriminator.rs index 3509c34bc66ae..de1426a302f2e 100644 --- a/compiler/rustc_middle/src/ptrauth/discriminator.rs +++ b/compiler/rustc_middle/src/ptrauth/discriminator.rs @@ -84,6 +84,7 @@ use rustc_abi::{ExternAbi, TagEncoding, Variants}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, Unnormalized}; use rustc_session::{PointerAuthDiscrimination, PointerAuthSchema}; +use rustc_target::spec::Arch; use crate::ptrauth::llvm_siphash::llvm_pointer_auth_stable_siphash; use crate::ty::layout::LayoutCx; @@ -497,10 +498,17 @@ fn encode_ty<'tcx>(enc: &mut PtrauthEncoder, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) { ClangDiscTy::Bool | ClangDiscTy::Char | ClangDiscTy::Int => enc.push(b'i'), ClangDiscTy::Float(f) => match f.bit_width() { - 16 => enc.push_str("Dh"), + 16 => enc.push_str("DF16_"), 32 => enc.push(b'f'), 64 => enc.push(b'd'), - 128 => enc.push(b'g'), + 128 => match tcx.sess.target.arch { + Arch::AArch64 + if !tcx.sess.target.is_like_darwin && !tcx.sess.target.is_like_windows => + { + enc.push(b'e') + } + _ => enc.push(b'g'), + }, _ => enc.push(b'?'), }, diff --git a/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md b/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md index 12be74b319584..4743669cf4179 100644 --- a/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md +++ b/src/doc/rustc/src/platform-support/aarch64-unknown-linux-pauthtest.md @@ -475,6 +475,7 @@ The following categories are supported (all present in tree): * invalid_target_pointer_authentication.rs * type_discrimination_not_supported_pointer_authentication.rs * discriminator-abi-compat.rs + * discriminator-float-encoding.rs * incompatible_pauth.rs * Unit tests for siphash function: * compiler/rustc_middle/src/ptrauth/llvm_siphash/tests.rs @@ -506,6 +507,7 @@ x.py test --target aarch64-unknown-linux-pauthtest --force-rerun assembly-llvm \ tests/ui/pointer_authentication/invalid_target_pointer_authentication.rs \ tests/ui/pointer_authentication/type_discrimination_not_supported_pointer_authentication.rs \ tests/ui/pointer_authentication/discriminator-abi-compat.rs \ + tests/ui/pointer_authentication/discriminator-float-encoding.rs \ tests/ui/target_modifiers/incompatible_pauth.rs ``` diff --git a/tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_darwin.stderr b/tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_darwin.stderr new file mode 100644 index 0000000000000..3c64787d13875 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_darwin.stderr @@ -0,0 +1,14 @@ +error: ptrauth discriminator encoding: "FDF16_DF16_E" + --> $DIR/discriminator-float-encoding.rs:27:1 + | +LL | extern "C" fn half(x: f16) -> f16 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FggE" + --> $DIR/discriminator-float-encoding.rs:32:1 + | +LL | extern "C" fn quad(x: f128) -> f128 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_linux.stderr b/tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_linux.stderr new file mode 100644 index 0000000000000..ad6e8d7e8b383 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-float-encoding.aarch64_linux.stderr @@ -0,0 +1,14 @@ +error: ptrauth discriminator encoding: "FDF16_DF16_E" + --> $DIR/discriminator-float-encoding.rs:27:1 + | +LL | extern "C" fn half(x: f16) -> f16 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FeeE" + --> $DIR/discriminator-float-encoding.rs:32:1 + | +LL | extern "C" fn quad(x: f128) -> f128 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/pointer_authentication/discriminator-float-encoding.rs b/tests/ui/pointer_authentication/discriminator-float-encoding.rs new file mode 100644 index 0000000000000..390937d569b3a --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-float-encoding.rs @@ -0,0 +1,34 @@ +//@ add-minicore +//@ revisions: aarch64_linux aarch64_darwin x86_64_linux +//@ [aarch64_linux] compile-flags: --target aarch64-unknown-linux-pauthtest +//@ [aarch64_linux] needs-llvm-components: aarch64 +//@ [aarch64_darwin] compile-flags: --target aarch64-apple-darwin +//@ [aarch64_darwin] needs-llvm-components: aarch64 +//@ [x86_64_linux] compile-flags: --target x86_64-unknown-linux-gnu +//@ [x86_64_linux] needs-llvm-components: x86 +//@ dont-require-annotations: ERROR + +// Test for 16 and 128 bit wide floating-point types in the discriminator encoding. +// +// Clang's `encodeTypeForFunctionPointerAuth` uses Itanium type codes: +// * `_Float16` is `DF16_` +// * `f128` is the C type with its representation: `long double` (`e`) on +// AArch64 Linux, where `long double` is IEEE quad precision, and +// `__float128` (`g`) elsewhere. + +#![crate_type = "lib"] +#![feature(no_core, rustc_attrs, f16, f128)] +#![no_core] +#![allow(improper_ctypes_definitions)] + +extern crate minicore; + +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn half(x: f16) -> f16 { + x +} + +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn quad(x: f128) -> f128 { + x +} diff --git a/tests/ui/pointer_authentication/discriminator-float-encoding.x86_64_linux.stderr b/tests/ui/pointer_authentication/discriminator-float-encoding.x86_64_linux.stderr new file mode 100644 index 0000000000000..3c64787d13875 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-float-encoding.x86_64_linux.stderr @@ -0,0 +1,14 @@ +error: ptrauth discriminator encoding: "FDF16_DF16_E" + --> $DIR/discriminator-float-encoding.rs:27:1 + | +LL | extern "C" fn half(x: f16) -> f16 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FggE" + --> $DIR/discriminator-float-encoding.rs:32:1 + | +LL | extern "C" fn quad(x: f128) -> f128 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + From 1984151aeb6d229db5e8b782d9aa7a821838248e Mon Sep 17 00:00:00 2001 From: Jakub Chlanda Date: Mon, 23 Nov 2026 14:29:15 +0000 Subject: [PATCH 6/6] [PAC] Add support for C `_Complex` in the encoder Match `core::num::Complex` (the `complex` lang item) against C `_Complex T` for float and integer `T`. --- .../rustc_middle/src/ptrauth/discriminator.rs | 42 ++++++---- ...tor-complex-encoding.aarch64_darwin.stderr | 56 +++++++++++++ ...ator-complex-encoding.aarch64_linux.stderr | 56 +++++++++++++ .../discriminator-complex-encoding.rs | 78 +++++++++++++++++++ ...nator-complex-encoding.x86_64_linux.stderr | 56 +++++++++++++ 5 files changed, 272 insertions(+), 16 deletions(-) create mode 100644 tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_darwin.stderr create mode 100644 tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_linux.stderr create mode 100644 tests/ui/pointer_authentication/discriminator-complex-encoding.rs create mode 100644 tests/ui/pointer_authentication/discriminator-complex-encoding.x86_64_linux.stderr diff --git a/compiler/rustc_middle/src/ptrauth/discriminator.rs b/compiler/rustc_middle/src/ptrauth/discriminator.rs index de1426a302f2e..a278950d1df5d 100644 --- a/compiler/rustc_middle/src/ptrauth/discriminator.rs +++ b/compiler/rustc_middle/src/ptrauth/discriminator.rs @@ -26,12 +26,8 @@ //! that mirrors the type categories used by Clang when computing function //! pointer discriminators. //! -//! One notable exception is C `_Complex`. Rust has no corresponding native type, -//! so there is no canonical Rust representation to map onto Clang's `_Complex` -//! type category. Rather than infer one (for example, by treating `(f32, f32)` -//! or `(f64, f64)` as complex numbers), this implementation leaves such -//! representation choices to users and does not provide dedicated `_Complex` -//! encoding. +//! C `_Complex T` corresponds to `core::num::Complex` (the `complex` lang +//! item) for float and integer `T`s. //! //! ### 2. Type encoding //! @@ -307,10 +303,9 @@ enum ClangDiscTy<'tcx> { Array { elem: Ty<'tcx> }, - // FIXME(jchlands) Decide if to support Complex types in future. Clang has - // dedicated node for this `Type::Complex`, Rust does not. So we could match - // against a Tuple(FP_TYPE, FP_TYPE). - // Complex(Ty<'tcx>), + // C `_Complex T`: `core::num::Complex` (`#[repr(complex)]`). + Complex { elem: Ty<'tcx> }, + Vector { bytes: u64 }, EnumLikeInt, @@ -388,18 +383,14 @@ fn canonicalize_abi_compatible_type<'tcx>(tcx: TyCtxt<'tcx>, mut ty: Ty<'tcx>) - /// that intentionally matches Clang's function pointer authentication encoding /// rules where Rust has a direct language-level equivalent. /// -/// In particular C `_Complex`, without a canonical Rust equivalent, is not -/// recognized. This avoids introducing heuristics for user-defined -/// representations that may vary across codebases. -/// /// Important invariants: /// - All pointer-like types (Rust refs, raw pointers, fn pointers) collapse to /// `Pointer`. /// - Struct/union types are encoded using name only, not layout. /// - Enums are treated as integers. /// - SIMD types are encoded only by total byte size (no lane semantics). -/// - No attempt is made to recognize user-defined representations of C -/// `_Complex` types. +/// - Only `core::num::Complex` with the C `_Complex` ABI is encoded as +/// `_Complex`. /// This must remain in sync with Clang's `encodeTypeForFunctionPointerAuth`. fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx> { let ty = canonicalize_abi_compatible_type(tcx, ty); @@ -430,6 +421,9 @@ fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx> // general Adt(_) => AdtName(..) arm below instead. ty::Adt(def, _) if def.is_enum() && def.is_payloadfree() => ClangDiscTy::EnumLikeInt, + // C `_Complex T`, recurses into the element type. + ty::Adt(_, args) if is_c_complex(tcx, ty) => ClangDiscTy::Complex { elem: args.type_at(0) }, + // simd vectors ty::Adt(def, args) if def.repr().simd() => { // Clang encodes SIMD vectors by their total size @@ -459,6 +453,17 @@ fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx> } } +/// Returns true if `ty` is `core::num::Complex` with the ABI of C `_Complex +/// T`. +/// +/// Uses the same check as the calling convention code, so a type is encoded as +/// `_Complex` exactly when it is passed as one. +fn is_c_complex<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { + let typing_env = ty::TypingEnv::fully_monomorphized(); + let cx = LayoutCx::new(tcx, typing_env); + tcx.layout_of(typing_env.as_query_input(ty)).is_ok_and(|layout| layout.is_complex_number(&cx)) +} + // Encoder struct PtrauthEncoder { buf: Vec, @@ -512,6 +517,11 @@ fn encode_ty<'tcx>(enc: &mut PtrauthEncoder, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) { _ => enc.push(b'?'), }, + ClangDiscTy::Complex { elem } => { + enc.push(b'C'); + encode_ty(enc, tcx, elem); + } + ClangDiscTy::Void => enc.push(b'v'), // pointer boundary (NO RECURSION) diff --git a/tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_darwin.stderr b/tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_darwin.stderr new file mode 100644 index 0000000000000..7036457ec3390 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_darwin.stderr @@ -0,0 +1,56 @@ +error: ptrauth discriminator encoding: "FvCfE" + --> $DIR/discriminator-complex-encoding.rs:40:1 + | +LL | extern "C" fn cf(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCdE" + --> $DIR/discriminator-complex-encoding.rs:44:1 + | +LL | extern "C" fn cd(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCiE" + --> $DIR/discriminator-complex-encoding.rs:48:1 + | +LL | extern "C" fn ci(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCDF16_E" + --> $DIR/discriminator-complex-encoding.rs:52:1 + | +LL | extern "C" fn ret_ch() -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCgE" + --> $DIR/discriminator-complex-encoding.rs:58:1 + | +LL | extern "C" fn ret_cq() -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCdCfE" + --> $DIR/discriminator-complex-encoding.rs:64:1 + | +LL | extern "C" fn cf_to_cd(_: Complex) -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCfCiCdE" + --> $DIR/discriminator-complex-encoding.rs:70:1 + | +LL | extern "C" fn mixed(_: Complex, _: Complex, _: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCfE" + --> $DIR/discriminator-complex-encoding.rs:74:1 + | +LL | extern "C" fn wrap(_: Wrap) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv7ComplexE" + --> $DIR/discriminator-complex-encoding.rs:78:1 + | +LL | extern "C" fn user_complex(_: user::Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 9 previous errors + diff --git a/tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_linux.stderr b/tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_linux.stderr new file mode 100644 index 0000000000000..a3c7c782445e0 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-complex-encoding.aarch64_linux.stderr @@ -0,0 +1,56 @@ +error: ptrauth discriminator encoding: "FvCfE" + --> $DIR/discriminator-complex-encoding.rs:40:1 + | +LL | extern "C" fn cf(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCdE" + --> $DIR/discriminator-complex-encoding.rs:44:1 + | +LL | extern "C" fn cd(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCiE" + --> $DIR/discriminator-complex-encoding.rs:48:1 + | +LL | extern "C" fn ci(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCDF16_E" + --> $DIR/discriminator-complex-encoding.rs:52:1 + | +LL | extern "C" fn ret_ch() -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCeE" + --> $DIR/discriminator-complex-encoding.rs:58:1 + | +LL | extern "C" fn ret_cq() -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCdCfE" + --> $DIR/discriminator-complex-encoding.rs:64:1 + | +LL | extern "C" fn cf_to_cd(_: Complex) -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCfCiCdE" + --> $DIR/discriminator-complex-encoding.rs:70:1 + | +LL | extern "C" fn mixed(_: Complex, _: Complex, _: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCfE" + --> $DIR/discriminator-complex-encoding.rs:74:1 + | +LL | extern "C" fn wrap(_: Wrap) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv7ComplexE" + --> $DIR/discriminator-complex-encoding.rs:78:1 + | +LL | extern "C" fn user_complex(_: user::Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 9 previous errors + diff --git a/tests/ui/pointer_authentication/discriminator-complex-encoding.rs b/tests/ui/pointer_authentication/discriminator-complex-encoding.rs new file mode 100644 index 0000000000000..bdfc3853551c3 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-complex-encoding.rs @@ -0,0 +1,78 @@ +//@ add-minicore +//@ revisions: aarch64_linux aarch64_darwin x86_64_linux +//@ [aarch64_linux] compile-flags: --target aarch64-unknown-linux-pauthtest +//@ [aarch64_linux] needs-llvm-components: aarch64 +//@ [aarch64_darwin] compile-flags: --target aarch64-apple-darwin +//@ [aarch64_darwin] needs-llvm-components: aarch64 +//@ [x86_64_linux] compile-flags: --target x86_64-unknown-linux-gnu +//@ [x86_64_linux] needs-llvm-components: x86 +//@ dont-require-annotations: ERROR + +// Test for `core::num::Complex` in the discriminator encoding. +// +// Clang's `encodeTypeForFunctionPointerAuth` encodes C `_Complex T` as `C` followed by the encoding +// of `T`. `Complex` follows the rule from `discriminator-float-encoding.rs`: `Ce` on AArch64 +// Linux, `Cg` elsewhere. + +#![crate_type = "lib"] +#![feature(no_core, rustc_attrs, f16, f128)] +#![no_core] +#![allow(improper_ctypes_definitions)] + +extern crate minicore; +use minicore::num::Complex; + +// A `repr(transparent)` wrapper encodes as its field. +#[repr(transparent)] +pub struct Wrap(Complex); + +// An ordinary `repr(C)` struct that happens to be named `Complex`: not `_Complex`. +pub mod user { + #[repr(C)] + pub struct Complex { + pub re: f32, + pub im: f32, + } +} + +// C: void (*)(float _Complex) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn cf(_: Complex) {} + +// C: void (*)(double _Complex) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn cd(_: Complex) {} + +// C: void (*)(int _Complex) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn ci(_: Complex) {} + +// C: _Float16 _Complex (*)(void) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn ret_ch() -> Complex { + loop {} +} + +// C: long double _Complex (*)(void) on AArch64 Linux, __float128 _Complex (*)(void) elsewhere +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn ret_cq() -> Complex { + loop {} +} + +// C: double _Complex (*)(float _Complex) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn cf_to_cd(_: Complex) -> Complex { + loop {} +} + +// C: void (*)(float _Complex, int _Complex, double _Complex) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn mixed(_: Complex, _: Complex, _: Complex) {} + +// Same as `cf`. +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn wrap(_: Wrap) {} + +// C: struct Complex { float re, im; }; void (*)(struct Complex) +#[rustc_dump_ptrauth_discriminator(ptrauth_encoding)] +extern "C" fn user_complex(_: user::Complex) {} diff --git a/tests/ui/pointer_authentication/discriminator-complex-encoding.x86_64_linux.stderr b/tests/ui/pointer_authentication/discriminator-complex-encoding.x86_64_linux.stderr new file mode 100644 index 0000000000000..7036457ec3390 --- /dev/null +++ b/tests/ui/pointer_authentication/discriminator-complex-encoding.x86_64_linux.stderr @@ -0,0 +1,56 @@ +error: ptrauth discriminator encoding: "FvCfE" + --> $DIR/discriminator-complex-encoding.rs:40:1 + | +LL | extern "C" fn cf(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCdE" + --> $DIR/discriminator-complex-encoding.rs:44:1 + | +LL | extern "C" fn cd(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCiE" + --> $DIR/discriminator-complex-encoding.rs:48:1 + | +LL | extern "C" fn ci(_: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCDF16_E" + --> $DIR/discriminator-complex-encoding.rs:52:1 + | +LL | extern "C" fn ret_ch() -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCgE" + --> $DIR/discriminator-complex-encoding.rs:58:1 + | +LL | extern "C" fn ret_cq() -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FCdCfE" + --> $DIR/discriminator-complex-encoding.rs:64:1 + | +LL | extern "C" fn cf_to_cd(_: Complex) -> Complex { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCfCiCdE" + --> $DIR/discriminator-complex-encoding.rs:70:1 + | +LL | extern "C" fn mixed(_: Complex, _: Complex, _: Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "FvCfE" + --> $DIR/discriminator-complex-encoding.rs:74:1 + | +LL | extern "C" fn wrap(_: Wrap) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: ptrauth discriminator encoding: "Fv7ComplexE" + --> $DIR/discriminator-complex-encoding.rs:78:1 + | +LL | extern "C" fn user_complex(_: user::Complex) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 9 previous errors +