Skip to content

Commit d5a6aaf

Browse files
committed
Auto merge of rust-lang#89652 - rcvalle:rust-cfi, r=nagisa
Add LLVM CFI support to the Rust compiler This PR adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments. 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 defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue rust-lang#89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). Thank you, `@eddyb` and `@pcc,` for all the help!
2 parents 8094e2e + 14b83de commit d5a6aaf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/builder.rs

+10
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,16 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
915915
// TODO(antoyo)
916916
}
917917

918+
fn type_metadata(&mut self, _function: RValue<'gcc>, _typeid: String) {
919+
// Unsupported.
920+
}
921+
922+
fn typeid_metadata(&mut self, _typeid: String) -> RValue<'gcc> {
923+
// Unsupported.
924+
self.context.new_rvalue_from_int(self.int_type, 0)
925+
}
926+
927+
918928
fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
919929
self.store_with_flags(val, ptr, align, MemFlags::empty())
920930
}

src/intrinsic/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
367367
// TODO(antoyo)
368368
}
369369

370+
fn type_test(&mut self, _pointer: Self::Value, _typeid: Self::Value) -> Self::Value {
371+
// Unsupported.
372+
self.context.new_rvalue_from_int(self.int_type, 0)
373+
}
374+
370375
fn va_start(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> {
371376
unimplemented!();
372377
}

0 commit comments

Comments
 (0)