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
|
@ -20,7 +20,7 @@ use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
|||
use rustc_middle::ty::{self, Instance, Ty, TypeVisitable};
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::{sym, Symbol};
|
||||
use rustc_symbol_mangling::typeid_for_fnabi;
|
||||
use rustc_symbol_mangling::typeid::typeid_for_fnabi;
|
||||
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
|
||||
use rustc_target::abi::{self, HasDataLayout, InitKind, WrappingRange};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
@ -920,7 +920,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
// FIXME(rcvalle): Add support for generalized identifiers.
|
||||
// FIXME(rcvalle): Create distinct unnamed MDNodes for internal identifiers.
|
||||
let typeid = typeid_for_fnabi(bx.tcx(), fn_abi);
|
||||
let typeid_metadata = bx.typeid_metadata(typeid);
|
||||
let typeid_metadata = self.cx.typeid_metadata(typeid);
|
||||
|
||||
// Test whether the function pointer is associated with the type identifier.
|
||||
let cond = bx.type_test(fn_ptr, typeid_metadata);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue