Skip to content

Commit c5528ce

Browse files
committed
Auto merge of #95548 - rcvalle:rust-cfi-2, r=nagisa
Add fine-grained LLVM CFI support to the Rust compiler This PR 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 rust-lang/rust#89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). Thank you again, `@eddyb,` `@nagisa,` `@pcc,` and `@tmiasko` for all the help!
2 parents e5e7395 + bfe3c24 commit c5528ce

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/builder.rs

-10
Original file line numberDiff line numberDiff line change
@@ -784,16 +784,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
784784
// TODO(antoyo)
785785
}
786786

787-
fn type_metadata(&mut self, _function: RValue<'gcc>, _typeid: String) {
788-
// Unsupported.
789-
}
790-
791-
fn typeid_metadata(&mut self, _typeid: String) -> RValue<'gcc> {
792-
// Unsupported.
793-
self.context.new_rvalue_from_int(self.int_type, 0)
794-
}
795-
796-
797787
fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
798788
self.store_with_flags(val, ptr, align, MemFlags::empty())
799789
}

src/type_.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::convert::TryInto;
22

33
use gccjit::{RValue, Struct, Type};
4-
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods};
4+
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods};
55
use rustc_codegen_ssa::common::TypeKind;
66
use rustc_middle::{bug, ty};
77
use rustc_middle::ty::layout::TyAndLayout;
@@ -290,3 +290,14 @@ pub fn struct_fields<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
290290

291291
(result, packed)
292292
}
293+
294+
impl<'gcc, 'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
295+
fn set_type_metadata(&self, _function: RValue<'gcc>, _typeid: String) {
296+
// Unsupported.
297+
}
298+
299+
fn typeid_metadata(&self, _typeid: String) -> RValue<'gcc> {
300+
// Unsupported.
301+
self.context.new_rvalue_from_int(self.int_type, 0)
302+
}
303+
}

0 commit comments

Comments
 (0)