Skip to content

Commit de250e5

Browse files
committed
Use libc::abort, not intrinsics::abort, in rtabort!
intrinsics::abort compiles down to an illegal instruction, which on Unix-like platforms causes the process to be killed with SIGILL. A more appropriate way to kill the process would be SIGABRT; this indicates better that the runtime has explicitly aborted, rather than some kind of compiler bug or architecture mismatch that SIGILL might indicate. For rtassert!, replace this with libc::abort. libc::abort raises SIGABRT, but is defined to do so in such a way that it will terminate the process even if SIGABRT is currently masked or caught by a signal handler that returns. On non-Unix platforms, retain the existing behavior. On Windows we prefer to avoid depending on the C runtime, and we need a fallback for any other platforms that may be defined. An alternative on Windows would be to call TerminateProcess, but this seems less essential than switching to using SIGABRT on Unix-like platforms, where it is common for the process-killing signal to be printed out or logged. This is a [breaking-change] for any code that depends on the exact signal raised to abort a process via rtabort! cc rust-lang#31273 cc rust-lang#31333
1 parent be2ffdd commit de250e5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/libstd/sys/common/util.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use env;
1212
use fmt;
13-
use intrinsics;
1413
use io::prelude::*;
1514
use sync::atomic::{self, Ordering};
1615
use sys::stdio::Stderr;
@@ -34,7 +33,16 @@ pub fn dumb_print(args: fmt::Arguments) {
3433
let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
3534
}
3635

36+
#[cfg(unix)]
3737
pub fn abort(args: fmt::Arguments) -> ! {
38+
use libc;
39+
dumb_print(format_args!("fatal runtime error: {}\n", args));
40+
unsafe { libc::abort(); }
41+
}
42+
43+
#[cfg(not(unix))]
44+
pub fn abort(args: fmt::Arguments) -> ! {
45+
use intrinsics;
3846
dumb_print(format_args!("fatal runtime error: {}\n", args));
3947
unsafe { intrinsics::abort(); }
4048
}

src/test/run-pass/out-of-stack.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ fn check_status(status: std::process::ExitStatus)
4646
use std::os::unix::process::ExitStatusExt;
4747

4848
assert!(!status.success());
49-
assert!(status.signal() != Some(libc::SIGSEGV)
50-
&& status.signal() != Some(libc::SIGBUS));
49+
assert_eq!(status.signal(), Some(libc::SIGABRT));
5150
}
5251

5352
#[cfg(not(unix))]

0 commit comments

Comments
 (0)