Skip to main content

std/sys/personality/
mod.rs

1//! This module contains the implementation of the `eh_personality` lang item.
2//!
3//! The actual implementation is heavily dependent on the target since Rust
4//! tries to use the native stack unwinding mechanism whenever possible.
5//!
6//! This personality function is still required with `-C panic=abort` because
7//! it is used to catch foreign exceptions from `extern "C-unwind"` and turn
8//! them into aborts.
9//!
10//! Additionally, ARM EHABI uses the personality function when generating
11//! backtraces.
12
13mod dwarf;
14
15#[cfg(not(any(test, doctest)))]
16cfg_select! {
17    any(target_env = "msvc", target_family = "wasm") => {
18        // This is required by the compiler to exist (e.g., it's a lang item),
19        // but it's never actually called by the compiler because
20        // __CxxFrameHandler3 (msvc) / __gxx_wasm_personality_v0 (wasm) is the
21        // personality function that is always used.  Hence this is just an
22        // aborting stub.
23        #[lang = "eh_personality"]
24        fn rust_eh_personality() {
25            core::intrinsics::abort()
26        }
27    }
28    any(
29        all(target_family = "windows", target_env = "gnu"),
30        target_os = "psp",
31        target_os = "xous",
32        target_os = "solid_asp3",
33        all(target_family = "unix", not(target_os = "espidf"), not(target_os = "nuttx")),
34        all(target_vendor = "fortanix", target_env = "sgx"),
35    ) => {
36        mod gcc;
37    }
38    _ => {
39        // Targets that don't support unwinding.
40        // - os=none ("bare metal" targets)
41        // - os=uefi
42        // - os=espidf
43        // - os=hermit
44        // - os=motor
45        // - nvptx64-nvidia-cuda
46        // - arch=avr
47    }
48}