4 ms·
As a novice with Rust maintaining a cross-platform library written in Rust, I've found panics/unwinding is one of the most annoying things to figure out in the
by matharmin 2y ago
As a novice with Rust maintaining a cross-platform library written in Rust, I've found panics/unwinding is one of the most annoying things to figure out in the builds for various platforms.
I'm using nostd and panic=abort to keep the library small (around 200kb after being stripped), but it's really not a well-supported setup.
Depending on the platform, I get an error that the _Unwind_Resume symbol is not defined (despite it not supposed to be needed), or if I define it myself I get a duplicate symbol error on other platforms. I ended up linking to gcc_eh on Linux just to avoid the issue.
I just find it strange that out of all the possible issues with using nostd, unwinding is causing the most issues.
- agarwaen163 2y agoI have had the same issue writing rust libraries for things like performant (Gb/s) network log analyzers. Agree this is one of the weak points of the language in my relatively amateur Rust experience. I also faced the rare cargo dependency bug, but still better than alternatives.
- Arnavion 2y ago>I get an error that the _Unwind_Resume symbol is not defined (despite it not supposed to be needed) Try `-Z build-std=core` if you're not already doing it.
- an_ko 2y agoCould you elaborate on why that works, or why it's necessary?
- Arnavion 2y agoI know little about it and I'm not sure that it works. It might. I do know that for regular std-using programs, std has its own panic strategy that it was compiled with, so even if you set your own code's panic strategy to abort, it still ends up pulling in unwind-related code from libstd. The solution to that is to also recompile libstd with the same parameters as your own code, which is what `-Z build-std` does. I don't know if the same thing applies even to libcore, ie for no_std programs. FWIW, coincidentally I spent yesterday making a no_std panic=abort program for a custom freestanding target, and the only missing symbols it needed from me were memcpy and memcmp, even though the code does do panicking things like slice indexing. That program requires `-Z build-std=core` since it's for a custom freestanding target.