-
Notifications
You must be signed in to change notification settings - Fork 13
Description
I'm documenting this separately from my older issue comment that briefly mentioned the topic:
- Notably for the explicit need to add
eh_personalityorno_std(in addition to the global allocator) and the related attributes when adaptingno_stdfor Eyra. - Such a change would differ from musl/glibc
no_stdexamples regardingpanic_handler, so if this were to be resolved as additional Eyra features this might be a separate one fromeh_personality.
#![no_std]
#![no_main]
#![feature(lang_items)]
#![allow(internal_features)]
extern crate eyra;
#[no_mangle]
pub extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
0
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} }
#[global_allocator]
static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::GlobalDlmalloc;
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}Could presumably be simplified to:
#![no_std]
#![no_main]
extern crate eyra;
#[global_allocator]
static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::GlobalDlmalloc;
#[no_mangle]
pub extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
0
}It's unclear to me if that is a customization a user can presently do via their Cargo.toml dependencies config, or if that clashes with the c-scape dependency config shown below.
Additional context
Extracted from: #27 (comment)
eh_personalityvspanic = "abort"I was under the impression that
eh_personalitywas not necessary whenpanic = "abort"is configured (even without related-Z build-stdargs?), but I guess that's something Rust implicitly handled withno_stdon-gnu/-musltargets when building without Eyra? (EDIT: Yep, as referenced from Rust unstable book onlang-items)This resource notes that
panic = "abort"inCargo.tomlshould disable unwinding and thus not requireeh_personality? I can see fromcargo treethatrustixis using theunwindingcrate which provides ano_stdcompatible pure rust alternative, so perhaps this opt-out behaviour belongs upstream there?
$ cargo tree --invert unwinding
unwinding v0.2.2
├── c-scape v0.18.1
│ └── c-gull v0.18.1
│ └── eyra v0.17.0
│ └── example v0.1.0 (/example)
└── origin v0.20.2
└── c-scape v0.18.1 (*)https://crates.io/crates/unwinding#personality-and-other-utilities
The library also provides Rust personality function. This can work with the unwinder described above or with a different unwinder. This can be handy if you are working on a
#![no_std]binary/staticlib/cdylib and you still want unwinding support.
If you are writing a
#![no_std]program, simply enablepersonality,panic-handlerandsystem-allocin addition to the defaults, you instantly obtains the ability to do unwinding!
# Enable "libc" and don't depend on "spin". # TODO: Eventually, we should propose a `fde-phdr-rustix` backend option to # upstream `unwinding` so that it doesn't need to go through `dl_iterate_phdr`, # but `fde-phdr-dl` works for now. [target.'cfg(not(target_arch = "arm"))'.dependencies.unwinding] version = "0.2.0" default-features = false features = [ "unwinder", "dwarf-expr", "hide-trace", "fde-phdr-dl", "fde-registry", "libc", ]