]> git.lizzy.rs Git - rust.git/blob - library/unwind/src/lib.rs
Rollup merge of #107459 - tshepang:cosistency, r=WaffleLapkin
[rust.git] / library / unwind / src / lib.rs
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 #[cfg(target_os = "android")]
58 cfg_if::cfg_if! {
59     if #[cfg(feature = "llvm-libunwind")] {
60         compile_error!("`llvm-libunwind` is not supported for Android targets");
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 = "gcc", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
67         #[link(name = "gcc", cfg(not(target_feature = "crt-static")))]
68         extern "C" {}
69     }
70 }
71 // Android's unwinding library depends on dl_iterate_phdr in `libdl`.
72 #[cfg(target_os = "android")]
73 #[link(name = "dl", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
74 #[link(name = "dl", cfg(not(target_feature = "crt-static")))]
75 extern "C" {}
76
77 // When building with crt-static, we get `gcc_eh` from the `libc` crate, since
78 // glibc needs it, and needs it listed later on the linker command line. We
79 // don't want to duplicate it here.
80 #[cfg(all(
81     target_os = "linux",
82     any(target_env = "gnu", target_env = "uclibc"),
83     not(feature = "llvm-libunwind"),
84     not(feature = "system-llvm-libunwind")
85 ))]
86 #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
87 extern "C" {}
88
89 #[cfg(all(
90     target_os = "linux",
91     any(target_env = "gnu", target_env = "uclibc"),
92     not(feature = "llvm-libunwind"),
93     feature = "system-llvm-libunwind"
94 ))]
95 #[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
96 extern "C" {}
97
98 #[cfg(target_os = "redox")]
99 #[link(name = "gcc_eh", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
100 #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
101 extern "C" {}
102
103 #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
104 #[link(name = "unwind", kind = "static", modifiers = "-bundle")]
105 extern "C" {}
106
107 #[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
108 #[link(name = "gcc_s")]
109 extern "C" {}
110
111 #[cfg(all(target_os = "openbsd", target_arch = "sparc64"))]
112 #[link(name = "gcc")]
113 extern "C" {}
114
115 #[cfg(all(target_os = "openbsd", not(target_arch = "sparc64")))]
116 #[link(name = "c++abi")]
117 extern "C" {}
118
119 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
120 #[link(name = "gcc_s")]
121 extern "C" {}
122
123 #[cfg(target_os = "dragonfly")]
124 #[link(name = "gcc_pic")]
125 extern "C" {}
126
127 #[cfg(target_os = "haiku")]
128 #[link(name = "gcc_s")]
129 extern "C" {}