about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2020-05-21 20:04:57 -0700
committerEric Huss <eric@huss.org>2020-07-15 08:38:11 -0700
commit9e58908e27d47683800ab0869a98502a6f485a62 (patch)
tree850c5201cbe8561ea56b0d19bdc1a56b99b0daa6 /src
parent432b4c14aad49f27bad3c59bb3bc85595e21a71b (diff)
downloadrust-9e58908e27d47683800ab0869a98502a6f485a62.tar.gz
rust-9e58908e27d47683800ab0869a98502a6f485a62.zip
Use cfg_if in libpanic_abort.
This allows setting a default abort using the core intrinsic.
Diffstat (limited to 'src')
-rw-r--r--src/libpanic_abort/Cargo.toml1
-rw-r--r--src/libpanic_abort/lib.rs34
2 files changed, 19 insertions, 16 deletions
diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml
index 2bee0b716c7..dc385022440 100644
--- a/src/libpanic_abort/Cargo.toml
+++ b/src/libpanic_abort/Cargo.toml
@@ -11,6 +11,7 @@ bench = false
 doc = false
 
 [dependencies]
+cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
 core = { path = "../libcore" }
 libc = { version = "0.2", default-features = false }
 compiler_builtins = "0.1.0"
diff --git a/src/libpanic_abort/lib.rs b/src/libpanic_abort/lib.rs
index 27056d5f934..497f40cafd3 100644
--- a/src/libpanic_abort/lib.rs
+++ b/src/libpanic_abort/lib.rs
@@ -40,23 +40,25 @@ 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 {
     abort();
 
-    #[cfg(any(unix, target_os = "cloudabi"))]
-    unsafe fn abort() -> ! {
-        libc::abort();
-    }
-
-    #[cfg(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten"))))]
-    unsafe fn abort() -> ! {
-        core::intrinsics::abort();
-    }
-
-    #[cfg(any(target_os = "hermit", all(target_vendor = "fortanix", target_env = "sgx")))]
-    unsafe fn abort() -> ! {
-        // call std::sys::abort_internal
-        extern "C" {
-            pub fn __rust_abort() -> !;
+    cfg_if::cfg_if! {
+        if #[cfg(any(unix, target_os = "cloudabi"))] {
+            unsafe fn abort() -> ! {
+                libc::abort();
+            }
+        } else if #[cfg(any(target_os = "hermit",
+                        all(target_vendor = "fortanix", target_env = "sgx")))] {
+            unsafe fn abort() -> ! {
+                // call std::sys::abort_internal
+                extern "C" {
+                    pub fn __rust_abort() -> !;
+                }
+                __rust_abort();
+            }
+        } else {
+            unsafe fn abort() -> ! {
+                core::intrinsics::abort();
+            }
         }
-        __rust_abort();
     }
 }