Use cfg_if in libpanic_abort.

This allows setting a default abort using the core intrinsic.
This commit is contained in:
Eric Huss 2020-05-21 20:04:57 -07:00
parent 432b4c14aa
commit 9e58908e27
3 changed files with 20 additions and 16 deletions

View file

@ -2056,6 +2056,7 @@ dependencies = [
name = "panic_abort" name = "panic_abort"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"cfg-if",
"compiler_builtins", "compiler_builtins",
"core", "core",
"libc", "libc",

View file

@ -11,6 +11,7 @@ bench = false
doc = false doc = false
[dependencies] [dependencies]
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
core = { path = "../libcore" } core = { path = "../libcore" }
libc = { version = "0.2", default-features = false } libc = { version = "0.2", default-features = false }
compiler_builtins = "0.1.0" compiler_builtins = "0.1.0"

View file

@ -40,17 +40,13 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen
pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 { pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 {
abort(); abort();
#[cfg(any(unix, target_os = "cloudabi"))] cfg_if::cfg_if! {
if #[cfg(any(unix, target_os = "cloudabi"))] {
unsafe fn abort() -> ! { unsafe fn abort() -> ! {
libc::abort(); libc::abort();
} }
} else if #[cfg(any(target_os = "hermit",
#[cfg(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten"))))] all(target_vendor = "fortanix", target_env = "sgx")))] {
unsafe fn abort() -> ! {
core::intrinsics::abort();
}
#[cfg(any(target_os = "hermit", all(target_vendor = "fortanix", target_env = "sgx")))]
unsafe fn abort() -> ! { unsafe fn abort() -> ! {
// call std::sys::abort_internal // call std::sys::abort_internal
extern "C" { extern "C" {
@ -58,6 +54,12 @@ pub unsafe extern "C" fn __rust_start_panic(_payload: usize) -> u32 {
} }
__rust_abort(); __rust_abort();
} }
} else {
unsafe fn abort() -> ! {
core::intrinsics::abort();
}
}
}
} }
// This... is a bit of an oddity. The tl;dr; is that this is required to link // This... is a bit of an oddity. The tl;dr; is that this is required to link