Skip to content

Commit 2c0a8de

Browse files
committed
CFI: Enable KCFI testing of run-pass tests
This enables KCFI-based testing for all the CFI run-pass tests in the suite today. We can add the test header on top of in-flight CFI tests once they land. It also enables KCFI as a sanitizer for x86_64 and aarch64 Linux to make this possible. The sanitizer should likely be available for all aarch64, x86_64, and riscv targets, but that isn't critical for initial testing.
1 parent c98ea0d commit 2c0a8de

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> Target {
1919
stack_probes: StackProbeType::Inline,
2020
supported_sanitizers: SanitizerSet::ADDRESS
2121
| SanitizerSet::CFI
22+
| SanitizerSet::KCFI
2223
| SanitizerSet::LEAK
2324
| SanitizerSet::MEMORY
2425
| SanitizerSet::MEMTAG

compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn target() -> Target {
1010
base.static_position_independent_executables = true;
1111
base.supported_sanitizers = SanitizerSet::ADDRESS
1212
| SanitizerSet::CFI
13+
| SanitizerSet::KCFI
1314
| SanitizerSet::DATAFLOW
1415
| SanitizerSet::LEAK
1516
| SanitizerSet::MEMORY

src/tools/compiletest/src/header.rs

+1
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
826826
"needs-sanitizer-cfi",
827827
"needs-sanitizer-dataflow",
828828
"needs-sanitizer-hwaddress",
829+
"needs-sanitizer-kcfi",
829830
"needs-sanitizer-leak",
830831
"needs-sanitizer-memory",
831832
"needs-sanitizer-memtag",

tests/ui/sanitizer/cfi-closure-fn-ptr-cast.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
//
66
// This checks that the reified function pointer will have the expected alias set at its call-site.
77

8-
//@ needs-sanitizer-cfi
8+
//@ revisions: cfi kcfi
99
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
1010
//@ only-linux
11-
//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi
12-
//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0
11+
//@ [cfi] needs-sanitizer-cfi
12+
//@ [kcfi] needs-sanitizer-kcfi
13+
//@ compile-flags: -C target-feature=-crt-static
14+
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
15+
//@ [cfi] compile-flags: -Z sanitizer=cfi
16+
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
1317
//@ run-pass
1418

1519
pub fn main() {

tests/ui/sanitizer/cfi-complex-receiver.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
// * Arc<dyn Foo> as for custom receivers
33
// * &dyn Bar<T=Baz> for type constraints
44

5-
//@ needs-sanitizer-cfi
5+
//@ revisions: cfi kcfi
66
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
77
//@ only-linux
8-
//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi
9-
//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0
8+
//@ [cfi] needs-sanitizer-cfi
9+
//@ [kcfi] needs-sanitizer-kcfi
10+
//@ compile-flags: -C target-feature=-crt-static
11+
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
12+
//@ [cfi] compile-flags: -Z sanitizer=cfi
13+
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
1014
//@ run-pass
1115

1216
use std::sync::Arc;

tests/ui/sanitizer/cfi-self-ref.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// Check that encoding self-referential types works with #[repr(transparent)]
22

3-
//@ needs-sanitizer-cfi
3+
//@ revisions: cfi kcfi
44
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
55
//@ only-linux
6-
//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi
7-
//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0
6+
//@ [cfi] needs-sanitizer-cfi
7+
//@ [kcfi] needs-sanitizer-kcfi
8+
//@ compile-flags: -C target-feature=-crt-static
9+
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
10+
//@ [cfi] compile-flags: -Z sanitizer=cfi
11+
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
812
//@ run-pass
913

1014
use std::marker::PhantomData;

tests/ui/sanitizer/cfi-virtual-auto.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// Tests that calling a trait object method on a trait object with additional auto traits works.
22

3-
//@ needs-sanitizer-cfi
3+
//@ revisions: cfi kcfi
44
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
55
//@ only-linux
6-
//@ compile-flags: --crate-type=bin -Cprefer-dynamic=off -Clto -Zsanitizer=cfi
7-
//@ compile-flags: -C target-feature=-crt-static -C codegen-units=1 -C opt-level=0
6+
//@ [cfi] needs-sanitizer-cfi
7+
//@ [kcfi] needs-sanitizer-kcfi
8+
//@ compile-flags: -C target-feature=-crt-static
9+
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
10+
//@ [cfi] compile-flags: -Z sanitizer=cfi
11+
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
812
//@ run-pass
913

1014
trait Foo {

0 commit comments

Comments
 (0)