Skip to content

Commit

Permalink
Rollup merge of rust-lang#123200 - maurer:kcfi-abort, r=compiler-errors
Browse files Browse the repository at this point in the history
KCFI: Require -C panic=abort

While the KCFI scheme is not incompatible with unwinding, LLVM's `invoke` instruction does not currently support KCFI bundles. While it likely will in the near future, we won't be able to assume that in Rust for a while.

We encountered this problem while [turning on closure support](rust-lang#123106 (comment)).

r? `@workingjubilee`
  • Loading branch information
matthiaskrgr authored Mar 30, 2024
2 parents 1aa221a + 29c1a2b commit 6e74347
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ session_sanitizer_cfi_requires_lto = `-Zsanitizer=cfi` requires `-Clto` or `-Cli
session_sanitizer_cfi_requires_single_codegen_unit = `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`
session_sanitizer_kcfi_requires_panic_abort = `-Z sanitizer=kcfi` requires `-C panic=abort`
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ pub(crate) struct SanitizerCfiGeneralizePointersRequiresCfi;
#[diag(session_sanitizer_cfi_normalize_integers_requires_cfi)]
pub(crate) struct SanitizerCfiNormalizeIntegersRequiresCfi;

#[derive(Diagnostic)]
#[diag(session_sanitizer_kcfi_requires_panic_abort)]
pub(crate) struct SanitizerKcfiRequiresPanicAbort;

#[derive(Diagnostic)]
#[diag(session_split_lto_unit_requires_lto)]
pub(crate) struct SplitLtoUnitRequiresLto;
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,11 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
sess.dcx().emit_err(errors::SanitizerCfiRequiresLto);
}

// KCFI requires panic=abort
if sess.is_sanitizer_kcfi_enabled() && sess.panic_strategy() != PanicStrategy::Abort {
sess.dcx().emit_err(errors::SanitizerKcfiRequiresPanicAbort);
}

// LLVM CFI using rustc LTO requires a single codegen unit.
if sess.is_sanitizer_cfi_enabled()
&& sess.lto() == config::Lto::Fat
Expand Down
1 change: 1 addition & 0 deletions tests/ui/sanitizer/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//@[cfi]compile-flags: -Clto -Ccodegen-units=1
//@[kcfi]needs-llvm-components: x86
//@[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi --target x86_64-unknown-none
//@[kcfi]compile-flags: -C panic=abort
//@[leak]needs-sanitizer-leak
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak
//@[memory]needs-sanitizer-memory
Expand Down
1 change: 1 addition & 0 deletions tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass

pub fn main() {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/sanitizer/cfi-complex-receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass

use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/sanitizer/cfi-self-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass

use std::marker::PhantomData;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/sanitizer/cfi-virtual-auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass

trait Foo {
Expand Down

0 comments on commit 6e74347

Please sign in to comment.