3 ms·
>having CI fail if the optimized binary contains ANY call-sites to the panic handler. How do you do that?
by cdchn 2y ago
>having CI fail if the optimized binary contains ANY call-sites to the panic handler.
How do you do that?
- woodruffw 2y agoYou can use something like `no_panic`[1]. You could also do it statically, post-build, by looking for calls to the panic handler. [1]: https://docs.rs/no-panic/latest/no_panic/ https://docs.rs/no-panic/latest/no_panic/
- bpicolo 2y agoDoes annotating `main` with no_panic do the trick? How much does that tend to affect compile times, do you know?
- woodruffw 2y ago> Does annotating `main` with no_panic do the trick? I've never tried that, so maybe :-) > How much does that tend to affect compile times, do you know? IME, not very much -- there might be a small amount of overhead, but the "trick" behind the check is to fail the linker with a symbol error if the panic code is inserted into a function. So the compiler itself should be roughly as fast, and the error path in the linker is really the only thing that should change too much.
- fleventynine 2y agoHave your panic handler call an extern "C" function that doesn't exist, and the linker will complain if there's any calls to that function that weren't optimized out. Alternately, you can look for the symbol in the output elf file and fail if it's there, which is a bit more graceful as panicking binaries can still be produced during development.