1#![no_std]
2#![unstable(feature = "panic_unwind", issue = "32837")]
3#![feature(link_cfg)]
4#![feature(staged_api)]
5#![feature(c_unwind)]
6#![feature(strict_provenance)]
7#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))]
8#![cfg_attr(not(target_env = "msvc"), feature(libc))]
9#![cfg_attr(
10 all(target_family = "wasm", not(target_os = "emscripten")),
11 feature(link_llvm_intrinsics)
12)]
13#![allow(internal_features)]
14
15// Force libc to be included even if unused. This is required by many platforms.
16#[cfg(not(all(windows, target_env = "msvc")))]
17extern crate libc as _;
18
19cfg_if::cfg_if! {
20 if #[cfg(target_env = "msvc")] {
21 // Windows MSVC no extra unwinder support needed
22 } else if #[cfg(any(
23 target_os = "l4re",
24 target_os = "none",
25 target_os = "espidf",
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")]
55cfg_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 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 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 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")]
75cfg_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 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 extern "C" {}
85 }
86}
87
88#[cfg(target_os = "android")]
89cfg_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 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")))]
102extern "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")))]
114extern "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")))]
123extern "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")))]
128extern "C" {}
129
130#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
131#[link(name = "unwind", kind = "static", modifiers = "-bundle")]
132extern "C" {}
133
134#[cfg(target_os = "netbsd")]
135#[link(name = "gcc_s")]
136extern "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")))]
142extern "C" {}
143
144#[cfg(all(target_os = "openbsd", target_arch = "sparc64"))]
145#[link(name = "gcc")]
146extern "C" {}
147
148#[cfg(all(target_os = "openbsd", not(target_arch = "sparc64")))]
149#[link(name = "c++abi")]
150extern "C" {}
151
152#[cfg(any(target_os = "solaris", target_os = "illumos"))]
153#[link(name = "gcc_s")]
154extern "C" {}
155
156#[cfg(target_os = "dragonfly")]
157#[link(name = "gcc_pic")]
158extern "C" {}
159
160#[cfg(target_os = "haiku")]
161#[link(name = "gcc_s")]
162extern "C" {}
163
164#[cfg(target_os = "aix")]
165#[link(name = "unwind")]
166extern "C" {}
167
168#[cfg(target_os = "nto")]
169#[link(name = "gcc_s")]
170extern "C" {}
171
172#[cfg(target_os = "hurd")]
173#[link(name = "gcc_s")]
174extern "C" {}
175