Skip to content

Malformed Wasm binaries with @extern's std.builtin.GlobalLinkage #11505

Closed

Description

Version is 0.10.0-dev.4176+6d7b0690a (stage2).

pub fn main() void {
    const a = @extern(*const fn ([*]const u8) void, .{
        .name = "a",
        .library_name = "b",
        .linkage = .Strong, // or `.Weak`
        .is_thread_local = false,
    });
    a("hello");
}
zig build-exe -target wasm32-freestanding-none -O ReleaseSmall x.zig

This seems to generate malformed Wasm?

$ wasm2wat x.wasm
x.wasm:0000048: error: type mismatch at end of function, expected [] but got [i32]

Activity

  1. added
    stage1
    arch-wasm
    bug
    on Apr 23, 2022
  2. added this to the 0.12.0 milestone on Apr 28, 2022
  3. added
    frontend
    on Sep 27, 2022
  4. removed
    stage1
    on Dec 8, 2022
  5. Luukdegram commented on Jan 2, 2023

    @Luukdegram
    Contributor

    Thanks to #14102 this now generates the proper undefined symbol 'a' linker error as it does with other platforms such as ELF/MachO. When forced with --import-symbols it does however generate a proper Wasm binary now:

    > wasm-validate x.wasm
    > $?
    0

    Note this imports a function pointer, not a function symbol, and therefore will not generate an import entry in the WebAssembly module.

  6. modified the milestones: 0.12.0, 0.11.0 on Jan 2, 2023
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-wasmbugfrontend

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions