Fixed: I set the DLL storage class of the function I was importing to dllimport
, and that allowed wasm-ld to emit the correct import namespace.
I am building a compiler with the LLVMSharp* library, and it emits LLVM .bc module files targeted to wasm32-unknown-unknown
. I am trying to import functions into it from the WASI interface by tagging those function values with the { "wasm-import-module"="wasi_unstable" }
attribute. (This should be equivalent to what clang does with __attribute__((import_module(<module_name>)))
; see here). However, when I pass the resulting .bc files to wasm-ld (the Windows 64-bit 9.0.0 installed version), the resulting .wasm module still imports those functions from "env"
, which doesn't work.
Is there some option to pass to wasm-ld to get it to handle wasm-import-module
correctly, or do I need to go another route?
*Specifically, I'm using LLVMSharp 5.0.0, which is the latest stable version. It's possible that LLVMSharp 8.0.0 may support building .wasm modules, but there isn't a release NuGet for it, and the beta NuGet has some problems that prevent me from upgrading. That's why I'm going the wasm-ld route.
wasm-ld should support this attribute. The first thing to check is your object file.
You can use llvm-readobj --syms
to dump the symbols in your object file. You should see ImportModule: foo
on your symbol where foo
is the module name you specified in your attribute.
I looks like the support for this landed in wasm-ld in: https://reviews.llvm.org/D45796
I believe this change landed just before llvm 8.0, so you will llvm 8.0 or above.