Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is eh_personality called?

Tags:

rust

I'm trying to implement an OS in Rust using libcore. In the documentation, it says that the eh_personality function needs to be implemented.

However, I see no usage of this function in libcore itself and I am able to compile, run, and execute panics without it.

Is there something I'm missing here? Where does eh_personality get called during the panic!() cycle?

like image 815
Chris Smith Avatar asked Feb 26 '18 05:02

Chris Smith


1 Answers

See unstable-book: lang_items:

The first of these functions, rust_eh_personality, is used by the failure mechanisms of the compiler. This is often mapped to GCC's personality function (see the libstd implementation for more information), but crates which do not trigger a panic can be assured that this function is never called. The language item's name is eh_personality.

As far as I can tell it is required to create unwind information; if you abort or loop in the panic_fmt language item (function rust_begin_unwind) it probably doesn't get called.

Also see the internal comments in libpanic_abort/lib.rs.

If you search for rust_eh_personality you'll find a usage in librustc_trans/context.rs: CodegenCx::eh_personality. Searching for eh_personality should reveal the places this function is called. (It is used for code generation, not a direct call.)

Searching for #[lang = "eh_personality"] only shows the places where a personality is defined, not the usage.

like image 158
Stefan Avatar answered Oct 14 '22 05:10

Stefan