Skip to content

Commit 88b79e8

Browse files
committed
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).
1 parent 7f69523 commit 88b79e8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_session/src/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,11 @@ impl Session {
704704
/// Returns the panic strategy for this compile session. If the user explicitly selected one
705705
/// using '-C panic', use that, otherwise use the panic strategy defined by the target.
706706
pub fn panic_strategy(&self) -> PanicStrategy {
707+
if self.opts.crate_name.as_deref() == Some("panic_abort") {
708+
// The panic_abort crate must always be compiled with panic=abort.
709+
return PanicStrategy::Abort;
710+
}
711+
707712
self.opts.cg.panic.unwrap_or(self.target.panic_strategy)
708713
}
709714

src/bootstrap/src/bin/rustc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ fn main() {
161161
// This... is a bit of a hack how we detect this. Ideally this
162162
// information should be encoded in the crate I guess? Would likely
163163
// require an RFC amendment to RFC 1513, however.
164-
if crate_name == Some("panic_abort") {
164+
// cfg(not(bootstrap))
165+
if crate_name == Some("panic_abort") && stage == "0" {
165166
cmd.arg("-C").arg("panic=abort");
166167
}
167168

0 commit comments

Comments
 (0)