strange segfault calling glTexImage2D with PROXY_TO_PTHREAD and disabled optimisation -O0
Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.5 (53b38d0c6f9fce1b62c55a8012bc6477f7a42711) clang version 21.0.0git (https:/github.com/llvm/llvm-project 553da9634dc4bae215e6c850d2de3186d09f9da5) Target: wasm32-unknown-emscripten
Simple test project in a gist
https://gist.github.com/xriss/66340cdb1dbe18d829b43e9489cd393c
Changing to -O1 fixes the issue...
I hit this in a bigger project and then broke it down into this to recreate the issue, I thought it might be something strange to do with GL_PACK/UNPACK_ALIGNMENT settings but that doesn't seem to be it.
I see this as the first error in the console:
RuntimeError: operation does not support unaligned accesses
at a.wasm.emscripten_thread_mailbox_ref (thread_mailbox.c:21:28)
at a.wasm.em_task_queue_send (em_task_queue.c:232:8)
at a.wasm.do_proxy (proxying.c:149:10)
at a.wasm.emscripten_proxy_async (proxying.c:156:10)
at a.wasm.do_dispatch_to_thread (proxying_legacy.c:379:3)
at a.wasm.emscripten_dispatch_to_thread_args (proxying_legacy.c:401:10)
at a.wasm.emscripten_dispatch_to_thread_ (proxying_legacy.c:415:13)
at a.wasm.glTexImage2D (webgl1.c:307:6)
at a.wasm.main (a.cpp:45:2)
Looks like one of the atomic operations in thread_mailbox.c is erroring because it is called on an unaligned address,
https://github.com/emscripten-core/emscripten/blob/ca0d691dfd15893657db1a72802dd1ef99d9ed16/system/lib/pthread/thread_mailbox.c#L21
cc @tlively any idea how the pthreads mailboxes could end up with invalid/unaligned addresses?
edit: to get that stack trace I added -gsource-maps to the link, and ran it with emrun
Ah, we were recently looking at a similar error in a test: #23922
Does this reproduce deterministically?
Yes, looks deterministic.