Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 004aa15

Browse files
committedMay 3, 2023
Add cross-language LLVM CFI support to the Rust compiler
This commit adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395). It provides 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). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653. Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).
1 parent fec9adc commit 004aa15

File tree

70 files changed

+1384
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1384
-387
lines changed
 

‎compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
501501
if options.contains(InlineAsmOptions::NORETURN) {
502502
let builtin_unreachable = self.context.get_builtin_function("__builtin_unreachable");
503503
let builtin_unreachable: RValue<'gcc> = unsafe { std::mem::transmute(builtin_unreachable) };
504-
self.call(self.type_void(), None, builtin_unreachable, &[], None);
504+
self.call(self.type_void(), None, None, builtin_unreachable, &[], None);
505505
}
506506

507507
// Write results to outputs.

‎compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_codegen_ssa::traits::{
3535
};
3636
use rustc_data_structures::fx::FxHashSet;
3737
use rustc_middle::bug;
38+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
3839
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
3940
use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout};
4041
use rustc_span::Span;
@@ -455,12 +456,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
455456
}
456457

457458
#[cfg(feature="master")]
458-
fn invoke(&mut self, typ: Type<'gcc>, _fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
459+
fn invoke(&mut self, typ: Type<'gcc>, fn_attrs: Option<&CodegenFnAttrs>, _fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
459460
let try_block = self.current_func().new_block("try");
460461

461462
let current_block = self.block.clone();
462463
self.block = try_block;
463-
let call = self.call(typ, None, func, args, None); // TODO(antoyo): use funclet here?
464+
let call = self.call(typ, fn_attrs, None, func, args, None); // TODO(antoyo): use funclet here?
464465
self.block = current_block;
465466

466467
let return_value = self.current_func()
@@ -483,8 +484,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
483484
}
484485

485486
#[cfg(not(feature="master"))]
486-
fn invoke(&mut self, typ: Type<'gcc>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
487-
let call_site = self.call(typ, None, func, args, None);
487+
fn invoke(&mut self, typ: Type<'gcc>, fn_attrs: &CodegenFnAttrs, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> {
488+
let call_site = self.call(typ, fn_attrs, None, func, args, None);
488489
let condition = self.context.new_rvalue_from_int(self.bool_type, 1);
489490
self.llbb().end_with_conditional(None, condition, then, catch);
490491
if let Some(_fn_abi) = fn_abi {
@@ -1351,6 +1352,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13511352
fn call(
13521353
&mut self,
13531354
_typ: Type<'gcc>,
1355+
_fn_attrs: Option<&CodegenFnAttrs>,
13541356
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
13551357
func: RValue<'gcc>,
13561358
args: &[RValue<'gcc>],

0 commit comments

Comments
 (0)
Please sign in to comment.