Open llvmbot opened 5 years ago
thread_local isn't supported yet in wasm. It's something we'd like to fix in the near future. It also requires support from the C library. We'd implement it in emscripten. In the future, if and when WASI gets threading support it would make sense to implement it there too, and make the interface the same.
I can reproduce the bug on a much simpler example:
include
include
thread_local int a;
int main() { printf("%d\n", a);
}
(Previous message was interrupted, I'll continue here)
For the first example I gave, if we comment out the calls to vlc_interrupt_var, which is a thread_local variable, the file compiles.
For the simple (and short) main.c example. If we compile using -pthread, the compiler will crash. See main.zip attachement for the Preprocessed source and associated run script.
clang-9 --target=wasm32-unknown-emscripten -I ../../emsdk/upstream/emscripten/system/include/ -pthread main.c
I hope this helps. Do not hesitate to reach out for further discussion.
Regards,
I can reproduce the bug on a much simpler example:
thread_local int a;
int main() { printf("%d\n", a);
}
Extended Description
Hi,
Enabling -pthread as a CFLAG in our build system causes a crash in clang-9. I will give the trace and source file with the run script. More details to come in the comments.
Trace: clang-9: /b/s/w/ir/cache/builder/emscripten-releases/llvm-project/llvm/lib/MC/WasmObjectWriter.cpp:1293: virtual uint64_t (anonymous namespace)::WasmObjectWriter::writeObject(llvm::MCAssembler &, const llvm::MCAsmLayout &): Assertion `Sec.getKind().isMetadata()' failed. Stack dump:
0 0x00007fddcea3d3e4 PrintStackTraceSignalHandler(void*) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x6b13e4)
1 0x00007fddcea3b0de llvm::sys::RunSignalHandlers() (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x6af0de)
2 0x00007fddcea3d698 SignalHandler(int) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x6b1698)
3 0x00007fddd17bbcb0 __restore_rt (/usr/lib/libpthread.so.0+0x13cb0)
4 0x00007fddcdebb755 __GI_raise (/usr/lib/libc.so.6+0x3a755)
5 0x00007fddcdea6851 __GI_abort (/usr/lib/libc.so.6+0x25851)
6 0x00007fddcdea6727 _nl_load_domain.cold (/usr/lib/libc.so.6+0x25727)
7 0x00007fddcdeb4026 (/usr/lib/libc.so.6+0x33026)
8 0x00007fddcfce5c16 (anonymous namespace)::WasmObjectWriter::writeObject(llvm::MCAssembler&, llvm::MCAsmLayout const&) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x1959c16)
9 0x00007fddcfc94706 llvm::MCAssembler::Finish() (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x1908706)
10 0x00007fddcf20e45c llvm::AsmPrinter::doFinalization(llvm::Module&) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0xe8245c)
11 0x00007fddceb88645 llvm::FPPassManager::doFinalization(llvm::Module&) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x7fc645)
12 0x00007fddceb88c96 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/../lib/libLLVM-9svn.so+0x7fcc96)
13 0x0000000000652ddc clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete >) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0x652ddc)
14 0x0000000000d6b025 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0xd6b025)
15 0x00000000012fecf3 clang::ParseAST(clang::Sema&, bool, bool) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0x12fecf3)
16 0x0000000000b642f0 clang::FrontendAction::Execute() (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0xb642f0)
17 0x0000000000b094f1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0xb094f1)
18 0x0000000000bff12d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0xbff12d)
19 0x0000000000612034 cc1_main(llvm::ArrayRef<char const>, char const, void*) (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0x612034)
20 0x0000000000610084 main (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0x610084)
21 0x00007fddcdea7ee3 __libc_start_main (/usr/lib/libc.so.6+0x26ee3)
22 0x000000000060d329 _start (/home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin/clang-9+0x60d329)
clang-9: error: unable to execute command: Aborted (core dumped) clang-9: error: clang frontend command failed due to signal (use -v to see invocation) clang version 9.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project 922759a63d7d8edbc47578b4718a38765093d24e) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /home/b1ue/b1ue/workdir_vlc/emsdk/upstream/bin clang-9: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script. clang-9: note: diagnostic msg:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-9: note: diagnostic msg: /tmp/interrupt-32bf76.c clang-9: note: diagnostic msg: /tmp/interrupt-32bf76.sh clang-9: note: diagnostic msg: