Stream: general

Topic: ✔ Did anyone manage to run a wasm32-wasi-threads module?


view this post on Zulip Cheng Shao (Feb 08 2023 at 14:08):

Given wasmtime recently landed support, I tried to run a pthread hello world program, and encountered two issues:

Did anyone else manage to compile and run a wasm32-wasi-threads module?

view this post on Zulip Andrew Brown (Feb 08 2023 at 19:06):

Yes, I hope to publish a blog post explaining all the details soon but there are a few remaining issues to work through.

view this post on Zulip Andrew Brown (Feb 08 2023 at 19:08):

One of the reasons that I'm working on https://github.com/WebAssembly/wasi-sdk/pull/293 is that LLVM 16 provides the --export-memory and --import-memory flags in a way that allows the "import, then export" paradigm currently necessary in Wasmtime. Once I have that working I plan to publish a pre-release of wasi-sdk that has all the right tools to make things work.

This change updates the src/llvm-project submodule to LLVM 16. It uses the same commit as the one in LLVM's own 16.0.0-rc1 pre-release. It also updates the src/wasi-libc submodule with some recent ...

view this post on Zulip Cheng Shao (Feb 08 2023 at 19:25):

Ah, --export-memory, that was new in wasm-ld and i was looking at the old manpage. I just got an example to run, the behavior is a bit odd but that's kinda expected in the early days. Thanks for your work.

view this post on Zulip Notification Bot (Feb 08 2023 at 19:25):

Cheng Shao has marked this topic as resolved.

view this post on Zulip Andrew Brown (Feb 08 2023 at 20:19):

Yeah, the "import, then export" idea is odd (if that's what you're referring to). @YAMAMOTO Takashi opened up https://github.com/WebAssembly/WASI/issues/502 to discuss this topic generally; feel free to comment there if you have a strong opinion one way or another.

currently a module exports its memory for wasi. for wasi-threads, a module imports the memory too. it's a bit redundant to both import and export a memory. regardless of what to do for wasi-thr...

view this post on Zulip Cheng Shao (Feb 08 2023 at 20:23):

No, I mean the runtime result is incorrect. Though I'm not sure if it's a wasi-libc issue or wasmtime issue, so don't know where to report it..

view this post on Zulip Andrew Brown (Feb 08 2023 at 20:40):

Oh, that's interesting! If you can diagnose which side it is on, please open a bug. The whole idea of this experimental wasi-sdk release is to bring to light these kinds of issues. Can you say more about the project and what you see?

view this post on Zulip Cheng Shao (Feb 08 2023 at 21:12):

The bug report is at https://gist.github.com/TerrorJack/a3128331031377a38d50912b0eab609c

GitHub Gist: instantly share code, notes, and snippets.

view this post on Zulip Andrew Brown (Feb 08 2023 at 23:15):

Thanks, I'll take a look!

view this post on Zulip YAMAMOTO Takashi (Feb 09 2023 at 03:01):

Cheng Shao said:

The bug report is at https://gist.github.com/TerrorJack/a3128331031377a38d50912b0eab609c

you should use large enough --max-memory.
eg.

spacetanuki% /opt/wasi-sdk-19.5g0236e959edbc/bin/clang -Wall --target=wasm32-wasi-threads -pthread thread.c -o thread.wasm -Wl,--import-memory,--max-memory=655360
spacetanuki% ~/git/toywasm/b.thread/toywasm --wasi thread.wasm
Thread - 2
Thread - 1
spacetanuki%

view this post on Zulip Andrew Brown (Feb 10 2023 at 18:27):

Yeah, that's it... wow, that was unintuitive. I just was taking a look at @Cheng Shao's report today and I can confirm that adding --max-memory=655360 to the linker flags makes everything start working again.

view this post on Zulip Andrew Brown (Feb 10 2023 at 18:32):

I guess non-PoC code would have error-checking like the following:

int ret = pthread_create(&thread1, NULL, &thread, (void *) thr);
if (ret) {
    printf("failed to spawn: %s\n", strerror(ret));
}

Which prints the following for me:

failed to spawn: Resource temporarily unavailable

Last updated: Nov 22 2024 at 17:03 UTC