Skip to content

Commit 465d04a

Browse files
committed
Auto merge of rust-lang#146317 - saethlin:panic=immediate-abort, r=nnethercote
Add panic=immediate-abort MCP: rust-lang/compiler-team#909 This adds a new panic strategy, `-Cpanic=immediate-abort`. This panic strategy essentially just codifies use of `-Zbuild-std-features=panic_immediate_abort`. This PR is intended to just set up infrastructure, and while it will change how the compiler is invoked for users of the feature, there should be no other impacts. In many parts of the compiler, `PanicStrategy::ImmediateAbort` behaves just like `PanicStrategy::Abort`, because actually most parts of the compiler just mean to ask "can this unwind?" so I've added a helper function so we can say `sess.panic_strategy().unwinds()`. The panic and unwind strategies have some level of compatibility, which mostly means that we can pre-compile the sysroot with unwinding panics then the sysroot can be linked with aborting panics later. The immediate-abort strategy is all-or-nothing, enforced by `compiler/rustc_metadata/src/dependency_format.rs` and this is tested for in `tests/ui/panic-runtime/`. We could _technically_ be more compatible with the other panic strategies, but immediately-aborting panics primarily exist for users who want to eliminate all the code size responsible for the panic runtime. I'm open to other use cases if people want to present them, but not right now. This PR is already large. `-Cpanic=immediate-abort` sets both `cfg(panic = "immediate-abort")` _and_ `cfg(panic = "abort")`. bjorn3 pointed out that people may be checking for the abort cfg to ask if panics will unwind, and also the sysroot feature this is replacing used to require `-Cpanic=abort` so this seems like a good back-compat step. At least for the moment. Unclear if this is a good idea indefinitely. I can imagine this being confusing. The changes to the standard library attributes are purely mechanical. Apart from that, I removed an `unsafe` we haven't needed for a while since the `abort` intrinsic became safe, and I've added a helpful diagnostic for people trying to use the old feature. To test that `-Cpanic=immediate-abort` conflicts with other panic strategies, I've beefed up the core-stubs infrastructure a bit. There is now a separate attribute to set flags on it. I've added a test that this produces the desired codegen, called `tests/run-make-cargo/panic-immediate-abort-codegen/` and also a separate run-make-cargo test that checks that we can build a binary.
2 parents b9a2e04 + 8f24436 commit 465d04a

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_middle::mir::mono::Visibility;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_session::config::DebugInfo;
1717
use rustc_span::Symbol;
18+
use rustc_target::spec::RelocModel;
1819
#[cfg(feature = "master")]
1920
use rustc_target::spec::SymbolVisibility;
20-
use rustc_target::spec::{PanicStrategy, RelocModel};
2121

2222
use crate::builder::Builder;
2323
use crate::context::CodegenCx;
@@ -101,7 +101,7 @@ pub fn compile_codegen_unit(
101101
// Instantiate monomorphizations without filling out definitions yet...
102102
let context = new_context(tcx);
103103

104-
if tcx.sess.panic_strategy() == PanicStrategy::Unwind {
104+
if tcx.sess.panic_strategy().unwinds() {
105105
context.add_command_line_option("-fexceptions");
106106
context.add_driver_option("-fexceptions");
107107
}

src/intrinsic/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_middle::ty::layout::LayoutOf;
2929
use rustc_middle::ty::{self, Instance, Ty};
3030
use rustc_span::{Span, Symbol, sym};
3131
use rustc_target::callconv::{ArgAbi, PassMode};
32-
use rustc_target::spec::PanicStrategy;
3332

3433
#[cfg(feature = "master")]
3534
use crate::abi::FnAbiGccExt;
@@ -1334,7 +1333,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
13341333
_catch_func: RValue<'gcc>,
13351334
dest: PlaceRef<'tcx, RValue<'gcc>>,
13361335
) {
1337-
if bx.sess().panic_strategy() == PanicStrategy::Abort {
1336+
if !bx.sess().panic_strategy().unwinds() {
13381337
bx.call(bx.type_void(), None, None, try_func, &[data], None, None);
13391338
// Return 0 unconditionally from the intrinsic call;
13401339
// we can never unwind.

0 commit comments

Comments
 (0)