4
4
/// For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
5
5
/// see design document in the tracking issue #89653.
6
6
use bitflags:: bitflags;
7
- use rustc_middle:: ty:: { FnSig , Instance , Ty , TyCtxt } ;
7
+ use rustc_middle:: ty:: { Instance , List , Ty , TyCtxt } ;
8
8
use rustc_target:: abi:: call:: FnAbi ;
9
9
use std:: hash:: Hasher ;
10
10
use twox_hash:: XxHash64 ;
@@ -26,16 +26,11 @@ pub fn typeid_for_fnabi<'tcx>(
26
26
fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
27
27
options : TypeIdOptions ,
28
28
) -> String {
29
- typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options)
30
- }
31
-
32
- /// Returns a type metadata identifier for the specified FnSig.
33
- pub fn typeid_for_fnsig < ' tcx > (
34
- tcx : TyCtxt < ' tcx > ,
35
- fn_sig : & FnSig < ' tcx > ,
36
- options : TypeIdOptions ,
37
- ) -> String {
38
- typeid_itanium_cxx_abi:: typeid_for_fnsig ( tcx, fn_sig, options)
29
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
30
+ tcx,
31
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
32
+ options,
33
+ )
39
34
}
40
35
41
36
/// Returns a type metadata identifier for the specified Instance.
@@ -44,7 +39,16 @@ pub fn typeid_for_instance<'tcx>(
44
39
instance : & Instance < ' tcx > ,
45
40
options : TypeIdOptions ,
46
41
) -> String {
47
- typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options)
42
+ let fn_abi = tcx
43
+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
44
+ . unwrap_or_else ( |instance| {
45
+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
46
+ } ) ;
47
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
48
+ tcx,
49
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
50
+ options,
51
+ )
48
52
}
49
53
50
54
/// Returns a KCFI type metadata identifier for the specified FnAbi.
@@ -56,20 +60,14 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
56
60
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
57
61
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
58
62
let mut hash: XxHash64 = Default :: default ( ) ;
59
- hash. write ( typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options) . as_bytes ( ) ) ;
60
- hash. finish ( ) as u32
61
- }
62
-
63
- /// Returns a KCFI type metadata identifier for the specified FnSig.
64
- pub fn kcfi_typeid_for_fnsig < ' tcx > (
65
- tcx : TyCtxt < ' tcx > ,
66
- fn_sig : & FnSig < ' tcx > ,
67
- options : TypeIdOptions ,
68
- ) -> u32 {
69
- // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
70
- // xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
71
- let mut hash: XxHash64 = Default :: default ( ) ;
72
- hash. write ( typeid_itanium_cxx_abi:: typeid_for_fnsig ( tcx, fn_sig, options) . as_bytes ( ) ) ;
63
+ hash. write (
64
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
65
+ tcx,
66
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
67
+ options,
68
+ )
69
+ . as_bytes ( ) ,
70
+ ) ;
73
71
hash. finish ( ) as u32
74
72
}
75
73
@@ -79,9 +77,21 @@ pub fn kcfi_typeid_for_instance<'tcx>(
79
77
instance : & Instance < ' tcx > ,
80
78
options : TypeIdOptions ,
81
79
) -> u32 {
80
+ let fn_abi = tcx
81
+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
82
+ . unwrap_or_else ( |instance| {
83
+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
84
+ } ) ;
82
85
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
83
86
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
84
87
let mut hash: XxHash64 = Default :: default ( ) ;
85
- hash. write ( typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options) . as_bytes ( ) ) ;
88
+ hash. write (
89
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
90
+ tcx,
91
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
92
+ options,
93
+ )
94
+ . as_bytes ( ) ,
95
+ ) ;
86
96
hash. finish ( ) as u32
87
97
}
0 commit comments