Not zero-initialize wasm globals

Hello, with that code:

static mut FOO: MaybeUnint<Foo> = MaybeUninit::uninit();

Final wasm binary would include zeros for that FOO. Is there a way to prevent that from happening? I'm also running wasm-opt -Oz.

The linking tool convention doesn't have an equivalent to .bss, so every global variable has to be defined with some value. As wasm (and basically every native target) doesn't have the concept of undefined memory, the compiler picks zeros to fill the data segment for FOO in the object file it produces.

Wasm-opt has flag --zero-filled-memory that remove those zeros

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.