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

Wasm modules with shared memories are rejected even if they do not spawn threads #470

Closed
whitequark opened this issue Jul 14, 2024 · 3 comments

Comments

@whitequark
Copy link
Contributor

To reproduce:

$ cat test.c
#include <stdio.h>

int main() {
  puts("hello");
}
$ .../wasi-sdk-22.0/bin/clang -target wasm32-wasip1-threads -pthread test.c -o test.wasm
$ jco new test.wasm --wasi-command -o test.component.wasm
(jco componentNew) ComponentError: failed to encode a component from module
$failed to validate component output

Caused by:
    type mismatch for export `memory` of module instantiation argument `env`
    mismatch in the shared flag for memories (at offset 0x7fd8)
    at componentNew (file:///home/whitequark/.npm-packages/lib/node_modules/@bytecodealliance/jco/obj/wasm-tools.js:2462:11)
    at componentNew (file:///home/whitequark/.npm-packages/lib/node_modules/@bytecodealliance/jco/src/cmd/wasm-tools.js:58:18)
    at async file:///home/whitequark/.npm-packages/lib/node_modules/@bytecodealliance/jco/src/jco.js:134:9

This example is extracted from a larger project (YoWASP Clang). LLVM currently does not compile for the wasm32-wasip1 target (it requires wasm32-wasip1-threads) because it extensively uses atomics even in a single-threaded build. This is difficult to change. However, an LTO build of LLVM/Clang/LLD (with the WebAssembly patchset that's likely going to be accepted in near future) doesn't import thread.spawn and so doesn't need to be treated differently.

Should this restriction be relaxed in jco?

@pchickey
Copy link
Collaborator

Thanks for identifying this issue! The responsible code here is the wit-component crate, which is getting invoked by jco as a component binary (!). can you please refile here https://github.com/bytecodealliance/wasm-tools/issues as "wit-component should accept modules with shared memories" and we can work out how we can resolve this.

@whitequark
Copy link
Contributor Author

@pchickey Done, and closing this in favor of bytecodealliance/wasm-tools#1674.

@whitequark whitequark closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2024
@whitequark
Copy link
Contributor Author

which is getting invoked by jco as a component binary (!)

I find this arrangement very clever and I admire it from a technical elegance point of view, but it definitely makes contribution more difficult at times...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants