Closed RazrFalcon closed 4 years ago
I think this is behaving correctly -- the extern "Rust"
ABI includes panicking on every extern function call at codegen time, which applies to all non-generic non-inline Rust functions from other crates as well as to all indirect calls made through Rust function pointers or trait objects.
The linker should be able to eliminate those panics at link time if you link with LTO:
[profile.release]
lto = "thin"
Thanks, it worked. But I'm not sure what is happening here. Does rustc wraps each call in a panic (for whatever reason) or is this a no-panic
limitation?
Rustc codegen wraps every extern function call with "Rust" ABI (as described above) in panic handling.
In your case it's two different codegen units compiling the function being called and the function making the call, so the earliest place that would have information to know there is no panic is the linker at LTO.
I see, thanks. I wanted to test my library without adding the no-panic
dependency and stumbled on this issue.
Sorry for bothering again, but I just wanted to clarify the no-panic
behavior. Let's say I will create a separate executable that will invoke all library methods wrapped in #[no_panic]
, like it was done in the linked repo, does it 100% guarantee that it will catch all panics or is it still false-positive?
It takes into account all panics.
It's hard to explain what is wrong, so I've created a dedicated repo: https://github.com/RazrFalcon/no-panic-bug
Interestingly, it works fine when the library function is marked as
#[inline]
.