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