]> git.proxmox.com Git - rustc.git/blame - library/unwind/src/lib.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / library / unwind / src / lib.rs
CommitLineData
a7813a04 1#![no_std]
a7813a04 2#![unstable(feature = "panic_unwind", issue = "32837")]
3b2f2976 3#![feature(link_cfg)]
a7813a04 4#![feature(staged_api)]
94222f64 5#![feature(c_unwind)]
04454e1e 6#![feature(cfg_target_abi)]
a7813a04 7#![cfg_attr(not(target_env = "msvc"), feature(libc))]
7453a54e 8
dc9dc135 9cfg_if::cfg_if! {
abe05a73 10 if #[cfg(target_env = "msvc")] {
3dfed10e
XL
11 // Windows MSVC no extra unwinder support needed
12 } else if #[cfg(any(
13 target_os = "l4re",
14 target_os = "none",
94222f64 15 target_os = "espidf",
3dfed10e
XL
16 ))] {
17 // These "unix" family members do not have unwinder.
3dfed10e
XL
18 } else if #[cfg(any(
19 unix,
20 windows,
21 target_os = "psp",
c295e0f8 22 target_os = "solid_asp3",
3dfed10e
XL
23 all(target_vendor = "fortanix", target_env = "sgx"),
24 ))] {
abe05a73
XL
25 mod libunwind;
26 pub use libunwind::*;
3dfed10e
XL
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.
abe05a73
XL
36 }
37}
3b2f2976 38
2c00a5a8 39#[cfg(target_env = "musl")]
17df50a5
XL
40cfg_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")] {
94222f64 44 #[link(name = "unwind", kind = "static", modifiers = "-bundle")]
17df50a5
XL
45 extern "C" {}
46 } else if #[cfg(feature = "system-llvm-libunwind")] {
94222f64 47 #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
17df50a5
XL
48 #[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
49 extern "C" {}
50 } else {
94222f64 51 #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
17df50a5
XL
52 #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
53 extern "C" {}
54 }
55}
416331ca 56
353b0b11
FG
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")]
60cfg_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
f2b60f7d
FG
73#[cfg(target_os = "android")]
74cfg_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")))]
91extern "C" {}
92
29967ef6
XL
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",
c295e0f8 98 any(target_env = "gnu", target_env = "uclibc"),
29967ef6
XL
99 not(feature = "llvm-libunwind"),
100 not(feature = "system-llvm-libunwind")
101))]
102#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
103extern "C" {}
104
105#[cfg(all(
106 target_os = "linux",
c295e0f8 107 any(target_env = "gnu", target_env = "uclibc"),
29967ef6
XL
108 not(feature = "llvm-libunwind"),
109 feature = "system-llvm-libunwind"
110))]
111#[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
112extern "C" {}
113
416331ca 114#[cfg(target_os = "redox")]
94222f64 115#[link(name = "gcc_eh", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
416331ca 116#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
dfeec247 117extern "C" {}
f9f354fc
XL
118
119#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
94222f64 120#[link(name = "unwind", kind = "static", modifiers = "-bundle")]
f9f354fc 121extern "C" {}
04454e1e 122
487cf647
FG
123#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
124#[link(name = "gcc_s")]
125extern "C" {}
126
127#[cfg(all(target_os = "openbsd", target_arch = "sparc64"))]
128#[link(name = "gcc")]
129extern "C" {}
130
131#[cfg(all(target_os = "openbsd", not(target_arch = "sparc64")))]
132#[link(name = "c++abi")]
133extern "C" {}
134
135#[cfg(any(target_os = "solaris", target_os = "illumos"))]
136#[link(name = "gcc_s")]
137extern "C" {}
138
139#[cfg(target_os = "dragonfly")]
140#[link(name = "gcc_pic")]
141extern "C" {}
142
143#[cfg(target_os = "haiku")]
144#[link(name = "gcc_s")]
04454e1e 145extern "C" {}
9ffffee4
FG
146
147#[cfg(target_os = "nto")]
148#[link(name = "gcc_s")]
149extern "C" {}