@@ -11,6 +11,9 @@ use rustc_hir::attrs::AttributeKind;
1111use rustc_hir:: lang_items:: LangItem ;
1212use rustc_lint_defs:: builtin:: TAIL_CALL_TRACK_CALLER ;
1313use rustc_middle:: mir:: { self , AssertKind , InlineAsmMacro , SwitchTargets , UnwindTerminateReason } ;
14+ use rustc_middle:: ptrauth:: {
15+ build_fn_ptr_type_discriminator_input_from_instance, compute_fn_ptr_type_discriminator,
16+ } ;
1417use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf , ValidityRequirement } ;
1518use rustc_middle:: ty:: print:: { with_no_trimmed_paths, with_no_visible_paths} ;
1619use rustc_middle:: ty:: { self , Instance , Ty , TypeVisitableExt } ;
@@ -684,12 +687,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
684687 virtual_drop,
685688 )
686689 }
687- _ => (
688- false ,
689- bx. get_fn_addr ( drop_fn, bx. sess ( ) . pointer_authentication_functions ( ) ) ,
690- bx. fn_abi_of_instance ( drop_fn, ty:: List :: empty ( ) ) ,
691- drop_fn,
692- ) ,
690+ _ => {
691+ let mut schema = bx. sess ( ) . pointer_authentication_functions ( ) . clone ( ) ;
692+
693+ if let Some ( ref mut s) = schema
694+ && bx. sess ( ) . pointer_authentication_fn_ptr_type_discrimination ( )
695+ {
696+ let disc_input =
697+ build_fn_ptr_type_discriminator_input_from_instance ( bx. tcx ( ) , drop_fn) ;
698+ let disc = compute_fn_ptr_type_discriminator ( bx. tcx ( ) , & disc_input) as u16 ;
699+
700+ s. constant_discriminator = disc;
701+ }
702+ (
703+ false ,
704+ bx. get_fn_addr ( drop_fn, schema) ,
705+ bx. fn_abi_of_instance ( drop_fn, ty:: List :: empty ( ) ) ,
706+ drop_fn,
707+ )
708+ }
693709 } ;
694710
695711 // We generate a null check for the drop_fn. This saves a bunch of relocations being
@@ -1102,13 +1118,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11021118 )
11031119 . unwrap ( ) ;
11041120
1105- (
1106- None ,
1107- Some ( bx. get_fn_addr (
1121+ let mut schema = bx. sess ( ) . pointer_authentication_functions ( ) . clone ( ) ;
1122+
1123+ if let Some ( ref mut s) = schema
1124+ && bx. sess ( ) . pointer_authentication_fn_ptr_type_discrimination ( )
1125+ {
1126+ let disc_input = build_fn_ptr_type_discriminator_input_from_instance (
1127+ bx. tcx ( ) ,
11081128 instance,
1109- bx. sess ( ) . pointer_authentication_functions ( ) ,
1110- ) ) ,
1111- )
1129+ ) ;
1130+ let disc =
1131+ compute_fn_ptr_type_discriminator ( bx. tcx ( ) , & disc_input) as u16 ;
1132+
1133+ s. constant_discriminator = disc;
1134+ } ;
1135+
1136+ ( None , Some ( bx. get_fn_addr ( instance, schema) ) )
11121137 }
11131138 _ => ( Some ( instance) , None ) ,
11141139 }
@@ -1422,7 +1447,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14221447
14231448 let fn_ptr = match ( instance, llfn) {
14241449 ( Some ( instance) , None ) => {
1425- bx. get_fn_addr ( instance, bx. sess ( ) . pointer_authentication_functions ( ) )
1450+ let mut schema = bx. sess ( ) . pointer_authentication_functions ( ) . clone ( ) ;
1451+
1452+ if let Some ( ref mut s) = schema
1453+ && bx. sess ( ) . pointer_authentication_fn_ptr_type_discrimination ( )
1454+ {
1455+ let disc_input =
1456+ build_fn_ptr_type_discriminator_input_from_instance ( bx. tcx ( ) , instance) ;
1457+ let disc = compute_fn_ptr_type_discriminator ( bx. tcx ( ) , & disc_input) as u16 ;
1458+
1459+ s. constant_discriminator = disc;
1460+ }
1461+
1462+ bx. get_fn_addr ( instance, schema)
14261463 }
14271464 ( _, Some ( llfn) ) => llfn,
14281465 _ => span_bug ! ( fn_span, "no instance or llfn for call" ) ,
0 commit comments