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