Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second Webassembly fn import of the same name but different module name is ignored #12880

Closed
Pyrolistical opened this issue Sep 17, 2022 · 1 comment · Fixed by #13396
Closed
Labels
arch-wasm 32-bit and 64-bit WebAssembly bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@Pyrolistical
Copy link
Contributor

Pyrolistical commented Sep 17, 2022

Zig Version

0.10.0-dev.4060+61aaef0b0

Steps to Reproduce

  1. Create two files that both import a function of the same name, but with different module names
  2. Import two files into a 3rd one and call both functions.
  3. Make webassembly build
  4. Decompile webassembly
  5. Observe the declared import functions

a.zig

pub extern "a" fn hello() i32;

b.zig

pub extern "b" fn hello() i32;

double-hello.zig

const a = @import("a.zig");
const b = @import("b.zig");

extern "env" fn out(value: i32) void;
export fn doubleHello() void {
    out(a.hello());
    out(b.hello());
}

build command zig build-lib double-hello.zig -target wasm32-freestanding -dynamic

decompile double-hello.wasm using https://webassembly.github.io/wabt/demo/wasm2wat/

Expected Behavior

In decompiled wasm, expected two hello functions.

  (import "a" "hello" (func $a_hello ...
  (import "b" "hello" (func $b_hello ...

Actual Behavior

In decompiled wasm, only found a.hello

  (import "a" "hello" (func $hello ...
@Pyrolistical Pyrolistical added the bug Observed behavior contradicts documented or intended behavior label Sep 17, 2022
@Pyrolistical
Copy link
Contributor Author

What is really bad about this bug is all calls to b.hello go to a.hello and that is really hard to detect. I got random errors with "bitcast invalid" but that was a red herring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants