News for hackers. Stuff that matters.
Re:Rust panics under the hood, and implementing them in .NET by matharmin on Monday September 23, 2024 @01:13PM (#41628324)
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.

Re:Rust panics under the hood, and implementing them in .NET by agarwaen163 on Monday September 23, 2024 @02:59PM (#41629396)
I 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.
Re:Rust panics under the hood, and implementing them in .NET by Arnavion on Monday September 23, 2024 @03:31PM (#41629649)
>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.

Re:Rust panics under the hood, and implementing them in .NET by an_ko on Monday September 23, 2024 @03:36PM (#41629680)
Could you elaborate on why that works, or why it's necessary?
Re:Rust panics under the hood, and implementing them in .NET by Arnavion on Monday September 23, 2024 @03:47PM (#41629779)
I 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.