You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In file included from test.cc:1:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/iostream:42:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/ios:220:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__locale:24:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/string:647:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/string_view:941:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/algorithm:1842:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__algorithm/for_each.h:16:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__ranges/movable_box.h:21:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/optional:1288:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/atomic:596:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/aliases.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic_base.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic_sync.h:20:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__thread/support.h:112:
./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__thread/support/pthread.h:182:10: error: static assertion failed: This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread
182 | return pthread_create(__t, nullptr, __func, __arg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/pthread.h:92:47: note: expanded from macro 'pthread_create'
92 | #define pthread_create(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
| ^
In file included from test.cc:1:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/iostream:42:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/ios:220:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__locale:24:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/string:647:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/string_view:941:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/algorithm:1842:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__algorithm/for_each.h:16:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__ranges/movable_box.h:21:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/optional:1288:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/atomic:596:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/aliases.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic_base.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic_sync.h:20:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__thread/support.h:112:
./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__thread/support/pthread.h:190:88: error: static assertion failed: This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread
190 | inline _LIBCPP_HIDE_FROM_ABI int __libcpp_thread_join(__libcpp_thread_t* __t) { return pthread_join(*__t, nullptr); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/pthread.h:98:45: note: expanded from macro 'pthread_join'
98 | #define pthread_join(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
| ^
In file included from test.cc:1:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/iostream:42:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/ios:220:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__locale:24:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/string:647:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/string_view:941:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/algorithm:1842:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__algorithm/for_each.h:16:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__ranges/movable_box.h:21:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/optional:1288:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/atomic:596:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/aliases.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic_base.h:12:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__atomic/atomic_sync.h:20:
In file included from ./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__thread/support.h:112:
./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/c++/v1/__thread/support/pthread.h:192:90: error: static assertion failed: This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread
192 | inline _LIBCPP_HIDE_FROM_ABI int __libcpp_thread_detach(__libcpp_thread_t* __t) { return pthread_detach(*__t); }
| ^~~~~~~~~~~~~~~~~~~~
./wasi-sdk-25.0-arm64-macos/share/wasi-sysroot/include/wasm32-wasip1-threads/pthread.h:95:47: note: expanded from macro 'pthread_detach'
95 | #define pthread_detach(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
| ^
3 errors generated.
Of course, passing -D_WASI_EMULATED_PTHREAD to clang++ allows compilation to succeed, but it doesn't seem like this should be necessary.
Moreover, the message about -lwasi-emulated-pthread is also misleading. This library is not available for wasm32-wasip1-threads, so following the error message blindly leads to a linking error too.
The ideal solution here would be to make sure that the assertion doesn't fire when targeting a WASI mode with threads enabled. If that's not doable, then ideally the message shouldn't erroneously suggest using -lwasi-emulated-pthread when it isn't needed and will lead to a linking error.
carlocab
changed the title
Thread-related static asserts trigger in C++ even when targeting thread-enabled WASI
Thread-related asserts trigger in C++ even when targeting thread-enabled WASI
Dec 13, 2024
To be fair portable usage of pthreads requires passing -pthread to gcc or clang. On some OSes it works without either (if pthread support is part of libc itself), on some OSes it links the required libpthread.so and on yet other OSes it links against an entirely different library that provides the pthread primitives. That said, I guess there is something to be said for making -pthread the default for wasm32-wasip1-threads.
Compiling a simple
hello world
program in C++ while targetingwasm32-wasip1-threads
triggers an assertion here:wasi-libc/libc-top-half/musl/include/pthread.h
Lines 91 to 100 in 574b88d
This seems wrong because this mode of WASI does have threads enabled (unless I'm misunderstanding the meaning of the
-threads
suffix).To reproduce:
This produces:
Error Log
Of course, passing
-D_WASI_EMULATED_PTHREAD
toclang++
allows compilation to succeed, but it doesn't seem like this should be necessary.Moreover, the message about
-lwasi-emulated-pthread
is also misleading. This library is not available forwasm32-wasip1-threads
, so following the error message blindly leads to a linking error too.The ideal solution here would be to make sure that the assertion doesn't fire when targeting a WASI mode with threads enabled. If that's not doable, then ideally the message shouldn't erroneously suggest using
-lwasi-emulated-pthread
when it isn't needed and will lead to a linking error.Related: #518, #518 (comment)
The text was updated successfully, but these errors were encountered: