]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_codegen_llvm/src/declare.rs
Add LLVM KCFI support to the Rust compiler
[rust.git] / compiler / rustc_codegen_llvm / src / declare.rs
index dc21a02cec44a144fef0c9704b3a16af5c1868d2..6a575095f7e45dbc5e05a7b86cebd7ce2851925e 100644 (file)
@@ -20,7 +20,7 @@
 use crate::value::Value;
 use rustc_codegen_ssa::traits::TypeMembershipMethods;
 use rustc_middle::ty::Ty;
-use rustc_symbol_mangling::typeid::typeid_for_fnabi;
+use rustc_symbol_mangling::typeid::{kcfi_typeid_for_fnabi, typeid_for_fnabi};
 use smallvec::SmallVec;
 
 /// Declare a function.
@@ -136,6 +136,11 @@ pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Val
             self.set_type_metadata(llfn, typeid);
         }
 
+        if self.tcx.sess.is_sanitizer_kcfi_enabled() {
+            let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi);
+            self.set_kcfi_type_metadata(llfn, kcfi_typeid);
+        }
+
         llfn
     }