Skip to content

Commit 0b4d960

Browse files
committed
sanitizers: Stabilize AddressSanitizer and LeakSanitizer
Stabilize AddressSanitizer and LeakSanitizer for the Tier 1 targets that support them.
1 parent 7f51a73 commit 0b4d960

27 files changed

+69
-26
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ pub(crate) fn target() -> Target {
1919
stack_probes: StackProbeType::Inline,
2020
supported_sanitizers: SanitizerSet::ADDRESS
2121
| SanitizerSet::CFI
22+
| SanitizerSet::HWADDRESS
2223
| SanitizerSet::KCFI
2324
| SanitizerSet::LEAK
2425
| SanitizerSet::MEMORY
2526
| SanitizerSet::MEMTAG
26-
| SanitizerSet::THREAD
27-
| SanitizerSet::HWADDRESS,
27+
| SanitizerSet::THREAD,
28+
stable_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::LEAK,
2829
supports_xray: true,
2930
..base::linux_gnu::opts()
3031
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) fn target() -> Target {
66
base.cpu = "pentium4".into();
77
base.max_atomic_width = Some(64);
88
base.supported_sanitizers = SanitizerSet::ADDRESS;
9+
base.stable_sanitizers = SanitizerSet::ADDRESS;
910

1011
base.add_pre_link_args(
1112
LinkerFlavor::Msvc(Lld::No),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) fn target() -> Target {
1919
base.cpu = "pentium4".into();
2020
base.max_atomic_width = Some(64);
2121
base.supported_sanitizers = SanitizerSet::ADDRESS;
22+
base.stable_sanitizers = SanitizerSet::ADDRESS;
2223
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
2324
base.stack_probes = StackProbeType::Inline;
2425

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) fn target() -> Target {
2323
| SanitizerSet::CFI
2424
| SanitizerSet::LEAK
2525
| SanitizerSet::THREAD,
26+
stable_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::LEAK,
2627
..opts
2728
},
2829
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub(crate) fn target() -> Target {
77
base.plt_by_default = false;
88
base.max_atomic_width = Some(128);
99
base.supported_sanitizers = SanitizerSet::ADDRESS;
10+
base.stable_sanitizers = SanitizerSet::ADDRESS;
1011

1112
Target {
1213
llvm_target: "x86_64-pc-windows-msvc".into(),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ pub(crate) fn target() -> Target {
1212
base.static_position_independent_executables = true;
1313
base.supported_sanitizers = SanitizerSet::ADDRESS
1414
| SanitizerSet::CFI
15-
| SanitizerSet::KCFI
1615
| SanitizerSet::DATAFLOW
16+
| SanitizerSet::KCFI
1717
| SanitizerSet::LEAK
1818
| SanitizerSet::MEMORY
1919
| SanitizerSet::SAFESTACK
2020
| SanitizerSet::THREAD;
21+
base.stable_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK;
2122
base.supports_xray = true;
2223

2324
// When we're asked to use the `rust-lld` linker by default, set the appropriate lld-using

tests/codegen/sanitizer/cfi/external_weak_symbols.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// emitted correctly.
33
//
44
//@ needs-sanitizer-cfi
5-
//@ compile-flags: -Clinker-plugin-lto -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static
5+
//@ compile-flags: -Clinker-plugin-lto -Copt-level=0 -Zunstable-options -Csanitize=cfi -Ctarget-feature=-crt-static
66
#![crate_type = "bin"]
77
#![feature(linkage)]
88

tests/codegen/sanitizer/kasan-emits-instrumentation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Verifies that `-Csanitize=kernel-address` emits sanitizer instrumentation.
22

33
//@ add-core-stubs
4-
//@ compile-flags: -Zunstable-options -Zsanitizer=kernel-address -Copt-level=0
4+
//@ compile-flags: -Zunstable-options -Csanitize=kernel-address -Copt-level=0
55
//@ revisions: aarch64 riscv64imac riscv64gc x86_64
66
//@[aarch64] compile-flags: --target aarch64-unknown-none
77
//@[aarch64] needs-llvm-components: aarch64

tests/codegen/sanitizer/riscv64-shadow-call-stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ add-core-stubs
2-
//@ compile-flags: --target riscv64imac-unknown-none-elf -Zunstable-options -Zsanitizer=shadow-call-stack
2+
//@ compile-flags: --target riscv64imac-unknown-none-elf -Zunstable-options -Csanitize=shadow-call-stack
33
//@ needs-llvm-components: riscv
44

55
#![allow(internal_features)]

tests/ui/asm/global-asm-isnt-really-a-mir-body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//@[instrument] only-linux
99

1010
// Make sure we don't try to CFI encode it.
11-
//@[cfi] compile-flags: -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Clink-dead-code=true
11+
//@[cfi] compile-flags: -Zunstable-options -Csanitize=cfi -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Clink-dead-code=true
1212
//@[cfi] needs-sanitizer-cfi
1313
//@[cfi] no-prefer-dynamic
1414
// FIXME(#122848) Remove only-linux once OSX CFI binaries work

tests/ui/sanitizer/cfi/canonical-jump-tables-requires-cfi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#![no_core]
88
#![no_main]
99

10-
//~? ERROR `-Zsanitizer-cfi-canonical-jump-tables` requires `-Zsanitizer=cfi`
10+
//~? ERROR `-Zsanitizer-cfi-canonical-jump-tables` requires `-Csanitize=cfi`

tests/ui/sanitizer/cfi/generalize-pointers-requires-cfi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
#![no_core]
99
#![no_main]
1010

11-
//~? ERROR `-Zsanitizer-cfi-generalize-pointers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi`
11+
//~? ERROR `-Zsanitizer-cfi-generalize-pointers` requires `-Csanitize=cfi` or `-Csanitize=kcfi`

tests/ui/sanitizer/cfi/is-incompatible-with-kcfi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
#![no_main]
1313

1414
//~? ERROR cfi sanitizer is not supported for this target
15-
//~? ERROR `-Zsanitizer=cfi` is incompatible with `-Zsanitizer=kcfi`
15+
//~? ERROR `-Csanitize=cfi` is incompatible with `-Csanitize=kcfi`

tests/ui/sanitizer/cfi/normalize-integers-requires-cfi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
#![no_core]
99
#![no_main]
1010

11-
//~? ERROR `-Zsanitizer-cfi-normalize-integers` requires `-Zsanitizer=cfi` or `-Zsanitizer=kcfi`
11+
//~? ERROR `-Zsanitizer-cfi-normalize-integers` requires `-Csanitize=cfi` or `-Csanitize=kcfi`

tests/ui/sanitizer/cfi/requires-lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#![no_core]
88
#![no_main]
99

10-
//~? ERROR `-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto`
10+
//~? ERROR `-Csanitize=cfi` requires `-Clto` or `-Clinker-plugin-lto`

tests/ui/sanitizer/cfi/with-rustc-lto-requires-single-codegen-unit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#![no_core]
88
#![no_main]
99

10-
//~? ERROR `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`
10+
//~? ERROR `-Csanitize=cfi` with `-Clto` requires `-Ccodegen-units=1`

tests/ui/sanitizer/incompatible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
#![no_core]
66
#![no_main]
77

8-
//~? ERROR `-Zsanitizer=address` is incompatible with `-Zsanitizer=memory`
8+
//~? ERROR `-Csanitize=address` is incompatible with `-Csanitize=memory`
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Verifies that `-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later.
22
//
33
//@ needs-sanitizer-kcfi
4-
//@ compile-flags: -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Cpanic=abort -Zsanitizer=kcfi -Zsanitizer-kcfi-arity
4+
//@ compile-flags: -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Cpanic=abort -Zunstable-options -Csanitize=kcfi -Zsanitizer-kcfi-arity
55
//@ build-fail
66
//@ max-llvm-major-version: 20
77

8-
//~? ERROR `-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later.
98
#![feature(no_core)]
109
#![no_core]
1110
#![no_main]
11+
12+
//~? ERROR `-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Verifies that stable and unstable supported sanitizers can be used with `-Zunstable-options`.
2+
//
3+
//@ needs-llvm-components: x86
4+
//@ needs-sanitizer-support
5+
//@ build-pass
6+
//@ compile-flags: -Zunstable-options -Clto -Csanitize=address,cfi --target x86_64-unknown-linux-gnu
7+
8+
#![crate_type = "rlib"]
9+
#![feature(no_core)]
10+
#![no_core]
11+
#![no_main]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Verifies that stable and unstable supported sanitizers cannot be used without
2+
// `-Zunstable-options`.
3+
//
4+
//@ needs-llvm-components: x86
5+
//@ needs-sanitizer-support
6+
//@ compile-flags: -Clto -Csanitize=address,cfi --target x86_64-unknown-linux-gnu
7+
//@ error-pattern: error: cfi sanitizer is not supported for this target
8+
9+
fn main() { }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: cfi sanitizer is not supported for this target
2+
3+
error: aborting due to 1 previous error
4+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Verifies that stable supported sanitizers can be used with `-Zunstable-options`.
2+
//
3+
//@ needs-llvm-components: x86
4+
//@ needs-sanitizer-support
5+
//@ build-pass
6+
//@ compile-flags: -Zunstable-options -Csanitize=address --target x86_64-unknown-linux-gnu
7+
8+
fn main() { }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Verifies that stable supported sanitizers can be used without `-Zunstable-options`.
2+
//
3+
//@ needs-llvm-components: x86
4+
//@ needs-sanitizer-support
5+
//@ build-pass
6+
//@ compile-flags: -Csanitize=address --target x86_64-unknown-linux-gnu
7+
8+
fn main() { }

tests/ui/sanitizer/unstable-supported-cannot-be-used-without-unstable-options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
//
33
//@ needs-llvm-components: x86
44
//@ compile-flags: -Csanitize=kernel-address --target x86_64-unknown-none
5-
//@ error-pattern: error: kernel-address sanitizer is not supported for this target
65

76
#![feature(no_core)]
87
#![no_core]
98
#![no_main]
9+
10+
//~? ERROR kernel-address sanitizer is not supported for this target

tests/ui/sanitizer/unsupported-cannot-be-used-with-unstable-options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
#![feature(no_core)]
88
#![no_core]
99
#![no_main]
10+
11+
//~? ERROR kernel-address sanitizer is not supported for this target

tests/ui/sanitizer/unsupported-cannot-be-used-without-unstable-options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
//
33
//@ needs-llvm-components: x86
44
//@ compile-flags: -Csanitize=kernel-address --target x86_64-unknown-linux-gnu
5-
//@ error-pattern: error: kernel-address sanitizer is not supported for this target
65

76
#![feature(no_core)]
87
#![no_core]
98
#![no_main]
9+
10+
//~? ERROR kernel-address sanitizer is not supported for this target

tests/ui/sanitizer/unsupported-target.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)