| 1 | #![no_std ] |
| 2 | #![unstable (feature = "panic_unwind" , issue = "32837" )] |
| 3 | #![feature (cfg_emscripten_wasm_eh)] |
| 4 | #![feature (link_cfg)] |
| 5 | #![feature (staged_api)] |
| 6 | #![cfg_attr (not(target_env = "msvc" ), feature(libc))] |
| 7 | #![cfg_attr ( |
| 8 | all(target_family = "wasm" , any(not(target_os = "emscripten" ), emscripten_wasm_eh)), |
| 9 | feature(simd_wasm64, wasm_exception_handling_intrinsics) |
| 10 | )] |
| 11 | #![allow (internal_features)] |
| 12 | #![deny (unsafe_op_in_unsafe_fn)] |
| 13 | |
| 14 | // Force libc to be included even if unused. This is required by many platforms. |
| 15 | #[cfg (not(all(windows, target_env = "msvc" )))] |
| 16 | extern crate libc as _; |
| 17 | |
| 18 | cfg_if::cfg_if! { |
| 19 | if #[cfg(target_env = "msvc" )] { |
| 20 | // Windows MSVC no extra unwinder support needed |
| 21 | } else if #[cfg(any( |
| 22 | target_os = "l4re" , |
| 23 | target_os = "none" , |
| 24 | target_os = "espidf" , |
| 25 | target_os = "nuttx" , |
| 26 | ))] { |
| 27 | // These "unix" family members do not have unwinder. |
| 28 | } else if #[cfg(any( |
| 29 | unix, |
| 30 | windows, |
| 31 | target_os = "psp" , |
| 32 | target_os = "solid_asp3" , |
| 33 | all(target_vendor = "fortanix" , target_env = "sgx" ), |
| 34 | ))] { |
| 35 | mod libunwind; |
| 36 | pub use libunwind::*; |
| 37 | } else if #[cfg(target_os = "xous" )] { |
| 38 | mod unwinding; |
| 39 | pub use unwinding::*; |
| 40 | } else if #[cfg(target_family = "wasm" )] { |
| 41 | mod wasm; |
| 42 | pub use wasm::*; |
| 43 | } else { |
| 44 | // no unwinder on the system! |
| 45 | // - os=none ("bare metal" targets) |
| 46 | // - os=hermit |
| 47 | // - os=uefi |
| 48 | // - os=cuda |
| 49 | // - nvptx64-nvidia-cuda |
| 50 | // - Any new targets not listed above. |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | #[cfg (target_env = "musl" )] |
| 55 | cfg_if::cfg_if! { |
| 56 | if #[cfg(all(feature = "llvm-libunwind" , feature = "system-llvm-libunwind" ))] { |
| 57 | compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time" ); |
| 58 | } else if #[cfg(feature = "llvm-libunwind" )] { |
| 59 | #[link(name = "unwind" , kind = "static" , modifiers = "-bundle" )] |
| 60 | unsafe extern "C" {} |
| 61 | } else if #[cfg(feature = "system-llvm-libunwind" )] { |
| 62 | #[link(name = "unwind" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 63 | #[link(name = "unwind" , cfg(not(target_feature = "crt-static" )))] |
| 64 | unsafe extern "C" {} |
| 65 | } else { |
| 66 | #[link(name = "unwind" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 67 | #[link(name = "gcc_s" , cfg(not(target_feature = "crt-static" )))] |
| 68 | unsafe extern "C" {} |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // This is the same as musl except that we default to using the system libunwind |
| 73 | // instead of libgcc. |
| 74 | #[cfg (target_env = "ohos" )] |
| 75 | cfg_if::cfg_if! { |
| 76 | if #[cfg(all(feature = "llvm-libunwind" , feature = "system-llvm-libunwind" ))] { |
| 77 | compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time" ); |
| 78 | } else if #[cfg(feature = "llvm-libunwind" )] { |
| 79 | #[link(name = "unwind" , kind = "static" , modifiers = "-bundle" )] |
| 80 | unsafe extern "C" {} |
| 81 | } else { |
| 82 | #[link(name = "unwind" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 83 | #[link(name = "unwind" , cfg(not(target_feature = "crt-static" )))] |
| 84 | unsafe extern "C" {} |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | #[cfg (target_os = "android" )] |
| 89 | cfg_if::cfg_if! { |
| 90 | if #[cfg(feature = "llvm-libunwind" )] { |
| 91 | compile_error!("`llvm-libunwind` is not supported for Android targets" ); |
| 92 | } else { |
| 93 | #[link(name = "unwind" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 94 | #[link(name = "unwind" , cfg(not(target_feature = "crt-static" )))] |
| 95 | unsafe extern "C" {} |
| 96 | } |
| 97 | } |
| 98 | // Android's unwinding library depends on dl_iterate_phdr in `libdl`. |
| 99 | #[cfg (target_os = "android" )] |
| 100 | #[link (name = "dl" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 101 | #[link (name = "dl" , cfg(not(target_feature = "crt-static" )))] |
| 102 | unsafe extern "C" {} |
| 103 | |
| 104 | // When building with crt-static, we get `gcc_eh` from the `libc` crate, since |
| 105 | // glibc needs it, and needs it listed later on the linker command line. We |
| 106 | // don't want to duplicate it here. |
| 107 | #[cfg (all( |
| 108 | target_os = "linux" , |
| 109 | any(target_env = "gnu" , target_env = "uclibc" ), |
| 110 | not(feature = "llvm-libunwind" ), |
| 111 | not(feature = "system-llvm-libunwind" ) |
| 112 | ))] |
| 113 | #[link (name = "gcc_s" , cfg(not(target_feature = "crt-static" )))] |
| 114 | unsafe extern "C" {} |
| 115 | |
| 116 | #[cfg (all( |
| 117 | target_os = "linux" , |
| 118 | any(target_env = "gnu" , target_env = "uclibc" ), |
| 119 | not(feature = "llvm-libunwind" ), |
| 120 | feature = "system-llvm-libunwind" |
| 121 | ))] |
| 122 | #[link (name = "unwind" , cfg(not(target_feature = "crt-static" )))] |
| 123 | unsafe extern "C" {} |
| 124 | |
| 125 | #[cfg (target_os = "redox" )] |
| 126 | #[link (name = "gcc_eh" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 127 | #[link (name = "gcc_s" , cfg(not(target_feature = "crt-static" )))] |
| 128 | unsafe extern "C" {} |
| 129 | |
| 130 | #[cfg (all(target_vendor = "fortanix" , target_env = "sgx" ))] |
| 131 | #[link (name = "unwind" , kind = "static" , modifiers = "-bundle" )] |
| 132 | unsafe extern "C" {} |
| 133 | |
| 134 | #[cfg (target_os = "netbsd" )] |
| 135 | #[link (name = "gcc_s" )] |
| 136 | unsafe extern "C" {} |
| 137 | |
| 138 | #[cfg (target_os = "freebsd" )] |
| 139 | #[link (name = "gcc" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 140 | #[link (name = "gcc_eh" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 141 | #[link (name = "gcc_s" , cfg(not(target_feature = "crt-static" )))] |
| 142 | unsafe extern "C" {} |
| 143 | |
| 144 | #[cfg (all(target_os = "openbsd" , target_arch = "sparc64" ))] |
| 145 | #[link (name = "gcc" )] |
| 146 | unsafe extern "C" {} |
| 147 | |
| 148 | #[cfg (all(target_os = "openbsd" , not(target_arch = "sparc64" )))] |
| 149 | #[link (name = "c++abi" )] |
| 150 | unsafe extern "C" {} |
| 151 | |
| 152 | #[cfg (any(target_os = "solaris" , target_os = "illumos" ))] |
| 153 | #[link (name = "gcc_s" )] |
| 154 | unsafe extern "C" {} |
| 155 | |
| 156 | #[cfg (target_os = "dragonfly" )] |
| 157 | #[link (name = "gcc_pic" )] |
| 158 | unsafe extern "C" {} |
| 159 | |
| 160 | #[cfg (target_os = "haiku" )] |
| 161 | #[link (name = "gcc_s" )] |
| 162 | unsafe extern "C" {} |
| 163 | |
| 164 | #[cfg (target_os = "aix" )] |
| 165 | #[link (name = "unwind" )] |
| 166 | unsafe extern "C" {} |
| 167 | |
| 168 | #[cfg (target_os = "nto" )] |
| 169 | cfg_if::cfg_if! { |
| 170 | if #[cfg(target_env = "nto70" )] { |
| 171 | #[link(name = "gcc" )] |
| 172 | unsafe extern "C" {} |
| 173 | } else { |
| 174 | #[link(name = "gcc_s" )] |
| 175 | unsafe extern "C" {} |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | #[cfg (target_os = "hurd" )] |
| 180 | #[link (name = "gcc_s" )] |
| 181 | unsafe extern "C" {} |
| 182 | |
| 183 | #[cfg (all(target_os = "windows" , target_env = "gnu" , target_abi = "llvm" ))] |
| 184 | #[link (name = "unwind" , kind = "static" , modifiers = "-bundle" , cfg(target_feature = "crt-static" ))] |
| 185 | #[link (name = "unwind" , cfg(not(target_feature = "crt-static" )))] |
| 186 | unsafe extern "C" {} |
| 187 | |