Why -sUSE_OFFSET_CONVERTER is needed?

My goal is to use emcc to combine a c++ lib and a Zig built lib together to be a wasm.
The problem is when the wasm is used in web, it says:

Aborted(Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER).

So -sUSE_OFFSET_CONVERTER must be added to the emcc args to fix this.

But if I replace the Zig built lib with the Rust built lib(same code logic), the -sUSE_OFFSET_CONVERTER is not needed for emcc.

Why this arg is needed for Zig built version? Does anyone know what the -sUSE_OFFSET_CONVERTER flag means?

I believe that it is needed because of the way __builtin_return_address (in Zig @returnAddress) is implemented in Emscripten. In Zig this builtin is used in several core places such as the std.mem.Allocator interface. See my post here. If you build with unsafe release modes and don’t explicitly use @returnAddress then you shouldn’t need -s USE_OFFSET_CONVERTER.

1 Like

Thank you for the very useful info provided. I use std.heap.c_allocator in my code, so according to your explain @returnAddress is used in this part.