1 // For more information about type metadata and type metadata identifiers for cross-language LLVM
2 // CFI support, see Type metadata in the design document in the tracking issue #89653.
4 use rustc_middle::ty::{FnSig, Ty, TyCtxt};
5 use rustc_target::abi::call::FnAbi;
7 use twox_hash::XxHash64;
9 mod typeid_itanium_cxx_abi;
10 use typeid_itanium_cxx_abi::TypeIdOptions;
12 /// Returns a type metadata identifier for the specified FnAbi.
13 pub fn typeid_for_fnabi<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> String {
14 typeid_itanium_cxx_abi::typeid_for_fnabi(tcx, fn_abi, TypeIdOptions::NO_OPTIONS)
17 /// Returns a type metadata identifier for the specified FnSig.
18 pub fn typeid_for_fnsig<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: &FnSig<'tcx>) -> String {
19 typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, TypeIdOptions::NO_OPTIONS)
22 /// Returns an LLVM KCFI type metadata identifier for the specified FnAbi.
23 pub fn kcfi_typeid_for_fnabi<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> u32 {
24 // An LLVM KCFI type metadata identifier is a 32-bit constant produced by taking the lower half
25 // of the xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
26 let mut hash: XxHash64 = Default::default();
28 typeid_itanium_cxx_abi::typeid_for_fnabi(tcx, fn_abi, TypeIdOptions::NO_OPTIONS).as_bytes(),
33 /// Returns an LLVM KCFI type metadata identifier for the specified FnSig.
34 pub fn kcfi_typeid_for_fnsig<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: &FnSig<'tcx>) -> u32 {
35 // An LLVM KCFI type metadata identifier is a 32-bit constant produced by taking the lower half
36 // of the xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
37 let mut hash: XxHash64 = Default::default();
39 typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, TypeIdOptions::NO_OPTIONS).as_bytes(),