Closed
Description
The following code illustrates the issue:
#![allow(dead_code, unused_imports)]
#![feature(lang_items, core_intrinsics)]
#![feature(custom_attribute)] // <- required for wasm_import_module
#![feature(wasm_import_module)]
#![no_std]
use core::intrinsics;
#[lang = "panic_fmt"]
#[no_mangle]
pub extern fn rust_begin_panic(
_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32,
_column: u32) -> ! {
unsafe { intrinsics::abort() }
}
mod m1 {
#[wasm_import_module = "m1"]
extern "C" {
pub fn f();
}
#[wasm_import_module = "m1"]
extern "C" {
pub fn g();
}
}
mod m2 {
#[wasm_import_module = "m2"]
extern "C" {
pub fn f(_: i32);
}
}
#[no_mangle]
pub unsafe fn run() {
m1::g();
// In generated code, expected:
// (import "m2" "f" (func $f (param i32)))
// but got:
// (import "m1" "f" (func $f (param i32)))
m2::f(0);
}
To compile:
❯ rustc \
--crate-type=cdylib \
--target=wasm32-unknown-unknown \
-o result.wasm \
src/lib.rs
Then, using binaryen's wasm-dis
:
❯ wasm-dis foo.wasm | grep import
(import "m1" "g" (func $g))
(import "m1" "f" (func $f (param i32)))
The type of f
is correct since m1::f()
takes no arguments, but the module name is not. Looks like rustc
has the right function but with wrong module name.