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