Compiling an empty program with "no_global_oom_handling" fails

Hello everyone! Recently, I've learned about the no_global_oom_handling option and tried to test how it works. I'm trying to build a simple program with:

RUSTFLAGS="--cfg no_global_oom_handling" cargo +nightly build -Z build-std --target=x86_64-unknown-linux-gnu --release

However, I cannot compile even an "empty" program (that only consists of fn main() {}) in such mode, since it reports errors in the "gimli" crate (that I don't explicitly depend on). How can it be fixed?

You do depend on gimli through std (for DWARF, likely used by backtraces/unwinding). The crate probably doesn't support being used without global OOM handling.
You can try building with panic=abort (or even -Z build-std-features=panic_immediate_abort). If that doesn't work, try building entirely #![no_std].
Almost all crates (that allocate) expect a global OOM handler to exist.

Oh, I see.

P.S. Also, I noticed that using #[no_panic] macro from no_panics create also prevents any use of infallible memory allocation API. It may be used where global OOM handling is undesirable.

no_global_oom_handling is only compatible with no_std programs.

3 Likes