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:: { 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 ;
@@ -27,7 +27,11 @@ pub fn typeid_for_fnabi<'tcx>(
27
27
fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
28
28
options : TypeIdOptions ,
29
29
) -> String {
30
- typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options)
30
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
31
+ tcx,
32
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
33
+ options,
34
+ )
31
35
}
32
36
33
37
/// Returns a type metadata identifier for the specified Instance.
@@ -36,7 +40,16 @@ pub fn typeid_for_instance<'tcx>(
36
40
instance : & Instance < ' tcx > ,
37
41
options : TypeIdOptions ,
38
42
) -> String {
39
- typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options)
43
+ let fn_abi = tcx
44
+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
45
+ . unwrap_or_else ( |instance| {
46
+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
47
+ } ) ;
48
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
49
+ tcx,
50
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
51
+ options,
52
+ )
40
53
}
41
54
42
55
/// Returns a KCFI type metadata identifier for the specified FnAbi.
@@ -48,7 +61,14 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
48
61
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
49
62
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
50
63
let mut hash: XxHash64 = Default :: default ( ) ;
51
- hash. write ( typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options) . as_bytes ( ) ) ;
64
+ hash. write (
65
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
66
+ tcx,
67
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
68
+ options,
69
+ )
70
+ . as_bytes ( ) ,
71
+ ) ;
52
72
hash. finish ( ) as u32
53
73
}
54
74
@@ -58,9 +78,21 @@ pub fn kcfi_typeid_for_instance<'tcx>(
58
78
instance : & Instance < ' tcx > ,
59
79
options : TypeIdOptions ,
60
80
) -> u32 {
81
+ let fn_abi = tcx
82
+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
83
+ . unwrap_or_else ( |instance| {
84
+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
85
+ } ) ;
61
86
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
62
87
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
63
88
let mut hash: XxHash64 = Default :: default ( ) ;
64
- hash. write ( typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options) . as_bytes ( ) ) ;
89
+ hash. write (
90
+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
91
+ tcx,
92
+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
93
+ options,
94
+ )
95
+ . as_bytes ( ) ,
96
+ ) ;
65
97
hash. finish ( ) as u32
66
98
}
0 commit comments