From f05f75a25c001b3eb2ecb8c80d4b52b19eeda4fc Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Mon, 8 Sep 2025 16:47:37 +0000 Subject: [PATCH] Stabilize `-Zstack-protector` as `-Cstack-protector` I propose stabilizing `-Cstack-protector` as `-Zstack-protector`. This PR adds a new `-Cstack-protector` flag, leaving the unstable `-Z` flag as is to ease the transition period. The `-Z` flag will be removed in the future. No RFC/MCP, this flag was added in 84197 and was not deemed large enough to require additional process. The tracking issue for this feature is 114903. The `-Cstack-protector=strong` mode uses the same underlying heuristics as Clang's `-fstack-protector-strong`. These heuristics weren't designed for Rust, and may be over-conservative in some cases - for example, if Rust stores a field's data in an alloca using an LLVM array type, LLVM regard the alloca as meaning that the function has a C array, and enable stack overflow canaries even if the function accesses the alloca in a safe way. Some people thought we should wait on stabilization until there are better heuristics, but I didn't hear about any concrete case where this unduly harms performance, and I think that when a need comes, we can improve the heuristics in LLVM after stabilization. The heuristics do seem to not be under-conservative, so this should not be a security risk. The `-Cstack-protector=basic` mode (`-fstack-protector`) uses heuristics that are specifically designed to catch old-C-style string manipulation. This is not a good fit to Rust, which does not perform much unsafe C-style string manipulation. As far as I can tell, nobody has been asking for it, and few people are using it even in today's C - modern distros (e.g. [Debian]) tend to use `-fstack-protector-strong`. Therefore, `-Cstack-protector=basic` has been **removed**. If anyone is interested in it, they are welcome to add it back as an unstable option. [Debian]: https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_STACKPROTECTOR_.28gcc.2Fg.2B-.2B-_-fstack-protector-strong.29 Most implementation was done in . The command-line attribute enables the relevant LLVM attribute on all functions in . Each target can indicate that it does not support stack canaries - currently, the GPU platforms `nvptx64-nvidia-cuda` and `amdgcn-amd-amdhsa`. On these platforms, use of `-Cstack-protector` causes an error. The feature has tests that make sure that the LLVM heuristic gives reasonable results for several functions, by checking for `__security_check_cookie` (on Windows) or `__stack_chk_fail` (on Linux). See No call-for-testing has been conducted, but the feature seems to be in use. No reported bugs seem to exist. - bbjornse was the original implementor at 84197 - mrcnski documented it at 111722 - wesleywiser added tests for Windows at 116037 - davidtwco worked on the feature at 121742 - nikic provided support from the LLVM side (on Zulip on and elsewhere), thanks nikic! No FIXMEs related to this feature. This feature cannot cause undefined behavior. No changes to reference/spec, docs added to the codegen docs as part of the stabilization PR. No. None. No support needed for rustdoc, clippy, rust-analyzer, rustfmt or rustup. Cargo could expose this as an option in build profiles but I would expect the decision as to what version should be used would be made for the entire crate graph at build time rather than by individual package authors. `-C stack-protector` is propagated to C compilers using cc-rs via rust-lang/cc-rs issue 1550 --- bootstrap.example.toml | 2 +- compiler/rustc_interface/src/tests.rs | 3 +- compiler/rustc_metadata/src/creader.rs | 9 +++-- compiler/rustc_session/src/diagnostics.rs | 4 +- compiler/rustc_session/src/options.rs | 14 +++++-- .../src/options/mitigation_coverage.rs | 1 - compiler/rustc_session/src/session.rs | 21 ++++++---- src/bootstrap/src/core/builder/cargo.rs | 2 + src/doc/rustc/src/codegen-options/index.md | 23 +++++++++++ src/doc/rustc/src/exploit-mitigations.md | 2 +- .../stack-protector-heuristics-effect.rs | 6 +-- ...ector-heuristics-effect-windows-32bit-2.rs | 6 +-- ...otector-heuristics-effect-windows-32bit.rs | 10 ++--- ...otector-heuristics-effect-windows-64bit.rs | 10 ++--- .../stack-protector-heuristics-effect.rs | 12 +++--- .../stack-protector-target-support.rs | 14 +++---- tests/codegen-llvm/stack-protector.rs | 28 +++++++++++-- tests/ui/README.md | 2 +- tests/ui/abi/stack-protector.rs | 2 +- ...d-future-allow-reset-by-mitigation.stderr} | 0 ...l-mitigations-1-error-no-future-compat.rs} | 9 +++-- ...mpat.stack-protector-future-stable.stderr} | 12 ------ .../err-allow-partial-mitigations-1-error.rs | 5 +-- ...ion.control-flow-2024-explicit-deny.stderr | 27 ------------- ...low-partial-mitigations-current-edition.rs | 35 ----------------- ...2024-allow-deny-reset-by-mitigation.stderr | 39 ------------------- ...urrent-edition.stack-protector-2024.stderr | 39 ------------------- ...l-stack-protector-unsupported.all-z.stderr | 4 ++ ...ail-stack-protector-unsupported.all.stderr | 4 ++ .../fail-stack-protector-unsupported.rs | 30 ++++++++++++++ ...-stack-protector-unsupported.strong.stderr | 4 ++ .../no-stack-protector-basic.rs | 7 +++- .../no-stack-protector-basic.stable.stderr | 2 + ... no-stack-protector-basic.unstable.stderr} | 0 ...arn-stack-protector-unsupported.all.stderr | 4 -- .../warn-stack-protector-unsupported.rs | 28 ------------- ...-stack-protector-unsupported.strong.stderr | 4 -- 37 files changed, 169 insertions(+), 255 deletions(-) rename tests/ui/allow-partial-mitigations/{err-allow-partial-mitigations-1-error-control-flow-guard.control-flow-guard-future-allow-reset-by-mitigation.stderr => err-allow-partial-mitigations-1-error-no-future-compat.control-flow-guard-future-allow-reset-by-mitigation.stderr} (100%) rename tests/ui/allow-partial-mitigations/{err-allow-partial-mitigations-1-error-control-flow-guard.rs => err-allow-partial-mitigations-1-error-no-future-compat.rs} (77%) rename tests/ui/allow-partial-mitigations/{err-allow-partial-mitigations-current-edition.stack-protector-2024-deny-reset-by-mitigation.stderr => err-allow-partial-mitigations-1-error-no-future-compat.stack-protector-future-stable.stderr} (62%) delete mode 100644 tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.control-flow-2024-explicit-deny.stderr delete mode 100644 tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.rs delete mode 100644 tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-allow-deny-reset-by-mitigation.stderr delete mode 100644 tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024.stderr create mode 100644 tests/ui/stack-protector/fail-stack-protector-unsupported.all-z.stderr create mode 100644 tests/ui/stack-protector/fail-stack-protector-unsupported.all.stderr create mode 100644 tests/ui/stack-protector/fail-stack-protector-unsupported.rs create mode 100644 tests/ui/stack-protector/fail-stack-protector-unsupported.strong.stderr create mode 100644 tests/ui/stack-protector/no-stack-protector-basic.stable.stderr rename tests/ui/stack-protector/{no-stack-protector-basic.stderr => no-stack-protector-basic.unstable.stderr} (100%) delete mode 100644 tests/ui/stack-protector/warn-stack-protector-unsupported.all.stderr delete mode 100644 tests/ui/stack-protector/warn-stack-protector-unsupported.rs delete mode 100644 tests/ui/stack-protector/warn-stack-protector-unsupported.strong.stderr diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 6740de03eb800..8bbc2a85e8c93 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -783,7 +783,7 @@ #rust.frame-pointers = false # Indicates whether stack protectors should be used -# via the unstable option `-Zstack-protector`. +# via `-Cstack-protector`. # # Valid options are : `none`(default), `strong`, or `all`. #rust.stack-protector = "none" diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index fd54da09bdca6..fbafda0a167e8 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -664,6 +664,7 @@ fn test_codegen_options_tracking_hash() { tracked!(relocation_model, Some(RelocModel::Pic)); tracked!(relro_level, Some(RelroLevel::Full)); tracked!(split_debuginfo, Some(SplitDebuginfo::Packed)); + tracked!(stack_protector, Some(StackProtector::All)); tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0)); tracked!(target_cpu, Some(String::from("abc"))); tracked!(target_feature, String::from("all the features, all of them")); @@ -901,7 +902,7 @@ fn test_unstable_options_tracking_hash() { tracked!(small_data_threshold, Some(16)); tracked!(split_lto_unit, Some(true)); tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1)); - tracked!(stack_protector, StackProtector::All); + tracked!(stack_protector, Some(StackProtector::All)); tracked!(staticlib_hide_internal_symbols, true); tracked!(staticlib_rename_internal_symbols, true); tracked!(teach, true); diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 70302bbef51cb..c2098d830e372 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -561,9 +561,12 @@ impl CStore { mitigation_level: my_mitigation.level.level_str().to_string(), extern_crate: data.name(), }; - if my_mitigation.kind == DeniedPartialMitigationKind::StackProtector { - // make stack-protector only a forward-compat warning since it was - // pretty widely used + // Make stack-protector with -Z stack-protector only a forward-compat warning since it was + // pretty widely used. When using -C stack-protector, it should still be a hard error since + // -C stack-protector has no pre-existing users + if my_mitigation.kind == DeniedPartialMitigationKind::StackProtector + && !tcx.sess.using_stable_stack_protector() + { tcx.sess.psess.buffer_crate_lint(PARTIAL_STACK_PROTECTOR, diagnostic); } else { tcx.dcx().emit_err(diagnostic); diff --git a/compiler/rustc_session/src/diagnostics.rs b/compiler/rustc_session/src/diagnostics.rs index 53a0fde70b089..41c61bcf67350 100644 --- a/compiler/rustc_session/src/diagnostics.rs +++ b/compiler/rustc_session/src/diagnostics.rs @@ -386,9 +386,7 @@ pub(crate) struct EmbedSourceInsufficientDwarfVersion { pub(crate) struct EmbedSourceRequiresDebugInfo; #[derive(Diagnostic)] -#[diag( - "`-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored" -)] +#[diag("`-C stack-protector={$stack_protector}` is not supported for target {$target_triple}")] pub(crate) struct StackProtectorNotSupportedForTarget<'a> { pub(crate) stack_protector: StackProtector, pub(crate) target_triple: &'a TargetTuple, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index d8da338f83d87..9047579345274 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2050,9 +2050,12 @@ pub mod parse { true } - pub(crate) fn parse_stack_protector(slot: &mut StackProtector, v: Option<&str>) -> bool { + pub(crate) fn parse_stack_protector( + slot: &mut Option, + v: Option<&str>, + ) -> bool { match v.and_then(|s| StackProtector::from_str(s).ok()) { - Some(ssp) => *slot = ssp, + Some(ssp) => *slot = Some(ssp), _ => return false, } true @@ -2376,6 +2379,9 @@ options! { #[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")] split_debuginfo: Option = (None, parse_split_debuginfo, [TRACKED], "how to handle split-debuginfo, a platform-specific option"), + #[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")] + stack_protector: Option = (None, parse_stack_protector, [TRACKED] { MITIGATION: StackProtector }, + "control stack smashing protection strategy (`rustc --print stack-protector-strategies` for details)"), strip: Strip = (Strip::None, parse_strip, [UNTRACKED], "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"), symbol_mangling_version: Option = (None, @@ -2946,8 +2952,8 @@ written to standard error output)"), src_hash_algorithm: Option = (None, parse_src_file_hash, [TRACKED], "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"), #[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")] - stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED] { MITIGATION: StackProtector }, - "control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"), + stack_protector: Option = (None, parse_stack_protector, [TRACKED] { MITIGATION: StackProtector }, + "control stack smashing protection strategy (`rustc --print stack-protector-strategies` for details)"), staticlib_allow_rdylib_deps: bool = (false, parse_bool, [TRACKED], "allow staticlibs to have rust dylib dependencies"), staticlib_hide_internal_symbols: bool = (false, parse_bool, [TRACKED], diff --git a/compiler/rustc_session/src/options/mitigation_coverage.rs b/compiler/rustc_session/src/options/mitigation_coverage.rs index 5dea83e5751e0..9fe4ee8302ea1 100644 --- a/compiler/rustc_session/src/options/mitigation_coverage.rs +++ b/compiler/rustc_session/src/options/mitigation_coverage.rs @@ -200,7 +200,6 @@ denied_partial_mitigations! { // The mitigation name should match the option name in rustc_session::options, // to allow for resetting the mitigation - // stack-protector is an unstable option, so it can be denied-partial (StackProtector, "stack-protector", Edition2015, self.stack_protector()), (ControlFlowGuard, "control-flow-guard", EditionFuture, self.opts.cg.control_flow_guard == CFGuard::Checks) } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 9bf2de0466233..ffc17dad5b13a 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1120,11 +1120,16 @@ impl Session { } pub fn stack_protector(&self) -> StackProtector { - if self.target.options.supports_stack_protector { - self.opts.unstable_opts.stack_protector - } else { - StackProtector::None - } + // -C stack-protector overwrites -Z stack-protector, default to StackProtector::None + self.opts + .cg + .stack_protector + .or(self.opts.unstable_opts.stack_protector) + .unwrap_or(StackProtector::None) + } + + pub fn using_stable_stack_protector(&self) -> bool { + self.opts.cg.stack_protector.is_some() } /// Returns the `-Zbranch-protection` info. Note that it is adjusted to the current target, e.g. @@ -1738,10 +1743,10 @@ fn validate_commandline_args_with_session_available(sess: &Session) { } } - if sess.opts.unstable_opts.stack_protector != StackProtector::None { + if sess.stack_protector() != StackProtector::None { if !sess.target.options.supports_stack_protector { - sess.dcx().emit_warn(diagnostics::StackProtectorNotSupportedForTarget { - stack_protector: sess.opts.unstable_opts.stack_protector, + sess.dcx().emit_err(diagnostics::StackProtectorNotSupportedForTarget { + stack_protector: sess.stack_protector(), target_triple: &sess.opts.target_triple, }); } diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index 5928860bad0a9..9f6f7062ea6f3 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -1095,6 +1095,8 @@ impl Builder<'_> { cargo.env(profile_var("STRIP"), self.config.rust_strip.to_string()); if let Some(stack_protector) = &self.config.rust_stack_protector { + // Use -Zstack-protector here instead of -Cstack-protector + // to avoid bootstrap problems using the 1.100 stage0 compiler. rustflags.arg(&format!("-Zstack-protector={stack_protector}")); } diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 67c4fd7806933..3e977d1247e14 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -688,6 +688,29 @@ Note that all three options are supported on Linux and Apple platforms, Attempting to use an unsupported option requires using the nightly channel with the `-Z unstable-options` flag. +## stack-protector + +The option `-C stack-protector` controls the generation of +stack-protector canaries which offer stack smashing protection. + +The exact presence, location and behavior of the stack-protector canaries depend +on rustc's codegen backend, the target architecture, and codegen details, and are +unstable and subject to change. + +Supported values for this option are: +- `none` (default): Disable stack canary generation +- `strong`: Generate stack canaries in any function that could be the source + of a stack buffer overflow (even in the presence of undefined behavior). + This provides similar security guarantees to Clang (or GCC's) + `-fstack-protector-strong`. +- `all`: Generate stack canaries in all functions + +There is no mode equivalent to Clang's (or GCC's) plain `-fstack-protector` +because its heuristic is tuned for C and does not offer protection for Rust programs. + +Stack protectors are not supported on some targets such as GPU targets; use +of stack protectors on these targets is an error. + ## strip The option `-C strip=val` controls stripping of debuginfo and similar auxiliary diff --git a/src/doc/rustc/src/exploit-mitigations.md b/src/doc/rustc/src/exploit-mitigations.md index 41e5c93a1b7dc..a9c8d9949370c 100644 --- a/src/doc/rustc/src/exploit-mitigations.md +++ b/src/doc/rustc/src/exploit-mitigations.md @@ -62,7 +62,7 @@ equivalent. | Stack clashing protection | Yes | Yes | 1.20.0 (2017-08-31) | | Read-only relocations and immediate binding | Yes | Yes | 1.21.0 (2017-10-12) | | Heap corruption protection | Yes | Yes | 1.32.0 (2019-01-17) (via operating system default or specified allocator) | -| Stack smashing protection | Yes | No, `-Z stack-protector` | Nightly | +| Stack smashing protection | Yes | No, `-C stack-protector` | 1.101.0 (2026-12-24) | | Forward-edge control flow protection | Yes | No, `-Z sanitizer=cfi` | Nightly | | Backward-edge control flow protection (e.g., shadow and safe stack) | Yes | No, `-Z sanitizer=shadow-call-stack,safestack` | Nightly | diff --git a/tests/assembly-gcc/stack-protector/stack-protector-heuristics-effect.rs b/tests/assembly-gcc/stack-protector/stack-protector-heuristics-effect.rs index 9366e949856d4..cb995b0352ce7 100644 --- a/tests/assembly-gcc/stack-protector/stack-protector-heuristics-effect.rs +++ b/tests/assembly-gcc/stack-protector/stack-protector-heuristics-effect.rs @@ -4,9 +4,9 @@ //@ ignore-msvc stack check code uses different function names //@ ignore-nvptx64 stack protector is not supported //@ ignore-wasm32-unknown-unknown -//@ [all] compile-flags: -Z stack-protector=all -//@ [strong] compile-flags: -Z stack-protector=strong -//@ [none] compile-flags: -Z stack-protector=none +//@ [all] compile-flags: -C stack-protector=all +//@ [strong] compile-flags: -C stack-protector=strong +//@ [none] compile-flags: -C stack-protector=none //@ compile-flags: -C opt-level=2 -Z merge-functions=disabled -Z allow-partial-mitigations=stack-protector #![crate_type = "lib"] diff --git a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit-2.rs b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit-2.rs index 4be0c3a3dbe98..033f7e81f230e 100644 --- a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit-2.rs +++ b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit-2.rs @@ -3,9 +3,9 @@ //@ only-windows //@ only-msvc //@ ignore-64bit 64-bit table based SEH has slightly different behaviors than classic SEH -//@ [all] compile-flags: -Z stack-protector=all -//@ [strong] compile-flags: -Z stack-protector=strong -//@ [none] compile-flags: -Z stack-protector=none +//@ [all] compile-flags: -C stack-protector=all +//@ [strong] compile-flags: -C stack-protector=strong +//@ [none] compile-flags: -C stack-protector=none //@ compile-flags: -Z allow-partial-mitigations=stack-protector -C opt-level=2 -Z merge-functions=disabled #![crate_type = "lib"] diff --git a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit.rs b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit.rs index af808ad9d9257..396f0f7ecd6f9 100644 --- a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit.rs +++ b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-32bit.rs @@ -3,9 +3,9 @@ //@ only-windows //@ only-msvc //@ ignore-64bit 64-bit table based SEH has slightly different behaviors than classic SEH -//@ [all] compile-flags: -Z stack-protector=all -//@ [strong] compile-flags: -Z stack-protector=strong -//@ [none] compile-flags: -Z stack-protector=none +//@ [all] compile-flags: -C stack-protector=all +//@ [strong] compile-flags: -C stack-protector=strong +//@ [none] compile-flags: -C stack-protector=none //@ compile-flags: -Z allow-partial-mitigations=stack-protector -C opt-level=2 -Z merge-functions=disabled -Cpanic=abort -Cdebuginfo=1 #![crate_type = "lib"] @@ -124,7 +124,7 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) { // This function takes the address of a local variable taken. Although this // address is never used as a way to refer to stack memory, the `strong` - // heuristic adds stack smash protection. This is also the case in C++: + // heuristic adds stack smashing protection. This is also the case in C++: // ``` // cat << EOF | clang++ -O2 -fstack-protector-strong -S -x c++ - -o - | grep stack_chk // #include @@ -180,7 +180,7 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32 // Even though the local variable conceptually has its address taken, as // it's passed by reference to the trait function, the use of the reference - // is easily inlined. There is therefore no stack smash protection even with + // is easily inlined. There is therefore no stack smashing protection even with // the `strong` heuristic. // all: __security_check_cookie diff --git a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs index c4e9e760edfe5..33bad8e47140e 100644 --- a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs +++ b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs @@ -3,9 +3,9 @@ //@ only-windows //@ only-msvc //@ ignore-32bit 64-bit table based SEH has slightly different behaviors than classic SEH -//@ [all] compile-flags: -Z stack-protector=all -//@ [strong] compile-flags: -Z stack-protector=strong -//@ [none] compile-flags: -Z stack-protector=none +//@ [all] compile-flags: -C stack-protector=all +//@ [strong] compile-flags: -C stack-protector=strong +//@ [none] compile-flags: -C stack-protector=none //@ compile-flags: -Z allow-partial-mitigations=stack-protector -C opt-level=2 -Z merge-functions=disabled -Cpanic=abort #![crate_type = "lib"] @@ -129,7 +129,7 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) { // This function takes the address of a local variable taken. Although this // address is never used as a way to refer to stack memory, the `strong` - // heuristic adds stack smash protection. This is also the case C++: + // heuristic adds stack smashing protection. This is also the case in C++: // ``` // cat << EOF | clang++ -O2 -fstack-protector-strong -S -x c++ - -o - | grep stack_chk // #include @@ -186,7 +186,7 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32 // Even though the local variable conceptually has its address taken, as // it's passed by reference to the trait function, the use of the reference - // is easily inlined. There is therefore no stack smash protectionen with + // is easily inlined. There is therefore no stack smashing protection even with // the `strong` heuristic. // all: __security_check_cookie diff --git a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect.rs b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect.rs index aa6bbf7168b47..1257ee1aac74c 100644 --- a/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect.rs +++ b/tests/assembly-llvm/stack-protector/stack-protector-heuristics-effect.rs @@ -4,12 +4,12 @@ //@ ignore-msvc stack check code uses different function names //@ ignore-nvptx64 stack protector is not supported //@ ignore-wasm32-unknown-unknown -//@ [all] compile-flags: -Z stack-protector=all -//@ [strong] compile-flags: -Z stack-protector=strong -//@ [none] compile-flags: -Z stack-protector=none +//@ [all] compile-flags: -C stack-protector=all +//@ [strong] compile-flags: -C stack-protector=strong +//@ [none] compile-flags: -C stack-protector=none //@ compile-flags: -C opt-level=2 -Z merge-functions=disabled -Z allow-partial-mitigations=stack-protector -// NOTE: the heuristics for stack smash protection inappropriately rely on types in LLVM IR, +// NOTE: the heuristics for stack smashing protection inappropriately rely on types in LLVM IR, // despite those types having no semantic meaning. This means that the `basic` and `strong` // settings do not behave in a coherent way. This is a known issue in LLVM. // See comments on https://github.com/rust-lang/rust/issues/114903. @@ -120,7 +120,7 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) { // This function takes the address of a local variable taken. Although this // address is never used as a way to refer to stack memory, the `strong` - // heuristic adds stack smash protection. This is also the case in C++: + // heuristic adds stack smashing protection. This is also the case in C++: // ``` // cat << EOF | clang++ -O2 -fstack-protector-strong -S -x c++ - -o - | grep stack_chk // #include @@ -171,7 +171,7 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32 // Even though the local variable conceptually has its address taken, as // it's passed by reference to the trait function, the use of the reference - // is easily inlined. There is therefore no stack smash protection even with + // is easily inlined. There is therefore no stack smashing protection even with // the `strong` heuristic. // all: __stack_chk_fail diff --git a/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs b/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs index c2a4ad5e2f74e..d63d1b8fb88a4 100644 --- a/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs +++ b/tests/assembly-llvm/stack-protector/stack-protector-target-support.rs @@ -1,10 +1,10 @@ -// Test that stack smash protection code is emitted for all tier1 and tier2 +// Test that stack smashing protection code is emitted for all tier1 and tier2 // targets, with the exception of nvptx64-nvidia-cuda // //@ add-minicore //@ revisions: r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 //@ revisions: r24 r25 r26 r27 r28 r29 r30 r31 r32 r33 r36 r37 r38 r39 r40 r41 r42 r43 r44 -//@ revisions: r45 r46 r47 r48 r49 r50 r51 r52 r53 r54 r55 r56 r57 r58 r59 r60 r61 r62 r63 r64 r65 +//@ revisions: r45 r46 r47 r48 r50 r51 r52 r53 r54 r55 r56 r57 r58 r59 r60 r61 r62 r63 r64 r65 //@ revisions: r66 r67 r68 r69 r70 r71 r72 r73 r74 r75 r76 r77 r78 r79 r80 r81 r82 r83 r84 r85 //@ assembly-output: emit-asm //@ [r1] compile-flags: --target aarch64-unknown-linux-gnu @@ -99,8 +99,8 @@ //@ [r47] needs-llvm-components: mips //@ [r48] compile-flags: --target mipsel-unknown-linux-musl //@ [r48] needs-llvm-components: mips -//@ [r49] compile-flags: --target nvptx64-nvidia-cuda -//@ [r49] needs-llvm-components: nvptx +//-@ [r49] compile-flags: --target nvptx64-nvidia-cuda [stack protector not supported on CUDA +//- see the test fail-stack-protector-unsupported] //@ [r50] compile-flags: --target powerpc-unknown-linux-gnu //@ [r50] needs-llvm-components: powerpc //@ [r51] compile-flags: --target powerpc64-unknown-linux-gnu @@ -173,7 +173,7 @@ //@ [r84] needs-llvm-components: x86 //@ [r85] compile-flags: --target x86_64-unknown-redox //@ [r85] needs-llvm-components: x86 -//@ compile-flags: -Z stack-protector=all -Z allow-partial-mitigations=stack-protector -Cpanic=abort +//@ compile-flags: -C stack-protector=all -Z allow-partial-mitigations=stack-protector -Cpanic=abort //@ compile-flags: -C opt-level=2 #![crate_type = "lib"] @@ -193,10 +193,6 @@ pub fn foo() { // r7: callq __security_check_cookie // r13: bl __security_check_cookie - // cuda doesn't support stack-smash protection - // r49-NOT: __security_check_cookie - // r49-NOT: __stack_chk_fail - // Other targets do stack checking within the function, and call a failure function on error // r1: __stack_chk_fail // r2: __stack_chk_fail diff --git a/tests/codegen-llvm/stack-protector.rs b/tests/codegen-llvm/stack-protector.rs index 5cd6cf4b0f8b5..8f10d8cb49f79 100644 --- a/tests/codegen-llvm/stack-protector.rs +++ b/tests/codegen-llvm/stack-protector.rs @@ -1,7 +1,11 @@ -//@ revisions: all strong none +// ignore-tidy-file-linelength +//@ revisions: all all-z strong strong-z none strong-c-overrides-z //@ ignore-nvptx64 stack protector not supported -//@ [all] compile-flags: -Z stack-protector=all -Z allow-partial-mitigations=stack-protector -//@ [strong] compile-flags: -Z stack-protector=strong -Z allow-partial-mitigations=stack-protector +//@ [all] compile-flags: -C stack-protector=all -Z allow-partial-mitigations=stack-protector +//@ [all-z] compile-flags: -Z stack-protector=all -Z allow-partial-mitigations=stack-protector +//@ [strong] compile-flags: -C stack-protector=strong -Z allow-partial-mitigations=stack-protector +//@ [strong-z] compile-flags: -Z stack-protector=strong -Z allow-partial-mitigations=stack-protector +//@ [strong-c-overrides-z] compile-flags: -C stack-protector=strong -Z stack-protector=all -Z allow-partial-mitigations=stack-protector #![crate_type = "lib"] @@ -15,12 +19,30 @@ pub fn foo() { // all-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} } // all-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // all-z-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} } + // all-z-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // all-z: attributes #0 = { {{.*}}sspreq {{.*}} } + // all-z-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} } + // all-z-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // strong-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } // strong-NOT: attributes #0 = { {{.*}}ssp {{.*}} } // strong: attributes #0 = { {{.*}}sspstrong {{.*}} } // strong-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } // strong-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // strong-z-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } + // strong-z-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // strong-z: attributes #0 = { {{.*}}sspstrong {{.*}} } + // strong-z-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } + // strong-z-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + + // strong-c-overrides-z-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } + // strong-c-overrides-z-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // strong-c-overrides-z: attributes #0 = { {{.*}}sspstrong {{.*}} } + // strong-c-overrides-z-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } + // strong-c-overrides-z-NOT: attributes #0 = { {{.*}}ssp {{.*}} } + // none-NOT: attributes #0 = { {{.*}}sspreq {{.*}} } // none-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} } // none-NOT: attributes #0 = { {{.*}}ssp {{.*}} } diff --git a/tests/ui/README.md b/tests/ui/README.md index cdebbea240dbf..027a88531f1e9 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -1308,7 +1308,7 @@ Stability attributes used internally by the standard library: `#[stable()]` and **FIXME**: Contains a single test, should likely be rehomed to `tests/ui/abi`. -## `tests/ui/stack-protector/`: `-Z stack-protector` command line flag +## `tests/ui/stack-protector/`: `-C stack-protector` command line flag See [Tracking Issue for stabilizing stack smashing protection (i.e., `-Z stack-protector`) #114903](https://github.com/rust-lang/rust/issues/114903). diff --git a/tests/ui/abi/stack-protector.rs b/tests/ui/abi/stack-protector.rs index ee12b541a3d53..3e593e5398811 100644 --- a/tests/ui/abi/stack-protector.rs +++ b/tests/ui/abi/stack-protector.rs @@ -1,7 +1,7 @@ //@ run-pass //@ only-x86_64-unknown-linux-gnu //@ revisions: ssp no-ssp -//@ [ssp] compile-flags: -Z stack-protector=all -Z allow-partial-mitigations=stack-protector +//@ [ssp] compile-flags: -C stack-protector=all -Z allow-partial-mitigations=stack-protector //@ compile-flags: -C opt-level=2 //@ compile-flags: -g diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-control-flow-guard.control-flow-guard-future-allow-reset-by-mitigation.stderr b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.control-flow-guard-future-allow-reset-by-mitigation.stderr similarity index 100% rename from tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-control-flow-guard.control-flow-guard-future-allow-reset-by-mitigation.stderr rename to tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.control-flow-guard-future-allow-reset-by-mitigation.stderr diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-control-flow-guard.rs b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.rs similarity index 77% rename from tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-control-flow-guard.rs rename to tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.rs index 5d111e87281e4..86f2035d34d91 100644 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-control-flow-guard.rs +++ b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.rs @@ -1,6 +1,5 @@ // ignore-tidy-file-linelength -//@ revisions: control-flow-guard-future-allow-reset-by-mitigation -//@ check-fail +//@ revisions: control-flow-guard-future-allow-reset-by-mitigation stack-protector-future-stable //@ ignore-nvptx64 stack protector is not supported //@ ignore-wasm32-unknown-unknown stack protector is not supported //@ edition:future @@ -8,12 +7,14 @@ // msvc has an extra unwind dependency of std, normalize it in the error messages //@ normalize-stderr: "\b(unwind|libc)\b" -> "unwind/libc" -// put the test for control-flow-guard in its own file since it does not have the future-compat warning, -// and you can't do negative revisions in compiletest +// test for cases with no future compat warning, since the relevant '-C' option is passed. // check that `-C control-flow-guard` overrides the `-Z allow-partial-mitigations=control-flow-guard` (to the default, which is deny at edition=future) //@ [control-flow-guard-future-allow-reset-by-mitigation] compile-flags: -Z unstable-options -Z allow-partial-mitigations=control-flow-guard -C control-flow-guard=on +// same, but for `-C stack-protector` +//@ [stack-protector-future-stable] compile-flags: -Z unstable-options -C stack-protector=all + fn main() {} //~? ERROR that is not compiled with //~? ERROR that is not compiled with diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-deny-reset-by-mitigation.stderr b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.stack-protector-future-stable.stderr similarity index 62% rename from tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-deny-reset-by-mitigation.stderr rename to tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.stack-protector-future-stable.stderr index 29a39a09478bd..cb791558ad1bb 100644 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-deny-reset-by-mitigation.stderr +++ b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error-no-future-compat.stack-protector-future-stable.stderr @@ -2,38 +2,26 @@ error: your program uses the crate `std`, that is not compiled with `stack-prote | = note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - = note: `-D partial-stack-protector` implied by `-D future-incompatible` - = help: to override `-D future-incompatible` add `#[allow(partial_stack_protector)]` error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled | = note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled | = note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled | = note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 error: your program uses the crate `unwind/libc`, that is not compiled with `stack-protector=all` enabled | = note: recompile `unwind/libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 error: aborting due to 5 previous errors diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error.rs b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error.rs index 25a88a08e638e..ff5b78a652806 100644 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error.rs +++ b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-1-error.rs @@ -1,6 +1,5 @@ // ignore-tidy-file-linelength -//@ revisions: stack-protector-future stack-protector-future-explicit-deny stack-protector-future-deny-reset-by-mitigation stack-protector-allow-then-deny stack-protector-but-allow-control-flow-guard stack-protector-future-allow-reset-by-mitigation stack-protector-future-deny-allow-reset-by-mitigation -//@ check-fail +//@ revisions: stack-protector-future stack-protector-future-explicit-deny stack-protector-future-deny-reset-by-mitigation stack-protector-allow-then-deny stack-protector-but-allow-control-flow-guard stack-protector-future-allow-reset-by-mitigation stack-protector-future-deny-allow-reset-by-mitigation //@ compile-flags: -D future-incompatible //@ ignore-nvptx64 stack protector is not supported //@ ignore-wasm32-unknown-unknown stack protector is not supported @@ -10,7 +9,7 @@ //@ normalize-stderr: "\b(unwind|libc)\b" -> "unwind/libc" // test that stack-protector is denied-partial in edition=future -//@ [stack-protector-future] compile-flags: -Z unstable-options -Z stack-protector=all +//@ [stack-protector-future] compile-flags: -Z unstable-options -Z stack-protector=all // same, but with explicit deny //@ [stack-protector-future-explicit-deny] compile-flags: -Z unstable-options -Z stack-protector=all -Z deny-partial-mitigations=stack-protector diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.control-flow-2024-explicit-deny.stderr b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.control-flow-2024-explicit-deny.stderr deleted file mode 100644 index bdb8962a408a7..0000000000000 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.control-flow-2024-explicit-deny.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: your program uses the crate `std`, that is not compiled with `control-flow-guard` enabled - | - = note: recompile `std` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard` - -error: your program uses the crate `core`, that is not compiled with `control-flow-guard` enabled - | - = note: recompile `core` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard` - -error: your program uses the crate `alloc`, that is not compiled with `control-flow-guard` enabled - | - = note: recompile `alloc` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard` - -error: your program uses the crate `compiler_builtins`, that is not compiled with `control-flow-guard` enabled - | - = note: recompile `compiler_builtins` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard` - -error: your program uses the crate `unwind/libc`, that is not compiled with `control-flow-guard` enabled - | - = note: recompile `unwind/libc` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.rs b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.rs deleted file mode 100644 index 38df00d66da88..0000000000000 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.rs +++ /dev/null @@ -1,35 +0,0 @@ -// ignore-tidy-file-linelength -//@ revisions: stack-protector-2024 stack-protector-2024-allow-deny-reset-by-mitigation stack-protector-2024-deny-reset-by-mitigation -//@ check-fail -//@ compile-flags: -D future-incompatible -//@ ignore-nvptx64 stack protector is not supported -//@ ignore-wasm32-unknown-unknown stack protector is not supported -//@ edition: 2024 - -// msvc has an extra unwind dependency of std, normalize it in the error messages -//@ normalize-stderr: "\b(unwind|libc)\b" -> "unwind/libc" - -// check that in edition 2024, it is still possible to explicitly -// disallow partial mitigations (in edition=future, they are -// disallowed by default) - -// check that explicit deny of stack-protector works in edition 2024 -//@ [stack-protector-2024-deny-reset-by-mitigation] compile-flags: -Z deny-partial-mitigations=stack-protector -Z stack-protector=all - -// check that this is the case even if there was an "allow" then a "deny" -//@ [stack-protector-2024-allow-deny-reset-by-mitigation] compile-flags: -Z unstable-options -Z allow-partial-mitigations=stack-protector -Z deny-partial-mitigations=stack-protector -Z stack-protector=all - -// check that stack-protector is partial-denied in edition 2024 -//@ [stack-protector-2024] compile-flags: -Z stack-protector=all - -fn main() {} -//~? ERROR that is not compiled with -//~? ERROR that is not compiled with -//~? ERROR that is not compiled with -//~? ERROR that is not compiled with -//~? ERROR that is not compiled with -//~? WARN this was previously accepted -//~? WARN this was previously accepted -//~? WARN this was previously accepted -//~? WARN this was previously accepted -//~? WARN this was previously accepted diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-allow-deny-reset-by-mitigation.stderr b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-allow-deny-reset-by-mitigation.stderr deleted file mode 100644 index 29a39a09478bd..0000000000000 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024-allow-deny-reset-by-mitigation.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - = note: `-D partial-stack-protector` implied by `-D future-incompatible` - = help: to override `-D future-incompatible` add `#[allow(partial_stack_protector)]` - -error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: your program uses the crate `unwind/libc`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `unwind/libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: aborting due to 5 previous errors - diff --git a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024.stderr b/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024.stderr deleted file mode 100644 index 29a39a09478bd..0000000000000 --- a/tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stack-protector-2024.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - = note: `-D partial-stack-protector` implied by `-D future-incompatible` - = help: to override `-D future-incompatible` add `#[allow(partial_stack_protector)]` - -error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: your program uses the crate `unwind/libc`, that is not compiled with `stack-protector=all` enabled - | - = note: recompile `unwind/libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation partially enabled - = help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector` - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #154613 - -error: aborting due to 5 previous errors - diff --git a/tests/ui/stack-protector/fail-stack-protector-unsupported.all-z.stderr b/tests/ui/stack-protector/fail-stack-protector-unsupported.all-z.stderr new file mode 100644 index 0000000000000..9f2876de057fd --- /dev/null +++ b/tests/ui/stack-protector/fail-stack-protector-unsupported.all-z.stderr @@ -0,0 +1,4 @@ +error: `-C stack-protector=all` is not supported for target nvptx64-nvidia-cuda + +error: aborting due to 1 previous error + diff --git a/tests/ui/stack-protector/fail-stack-protector-unsupported.all.stderr b/tests/ui/stack-protector/fail-stack-protector-unsupported.all.stderr new file mode 100644 index 0000000000000..9f2876de057fd --- /dev/null +++ b/tests/ui/stack-protector/fail-stack-protector-unsupported.all.stderr @@ -0,0 +1,4 @@ +error: `-C stack-protector=all` is not supported for target nvptx64-nvidia-cuda + +error: aborting due to 1 previous error + diff --git a/tests/ui/stack-protector/fail-stack-protector-unsupported.rs b/tests/ui/stack-protector/fail-stack-protector-unsupported.rs new file mode 100644 index 0000000000000..c9eb3560eda42 --- /dev/null +++ b/tests/ui/stack-protector/fail-stack-protector-unsupported.rs @@ -0,0 +1,30 @@ +//@ check-fail +//@ revisions: all strong all-z +//@ compile-flags: --target nvptx64-nvidia-cuda +//@ needs-llvm-components: nvptx +//@ [all] compile-flags: -C stack-protector=all +//@ [strong] compile-flags: -C stack-protector=strong +//@ [all-z] compile-flags: -Z stack-protector=all + +#![crate_type = "lib"] +#![feature(no_core, lang_items)] +#![no_std] +#![no_core] + +#[lang = "pointee_sized"] +pub trait PointeeSized {} + +#[lang = "meta_sized"] +pub trait MetaSized: PointeeSized {} + +#[lang = "sized"] +trait Sized: MetaSized {} + +#[lang = "copy"] +trait Copy {} + +pub fn main(){} + +//[all]~? ERROR `-C stack-protector=all` is not supported for target nvptx64-nvidia-cuda +//[all-z]~? ERROR `-C stack-protector=all` is not supported for target nvptx64-nvidia-cuda +//[strong]~? ERROR `-C stack-protector=strong` is not supported for target nvptx64-nvidia-cuda diff --git a/tests/ui/stack-protector/fail-stack-protector-unsupported.strong.stderr b/tests/ui/stack-protector/fail-stack-protector-unsupported.strong.stderr new file mode 100644 index 0000000000000..a92575e597af8 --- /dev/null +++ b/tests/ui/stack-protector/fail-stack-protector-unsupported.strong.stderr @@ -0,0 +1,4 @@ +error: `-C stack-protector=strong` is not supported for target nvptx64-nvidia-cuda + +error: aborting due to 1 previous error + diff --git a/tests/ui/stack-protector/no-stack-protector-basic.rs b/tests/ui/stack-protector/no-stack-protector-basic.rs index 2e42da5695373..4080b840d80ff 100644 --- a/tests/ui/stack-protector/no-stack-protector-basic.rs +++ b/tests/ui/stack-protector/no-stack-protector-basic.rs @@ -1,5 +1,8 @@ -//@ compile-flags: -Z stack-protector=basic +//@ revisions: stable unstable +//@ [unstable] compile-flags: -Z stack-protector=basic +//@ [stable] compile-flags: -C stack-protector=basic pub fn main(){} -//~? ERROR incorrect value `basic` for unstable option `stack-protector` +//[unstable]~? ERROR incorrect value `basic` for unstable option `stack-protector` +//[stable]~? ERROR incorrect value `basic` for codegen option `stack-protector` diff --git a/tests/ui/stack-protector/no-stack-protector-basic.stable.stderr b/tests/ui/stack-protector/no-stack-protector-basic.stable.stderr new file mode 100644 index 0000000000000..644c3e6a34f2a --- /dev/null +++ b/tests/ui/stack-protector/no-stack-protector-basic.stable.stderr @@ -0,0 +1,2 @@ +error: incorrect value `basic` for codegen option `stack-protector` - one of (`none` (default), `strong`, or `all`) was expected + diff --git a/tests/ui/stack-protector/no-stack-protector-basic.stderr b/tests/ui/stack-protector/no-stack-protector-basic.unstable.stderr similarity index 100% rename from tests/ui/stack-protector/no-stack-protector-basic.stderr rename to tests/ui/stack-protector/no-stack-protector-basic.unstable.stderr diff --git a/tests/ui/stack-protector/warn-stack-protector-unsupported.all.stderr b/tests/ui/stack-protector/warn-stack-protector-unsupported.all.stderr deleted file mode 100644 index 54887715523c1..0000000000000 --- a/tests/ui/stack-protector/warn-stack-protector-unsupported.all.stderr +++ /dev/null @@ -1,4 +0,0 @@ -warning: `-Z stack-protector=all` is not supported for target nvptx64-nvidia-cuda and will be ignored - -warning: 1 warning emitted - diff --git a/tests/ui/stack-protector/warn-stack-protector-unsupported.rs b/tests/ui/stack-protector/warn-stack-protector-unsupported.rs deleted file mode 100644 index c9505fe8b93db..0000000000000 --- a/tests/ui/stack-protector/warn-stack-protector-unsupported.rs +++ /dev/null @@ -1,28 +0,0 @@ -//@ build-pass -//@ revisions: all strong -//@ compile-flags: --target nvptx64-nvidia-cuda -//@ needs-llvm-components: nvptx -//@ [all] compile-flags: -Z stack-protector=all -//@ [strong] compile-flags: -Z stack-protector=strong - -#![crate_type = "lib"] -#![feature(no_core, lang_items)] -#![no_std] -#![no_core] - -#[lang = "pointee_sized"] -pub trait PointeeSized {} - -#[lang = "meta_sized"] -pub trait MetaSized: PointeeSized {} - -#[lang = "sized"] -trait Sized: MetaSized {} - -#[lang = "copy"] -trait Copy {} - -pub fn main(){} - -//[all]~? WARN `-Z stack-protector=all` is not supported for target nvptx64-nvidia-cuda and will be ignored -//[strong]~? WARN `-Z stack-protector=strong` is not supported for target nvptx64-nvidia-cuda and will be ignored diff --git a/tests/ui/stack-protector/warn-stack-protector-unsupported.strong.stderr b/tests/ui/stack-protector/warn-stack-protector-unsupported.strong.stderr deleted file mode 100644 index ccc2f9f2cc5b8..0000000000000 --- a/tests/ui/stack-protector/warn-stack-protector-unsupported.strong.stderr +++ /dev/null @@ -1,4 +0,0 @@ -warning: `-Z stack-protector=strong` is not supported for target nvptx64-nvidia-cuda and will be ignored - -warning: 1 warning emitted -