Skip to content

Commit 16b9a68

Browse files
Rollup merge of #146118 - RalfJung:miri-abort, r=joboet
improve process::abort rendering in Miri backtraces Also, avoid using the `sys` function directly in the panic machinery -- that seems like an unnecessary layering violation.
2 parents 0e203c4 + a6c0519 commit 16b9a68

28 files changed

+54
-90
lines changed

library/std/src/panicking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ fn panic_with_hook(
819819
rtprintpanic!("aborting due to panic at {location}:\n{payload}\n");
820820
}
821821
}
822-
crate::sys::abort_internal();
822+
crate::process::abort();
823823
}
824824

825825
match *HOOK.read().unwrap_or_else(PoisonError::into_inner) {
@@ -853,7 +853,7 @@ fn panic_with_hook(
853853
// through a nounwind function (e.g. extern "C") then we cannot continue
854854
// unwinding and have to abort immediately.
855855
rtprintpanic!("thread caused non-unwinding panic. aborting.\n");
856-
crate::sys::abort_internal();
856+
crate::process::abort();
857857
}
858858

859859
rust_panic(payload)

library/std/src/process.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,7 @@ pub fn exit(code: i32) -> ! {
24952495
#[stable(feature = "process_abort", since = "1.17.0")]
24962496
#[cold]
24972497
#[cfg_attr(not(test), rustc_diagnostic_item = "process_abort")]
2498+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
24982499
pub fn abort() -> ! {
24992500
crate::sys::abort_internal();
25002501
}

library/std/src/sys/pal/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
364364
// multithreaded C program. It is much less severe for Rust, because Rust
365365
// stdlib doesn't use libc stdio buffering. In a typical Rust program, which
366366
// does not use C stdio, even a buggy libc::abort() is, in fact, safe.
367+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
367368
pub fn abort_internal() -> ! {
368369
unsafe { libc::abort() }
369370
}

library/std/src/sys/pal/windows/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ pub fn abort_internal() -> ! {
356356
}
357357

358358
#[cfg(miri)]
359+
#[track_caller] // even without panics, this helps for Miri backtraces
359360
pub fn abort_internal() -> ! {
360361
crate::intrinsics::abort();
361362
}

src/tools/miri/tests/fail/alloc/alloc_error_handler.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@error-in-other-file: aborted
2-
//@normalize-stderr-test: "\|.*::abort\(\).*" -> "| ABORT()"
3-
//@normalize-stderr-test: "\| +\^+" -> "| ^"
42
#![feature(allocator_api)]
53

64
use std::alloc::*;

src/tools/miri/tests/fail/alloc/alloc_error_handler.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
memory allocation of 4 bytes failed
22
error: abnormal termination: the program aborted execution
3-
--> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
3+
--> RUSTLIB/std/src/alloc.rs:LL:CC
44
|
5-
LL | ABORT()
6-
| ^ abnormal termination occurred here
5+
LL | crate::process::abort()
6+
| ^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
77
|
88
= note: BACKTRACE:
9-
= note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
10-
= note: inside `std::process::abort` at RUSTLIB/std/src/process.rs:LL:CC
119
= note: inside `std::alloc::rust_oom` at RUSTLIB/std/src/alloc.rs:LL:CC
1210
= note: inside `std::alloc::_::__rg_oom` at RUSTLIB/std/src/alloc.rs:LL:CC
1311
= note: inside `std::alloc::handle_alloc_error::rt_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC
@@ -16,7 +14,7 @@ note: inside `main`
1614
--> tests/fail/alloc/alloc_error_handler.rs:LL:CC
1715
|
1816
LL | handle_alloc_error(Layout::for_value(&0));
19-
| ^
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2018

2119
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
2220

src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ panic in a function that cannot unwind
99
stack backtrace:
1010
thread caused non-unwinding panic. aborting.
1111
error: abnormal termination: the program aborted execution
12-
--> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
12+
--> RUSTLIB/std/src/panicking.rs:LL:CC
1313
|
14-
LL | ABORT()
15-
| ^ abnormal termination occurred here
14+
LL | crate::process::abort();
15+
| ^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
1616
|
1717
= note: BACKTRACE:
18-
= note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
1918
= note: inside `std::panicking::panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
2019
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
2120
= note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC
@@ -33,7 +32,7 @@ note: inside `main`
3332
--> tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC
3433
|
3534
LL | unsafe { nounwind() }
36-
| ^
35+
| ^^^^^^^^^^
3736

3837
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
3938

src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ panic in a function that cannot unwind
99
stack backtrace:
1010
thread caused non-unwinding panic. aborting.
1111
error: abnormal termination: the program aborted execution
12-
--> RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
12+
--> RUSTLIB/std/src/panicking.rs:LL:CC
1313
|
14-
LL | ABORT()
15-
| ^ abnormal termination occurred here
14+
LL | crate::process::abort();
15+
| ^^^^^^^^^^^^^^^^^^^^^^^ abnormal termination occurred here
1616
|
1717
= note: BACKTRACE:
18-
= note: inside `std::sys::pal::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/pal/PLATFORM/mod.rs:LL:CC
1918
= note: inside `std::panicking::panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
2019
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
2120
= note: inside `std::sys::backtrace::__rust_end_short_backtrace::<{closure@std::panicking::panic_handler::{closure#0}}, !>` at RUSTLIB/std/src/sys/backtrace.rs:LL:CC
@@ -33,7 +32,7 @@ note: inside `main`
3332
--> tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC
3433
|
3534
LL | unsafe { nounwind() }
36-
| ^
35+
| ^^^^^^^^^^
3736

3837
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
3938

src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ error: Undefined Behavior: unwinding past a stack frame that does not allow unwi
77
--> tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC
88
|
99
LL | unsafe { nounwind() }
10-
| ^ Undefined Behavior occurred here
10+
| ^^^^^^^^^^ Undefined Behavior occurred here
1111
|
1212
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1313
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/function_calls/exported_symbol_bad_unwind2.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@revisions: extern_block definition both
2-
//@normalize-stderr-test: "\|.*::abort\(\).*" -> "| ABORT()"
3-
//@normalize-stderr-test: "\| +\^+" -> "| ^"
42
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
53
//@normalize-stderr-test: "\n +at [^\n]+" -> ""
64
//@[definition,both]error-in-other-file: aborted execution

0 commit comments

Comments
 (0)