Add fine-grained LLVM CFI support to the Rust compiler
This commit improves the LLVM Control Flow Integrity (CFI) support in the Rust compiler by providing forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
This commit is contained in:
parent
5b8cf49c51
commit
5ad7a646a5
24 changed files with 1647 additions and 136 deletions
|
@ -626,32 +626,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn type_metadata(&mut self, function: &'ll Value, typeid: String) {
|
||||
let typeid_metadata = self.typeid_metadata(typeid);
|
||||
let v = [self.const_usize(0), typeid_metadata];
|
||||
unsafe {
|
||||
llvm::LLVMGlobalSetMetadata(
|
||||
function,
|
||||
llvm::MD_type as c_uint,
|
||||
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
|
||||
self.cx.llcx,
|
||||
v.as_ptr(),
|
||||
v.len() as c_uint,
|
||||
)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn typeid_metadata(&mut self, typeid: String) -> Self::Value {
|
||||
unsafe {
|
||||
llvm::LLVMMDStringInContext(
|
||||
self.cx.llcx,
|
||||
typeid.as_ptr() as *const c_char,
|
||||
typeid.as_bytes().len() as c_uint,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn store(&mut self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value {
|
||||
self.store_with_flags(val, ptr, align, MemFlags::empty())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue