[LLVM WASM backend] - pthread_local causes a compiler crash

25 views
Skip to first unread message

Mehdi Sabwat

unread,
Jul 4, 2019, 3:43:28 PM7/4/19
to emscripten-discuss
Hi,

Putting this here because I think it could lead to an interesting discussion. (and because by writing things down, I can understand them better. This is (very) new to me)

cross compiling this
[thread_local]$ cat main.c
#include <threads.h>
#include <stdio.h>

thread_local
int a;

int main()
{
  printf
("%d\n", a);
}

with:

emcc -pthread main.c

or:
emcc -s USE_PTHREADS=1

or:
clang-9 --target=wasm32-unknown-emscripten -I../../emsdk/upstream/emscripten/system/include/libc/ -pthread main.c)

leads to a SIGABORT because this assertion fails:
virtual uint64_t (anonymous namespace)::WasmObjectWriter::writeObject(llvm::MCAssembler &, const llvm::MCAsmLayout &): Assertion `Sec.getKind().isMetadata()' failed

WasmObjectWriter fails to write object code because of the IR, which has weird or unrecognized sections. Question is, if we change the code to initialise the sections, would it be recognised by WASM if so, how ?  :) there doesn't seem to be any reference of thread_local in WebAssembly.

Since pthread support is experimental in WASM (although we can already do a lot of things), I wanted to know if there was something we could do to work around it?

Complete logs are here.

Cheers!

Thomas Lively

unread,
Jul 4, 2019, 3:58:39 PM7/4/19
to emscripte...@googlegroups.com
Unfortunately thread local storage has not been implemented in the WebAssembly LLVM backend yet, although we’re just starting to work on it now. I saw the LLVM bug you filed, and we will definitely take a look at how we can avoid the crash you’re seeing or at least give a more helpful error message until TLS support is complete.

For now you can try using the pthreads library TLS rather than language-level TLS. I believe that should work.
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/78f61504-4e78-4afb-a4be-3e0314f5e29f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages