diff --git a/config.example.toml b/config.example.toml index f1ea6bac3ca16..d86c02a104691 100644 --- a/config.example.toml +++ b/config.example.toml @@ -504,6 +504,9 @@ # Defaults to rust.overflow-checks value #overflow-checks-std = rust.overflow-checks (boolean) +# The panic strategy used for all compiler invocations +#panic-strategy = "unwind" + # Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. # `0` - no debug info # `1` - line tables only - sufficient to generate backtraces that include line diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 4e20babc55a68..43eaa36c7bb63 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -2135,6 +2135,10 @@ impl<'a> Builder<'a> { cargo.env("RUSTFLAGS", &rustc_args.join(" ")); } + if matches!(self.config.rust_panic_strategy, crate::PanicStrategy::Abort) { + rustflags.arg("-Cpanic=abort"); + } + Cargo { command: cargo, rustflags, rustdocflags, hostflags, allow_features } } diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 3ac3e54563148..14e1290767f76 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -105,6 +105,14 @@ impl Display for DebuginfoLevel { } } +#[derive(Clone, Copy, Debug, Default, PartialEq, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum PanicStrategy { + #[default] + Unwind, + Abort, +} + /// LLD in bootstrap works like this: /// - Self-contained lld: use `rust-lld` from the compiler's sysroot /// - External: use an external `lld` binary @@ -272,6 +280,7 @@ pub struct Config { pub rust_profile_generate: Option, pub rust_lto: RustcLto, pub rust_validate_mir_opts: Option, + pub rust_panic_strategy: PanicStrategy, pub llvm_profile_use: Option, pub llvm_profile_generate: bool, pub llvm_libunwind_default: Option, @@ -1111,6 +1120,7 @@ define_config! { download_rustc: Option = "download-rustc", lto: Option = "lto", validate_mir_opts: Option = "validate-mir-opts", + panic_strategy: Option = "panic-strategy", } } @@ -1562,6 +1572,7 @@ impl Config { stack_protector, strip, lld_mode, + panic_strategy, } = rust; set(&mut config.channel, channel); @@ -1594,6 +1605,7 @@ impl Config { debuginfo_level_std = debuginfo_level_std_toml; debuginfo_level_tools = debuginfo_level_tools_toml; debuginfo_level_tests = debuginfo_level_tests_toml; + set(&mut config.rust_panic_strategy, panic_strategy); config.rust_split_debuginfo = split_debuginfo .as_deref() diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 871318de5955e..dae1402e84ee6 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -16,6 +16,7 @@ //! More documentation can be found in each respective module below, and you can //! also check out the `src/bootstrap/README.md` file for more information. +use core::config::PanicStrategy; use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet}; use std::env; @@ -708,13 +709,19 @@ impl Build { /// Gets the space-separated set of activated features for the standard /// library. fn std_features(&self, target: TargetSelection) -> String { - let mut features = " panic-unwind".to_string(); + let mut features = match self.config.rust_panic_strategy { + PanicStrategy::Abort => String::new(), + _ => { + let mut features = " panic-unwind".to_string(); + match self.config.llvm_libunwind(target) { + LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"), + LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"), + LlvmLibunwind::No => {} + } + features + } + }; - match self.config.llvm_libunwind(target) { - LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"), - LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"), - LlvmLibunwind::No => {} - } if self.config.backtrace { features.push_str(" backtrace"); }