@@ -16,7 +16,7 @@ use rustc_middle::bug;
1616use rustc_middle:: mir:: interpret:: { GlobalAlloc , PointerArithmetic , Scalar } ;
1717use rustc_middle:: ty:: { Instance , TyCtxt } ;
1818use rustc_session:: cstore:: DllImport ;
19- use rustc_target :: spec :: LlvmAbi ;
19+ use rustc_session :: { PointerAuthAddressDiscriminator , PointerAuthSchema } ;
2020use tracing:: debug;
2121
2222use crate :: consts:: { IsInitOrFini , IsStatic , const_alloc_to_llvm} ;
@@ -26,27 +26,13 @@ use crate::llvm::{
2626 self , BasicBlock , ConstantInt , FALSE , TRUE , ToLlvmBool , Type , Value , const_ptr_auth,
2727} ;
2828
29- #[ inline]
30- pub ( crate ) fn pauth_fn_attrs ( ) -> & ' static [ & ' static str ] {
31- // FIXME(jchlanda) This is not an exhaustive list of all `ptrauth`-related attributes, but only
32- // those currently supported. The list is expected to grow as additional functionality is
33- // implemented, particularly for C++ interoperability.
34- & [
35- "aarch64-jump-table-hardening" ,
36- "ptrauth-indirect-gotos" ,
37- "ptrauth-calls" ,
38- "ptrauth-returns" ,
39- "ptrauth-auth-traps" ,
40- ]
41- }
42-
4329pub ( crate ) fn maybe_sign_fn_ptr < ' ll , ' tcx > (
4430 cx : & CodegenCx < ' ll , ' _ > ,
4531 instance : Instance < ' tcx > ,
4632 llfn : & ' ll llvm:: Value ,
47- pac : PacMetadata ,
33+ schema : & PointerAuthSchema ,
4834) -> & ' ll llvm:: Value {
49- if cx. sess ( ) . target . llvm_abiname != LlvmAbi :: Pauthtest {
35+ if cx. tcx . sess . pointer_authentication_functions ( ) . is_none ( ) {
5036 return llfn;
5137 }
5238
@@ -68,16 +54,16 @@ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>(
6854 return llfn;
6955 }
7056
71- let addr_diversity = match pac . addr_diversity {
72- AddressDiversity :: None => None ,
73- AddressDiversity :: Real => Some ( llfn ) ,
74- AddressDiversity :: Synthetic ( val) => {
57+ let addr_diversity = match schema . is_address_discriminated {
58+ PointerAuthAddressDiscriminator :: HardwareAddress ( true ) => Some ( llfn ) ,
59+ PointerAuthAddressDiscriminator :: HardwareAddress ( false ) => None ,
60+ PointerAuthAddressDiscriminator :: Synthetic ( val) => {
7561 let llval = cx. const_u64 ( val) ;
7662 let llty = cx. val_ty ( llfn) ;
7763 Some ( unsafe { llvm:: LLVMConstIntToPtr ( llval, llty) } )
7864 }
7965 } ;
80- const_ptr_auth ( llfn, pac . key , pac . disc , addr_diversity)
66+ const_ptr_auth ( llfn, schema . key as u32 , schema . constant_discriminator as u64 , addr_diversity)
8167}
8268
8369/*
@@ -331,7 +317,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
331317 cv : Scalar ,
332318 layout : abi:: Scalar ,
333319 llty : & ' ll Type ,
334- pac : Option < PacMetadata > ,
320+ schema : Option < & PointerAuthSchema > ,
335321 ) -> & ' ll Value {
336322 let bitsize = if layout. is_bool ( ) { 1 } else { layout. size ( self ) . bits ( ) } ;
337323 match cv {
@@ -387,7 +373,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
387373 value
388374 }
389375 }
390- GlobalAlloc :: Function { instance, .. } => self . get_fn_addr ( instance, pac ) ,
376+ GlobalAlloc :: Function { instance, .. } => self . get_fn_addr ( instance, schema ) ,
391377 GlobalAlloc :: VTable ( ty, dyn_ty) => {
392378 let alloc = self
393379 . tcx
0 commit comments