[WASM_WORKERS] Don't define pthread function in WASM_WORKERS builds#26336
[WASM_WORKERS] Don't define pthread function in WASM_WORKERS builds#26336sbc100 merged 1 commit intoemscripten-core:mainfrom
Conversation
3205832 to
1423e8c
Compare
1423e8c to
c899a02
Compare
Using the pthread API with WASM_WORKERS simply will not work.
c899a02 to
986ba39
Compare
|
Is it possible to create a wasm worker in a build that uses pthreads (was that ever possible)? |
Yes, in that case you get all the pthread functions linked in. They exist, but bad things would happen if you called them from wasm worker. We don't have any protection against that though, either before of after this PR. I will update the PR description. |
| 5.0.3 (in development) | ||
| ---------------------- | ||
| - When building with `-sWASM_WORKERS` emscripten will no longer include pthread | ||
| API stub functions. These stub functions where never designed to work under |
There was a problem hiding this comment.
| API stub functions. These stub functions where never designed to work under | |
| API stub functions. These stub functions were never designed to work under |
|
Hmm, it looks like this isn't quite as simple. After this PR, this code fails:
#include <emscripten/html5.h>
int foo(int x)
{
static int z = emscripten_performance_now();
++z;
if (x <= 0) return 0;
return foo(x-1) + foo(x-2) + z;
}
int main()
{
return foo(42);
}em++ a.cpp -o a.html -sWASM_WORKERS wasm-ld: error: C:\emsdk\emscripten\main\cache\sysroot\lib\wasm32-emscripten\libc++abi-debug-ww-noexcept.a(cxa_guard.o): undefined symbol: pthread_cond_wait |
|
Maybe we should then contend to routing these functions to a partial stub implementation in Wasm Workers mode, so that the compiler emitted constructs will be there. |
|
Yes, I believe that is the exact issue described in #26277. That code has always been broken under Wasm Workers, but would fail in subtle ways at runtime before (because the locked around the initializer was not safe). Now we get a nice build time failure, which I think its better than a broken program. I believe fixing #26277 should not be too hard now that we have the futex API available. @AndreyRepko would you have time to update your PR (#26283) to use the futex API? |
Oh right, yeah indeed, before that the pthread lock functions would come out as no-ops. |
Using the pthread API with WASM_WORKERS simply will not work.
This also means function-local-static C++ initializes will now fail to link with WASM_WORKERS, at least until we fix #26277. Note that prior to this change this was already broken but would fail at runtime.
Note that its still possible to build with WASM_WORKERS + pthreads, in which case all the real pthread functions are available, but calling them from a Wasm Worker would be undefined behaviour (with or without this PR).
See #26314