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-interp --wasi --enable-threads can't handle emcc's pthread support #1645

Open
steven-johnson opened this issue Mar 17, 2021 · 5 comments

Comments

@steven-johnson
Copy link
Collaborator

I suspect this is a known issue, but recording it here:

emcc will allow you to compile with -pthread, and generate nice wrapper callers for POSIX pthread calls. I'd expect that invoking with --wasi --enable-threads would allow wasm code of this form to load and run, but it fails at load time with wasi error: unknown module import: env

Looking at the wasm2wat output for my code I see only two symbols in env:

(import "env" "pthread_create" (func $pthread_create (type 7)))
(import "env" "pthread_join" (func $pthread_join (type 1)))

I presume this is a known-ish issue due to the current incomplete status of wasi support? Just wanted to note it down here for reference (and in case someone else encounters it).

@sbc100
Copy link
Member

sbc100 commented Mar 17, 2021

Yes there is no support threads in WASI and no thread API to speak of. There it generally very little support for WASI in emscripten-generated code. Only the most trivial emscripten output doesn't include calls to APIs that are outside of WASI and even emscripten-specific.

So yeah.. although it would be nice to have one day what you are trying to do won't work today.

@steven-johnson
Copy link
Collaborator Author

Hm, so for code that I want to run under WASI, would I be better off using clang --target=wasm32 instead?

I've been using Emscripten up to because (initially) it was the only game in town, and then (later) it wasn't clear to me what the best options for libc/wasi support were. (Clang would actually be easier for us to support since we always have a recent clang available due to LLVM deps, and wouldn't require separate install/update like emsdk does.)

@sbc100
Copy link
Member

sbc100 commented Mar 17, 2021

wasi-sdk (which is basically clang + wasi-libc) is your best bet if you are targeting WASI: https://github.com/WebAssembly/wasi-sdk

emscripten tries it best to output WASI-compatible stuff where it can.. but this is normally impossible since many emsripten features (including threads) are built on JS APIs.

@steven-johnson
Copy link
Collaborator Author

there is no support [for] threads in WASI

Yikes, I missed this the first time through. That's, uh, surprising? Judging from the comments on WebAssembly/WASI#296 (which I'm now following) it looks like the consensus is "we'll get around to adding it to WASI someday", which, well, again, is surprising.

Sounds like the current status quo in wasm is basically "threads only work when compiling using emcc and using webworkers".

@sbc100
Copy link
Member

sbc100 commented Mar 17, 2021

Yes, basically. The WebAssembly threads proposal doesn't include any APIs for creating of joining threads, only the core concepts of shared memory and the operations on it. I think WASI wants to wait for some kind of standardized thread primitives in core WebAssembly before moving forward.

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