4 ms·
I tried exploring no_std Rust recently, and found it to be quite frustrating. After just using a Result type I was getting errors of things like `eh_unwind_resu
by jefftime 9y ago
I tried exploring no_std Rust recently, and found it to be quite frustrating. After just using a Result type I was getting errors of things like `eh_unwind_resume` being undefined. Toggling LTO rectified my problems but didn't give me much confidence in reliably using no_std
- red75prime 9y ago`-C panic=abort` compiler option should have fixed the problem. If you want to be able to intercept panics, you need to provide implementations for `eh_unwind_resume` and `eh_personality`.
- jefftime 9y agoPerhaps it's just an issue of me not being educated enough with this kind of low-level Rust. Setting panic to abort in the cargo config did indeed fix `eh_personality` being undefined, but `eh_unwind_resume` still seems finnicky. Building in release will work, but building in debug will still complain
- red75prime 9y agoI'm a little rusty on the topic, but it seems ([0]) that adding `#[no_mangle]` before `panic_fmt` should fix it. [0] https://github.com/rust-lang/rust/issues/38281 https://github.com/rust-lang/rust/issues/38281
- steveklabnik 9y agoSee also https://doc.rust-lang.org/nightly/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib https://doc.rust-lang.org/nightly/unstable-book/language-fea...
- jefftime 9y agoEven specifying `eh_unwind_resume` as a lang item gives me a linking error in debug builds.
- steveklabnik 9y agoDid you define them exactly the same way? Every aspect has to be identical; extern, no mangle, function name, arguments, lang item. If this happens to be open source, I can take a look at it.
- jefftime 9y agoI just whipped this up yesterday to test if I was still having the same issues. Debug fails to build with a linking error "undefined reference to `_Unwind_Resume`". Release build works fine. I'm using rustc 1.25.0-nightly on Ubuntu 17.10 https://gist.github.com/jefftime/d7e96461138b5aa6895550b63caac66c https://gist.github.com/jefftime/d7e96461138b5aa6895550b63ca...
- steveklabnik 9y agoThe lang item symbol names need to be prefixed with rust_ like this: https://gist.github.com/steveklabnik/5abd59a8fe7e5abda3db58bd8c208fbb https://gist.github.com/steveklabnik/5abd59a8fe7e5abda3db58b...
- jefftime 9y agoThis didn't fix the compilation errors for me. I can set my own no_mangle pub extern `_Unwind_Resume` function (without declaring it a lang_item) and fix the undefined reference that way, but I'm pretty sure that's not how one's supposed to solve this
- steveklabnik 9y agoHm, it compiled for me. Well, it didn't know about the C functions that were being linked in, but it didn't complain about the lang items. You should file a bug, maybe.
- quotemstr 9y agoFor low level code, do you really want to abort on panic? Rust error handling is easily my least favorite part of the language, combining the disadvantages of exceptions and return codes.
- steveklabnik 9y agoMany do, yes. Panics are non-recoverable errors, and aborting produces leaner code, which is important on embedded.
- quotemstr 9y agoPanics are recoverable though
- steveklabnik 9y agoThey’re not guaranteed to be, so you can’t rely on it. You can say that you do, but then you may cut yourself off from the rest of the ecosystem. Libraries generally can’t rely on either behavior, applications choose.
- quotemstr 9y agoAnd that's why I think the Rust has a worst-of-both-worlds error handling strategy.