Skip to content

wasm linker lowers undefined and 0 incorrectly with respect to the bss section #14834

Description

@andrewrk

Zig Version

0.11.0-dev.1898+36d47dd19

Steps to Reproduce and Observed Behavior

This test case is incorrect: https://github.com/ziglang/zig/blob/36d47dd1991f0ccd7a9673075624f09500cc415e/test/link/wasm/bss/build.zig

The global variable has value undefined:

pub var bss: u32 = undefined;

So it should not go into the bss section in debug mode.

Furthermore, when I change the value to 0 it should definitely go into bss, however in this case the test fails.

Expected Behavior

Zig is technically allowed to lower undefined in any way it wants to, however the linker test can test the actual behavior of the linker. It should do the following for undefined:

  • Debug, ReleaseSafe: lower to 0xaa bytes
  • ReleaseFast, ReleaseSmall: lower to bss

For zero values, it must lower to bss.

cc @Luukdegram and @kubkon

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasm32-bit and 64-bit WebAssemblybugObserved behavior contradicts documented or intended behaviorlinkingmiscompilationThe compiler reports success but produces semantically incorrect code.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions