]> git.lizzy.rs Git - rust.git/blob - library/unwind/src/lib.rs
Rollup merge of #100396 - chenyukang:fix-100394, r=petrochenkov
[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         // Note this also matches x86_64-unknown-none-linuxkernel.
19     } else if #[cfg(any(
20         unix,
21         windows,
22         target_os = "psp",
23         target_os = "solid_asp3",
24         all(target_vendor = "fortanix", target_env = "sgx"),
25     ))] {
26         mod libunwind;
27         pub use libunwind::*;
28     } else {
29         // no unwinder on the system!
30         // - wasm32 (not emscripten, which is "unix" family)
31         // - os=none ("bare metal" targets)
32         // - os=hermit
33         // - os=uefi
34         // - os=cuda
35         // - nvptx64-nvidia-cuda
36         // - Any new targets not listed above.
37     }
38 }
39
40 #[cfg(target_env = "musl")]
41 cfg_if::cfg_if! {
42     if #[cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind"))] {
43         compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time");
44     } else if #[cfg(feature = "llvm-libunwind")] {
45         #[link(name = "unwind", kind = "static", modifiers = "-bundle")]
46         extern "C" {}
47     } else if #[cfg(feature = "system-llvm-libunwind")] {
48         #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
49         #[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
50         extern "C" {}
51     } else {
52         #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
53         #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
54         extern "C" {}
55     }
56 }
57
58 #[cfg(target_os = "android")]
59 cfg_if::cfg_if! {
60     if #[cfg(feature = "llvm-libunwind")] {
61         compile_error!("`llvm-libunwind` is not supported for Android targets");
62     } else if #[cfg(feature = "system-llvm-libunwind")] {
63         #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
64         #[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
65         extern "C" {}
66     } else {
67         #[link(name = "gcc", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
68         #[link(name = "gcc", cfg(not(target_feature = "crt-static")))]
69         extern "C" {}
70     }
71 }
72 // Android's unwinding library depends on dl_iterate_phdr in `libdl`.
73 #[cfg(target_os = "android")]
74 #[link(name = "dl", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
75 #[link(name = "dl", cfg(not(target_feature = "crt-static")))]
76 extern "C" {}
77
78 // When building with crt-static, we get `gcc_eh` from the `libc` crate, since
79 // glibc needs it, and needs it listed later on the linker command line. We
80 // don't want to duplicate it here.
81 #[cfg(all(
82     target_os = "linux",
83     any(target_env = "gnu", target_env = "uclibc"),
84     not(feature = "llvm-libunwind"),
85     not(feature = "system-llvm-libunwind")
86 ))]
87 #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
88 extern "C" {}
89
90 #[cfg(all(
91     target_os = "linux",
92     any(target_env = "gnu", target_env = "uclibc"),
93     not(feature = "llvm-libunwind"),
94     feature = "system-llvm-libunwind"
95 ))]
96 #[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
97 extern "C" {}
98
99 #[cfg(target_os = "redox")]
100 #[link(name = "gcc_eh", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
101 #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
102 extern "C" {}
103
104 #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
105 #[link(name = "unwind", kind = "static", modifiers = "-bundle")]
106 extern "C" {}
107
108 #[cfg(all(target_os = "windows", target_env = "gnu", target_abi = "llvm"))]
109 #[link(name = "unwind", kind = "static", modifiers = "-bundle")]
110 extern "C" {}