From 88b79e8959824d47282fce91293b76f57e0db463 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:47:27 +0000 Subject: [PATCH] Make rustc implicitly use panic=abort for the panic_abort crate The panic_abort crate must be compiled with panic=abort, but cargo doesn't allow setting the panic strategy for a single crate. Bootstrap handles this in its rustc wrapper, but for example the build systems of cg_clif and cg_gcc don't use a rustc wrapper, so they would either need to add one or be unable to build a sysroot suitable for both panic=abort and panic=unwind (as is currently the case). --- compiler/rustc_session/src/session.rs | 5 +++++ src/bootstrap/src/bin/rustc.rs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 010ae42c2802d..60a3c4d889204 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -704,6 +704,11 @@ impl Session { /// Returns the panic strategy for this compile session. If the user explicitly selected one /// using '-C panic', use that, otherwise use the panic strategy defined by the target. pub fn panic_strategy(&self) -> PanicStrategy { + if self.opts.crate_name.as_deref() == Some("panic_abort") { + // The panic_abort crate must always be compiled with panic=abort. + return PanicStrategy::Abort; + } + self.opts.cg.panic.unwrap_or(self.target.panic_strategy) } diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index d8cae02456c0e..df4f3bf83ee3a 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -161,7 +161,8 @@ fn main() { // This... is a bit of a hack how we detect this. Ideally this // information should be encoded in the crate I guess? Would likely // require an RFC amendment to RFC 1513, however. - if crate_name == Some("panic_abort") { + // cfg(not(bootstrap)) + if crate_name == Some("panic_abort") && stage == "0" { cmd.arg("-C").arg("panic=abort"); }