llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.45k stars 12.18k forks source link

Clang frontend command failed with exit code 139 when compiling to webassembly #97496

Closed sumant85 closed 4 months ago

sumant85 commented 5 months ago

I am getting Clang frontend command failed with exit code 139 when compiling code using setjmp/longjmp to webassembly with emscripten 3.1.62. The same code compiles fine with an older (3.1.44) version of emscripten. The code also compiles if all calls to setjmp/longjmp are removed or if optimization level is set to -O0

Crash artifacts (preprocessed source and script)

Breaking change bisected to https://chromium.googlesource.com/emscripten-releases/+/9e09d60dbf6f5e1e0b4bb97b8aba8c5d5969652a

Backtrace:

0.  Program arguments: /home/code/emscripten/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr --sysroot=/home/code/emscripten/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -I/Users/home/code/libcvd -I/home/code/libcvd/build/include -isystem /home/code/toon/include/toon -isystem /home/code/jpeg/include/S -isystem /home/code/libpng/include/png -isystem //home/code/zlib/include/zlib -fwasm-exceptions -Wno-error=enum-constexpr-conversion -fcolor-diagnostics -Oz -DNDEBUG -std=gnu++20 -fvisibility=hidden -MD -c /home/code/libcvd/cvd_src/image_io/jpeg.cxx -o /tmp/jpeg.cxx.o
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module '/home/code/libcvd/cvd_src/image_io/jpeg.cxx'.
4.  Running pass 'WebAssembly Instruction Selection' on function '@_ZN3CVD4JPEG9ReadPimplC2ERNSt3__213basic_istreamIcNS2_11char_traitsIcEEEE'
 #0 0x000000010616eb48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013eab48)

 #1 0x000000010616c255 llvm::sys::RunSignalHandlers() (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013e8255)
 #2 0x000000010616df0e llvm::sys::CleanupOnSignal(unsigned long) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013e9f0e)
 #3 0x00000001060ca181 CrashRecoverySignalHandler(int) (.llvm.957067972329857832) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101346181)
 #4 0x00007ff818abafdd (/usr/lib/system/libsystem_platform.dylib+0x7ff80046afdd)
 #5 0x000000031507bb20
 #6 0x000000010738dca7 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x102609ca7)
 #7 0x00000001075188d4 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, true>, bool&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1027948d4)
 #8 0x0000000107518432 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x102794432)
 #9 0x00000001075151fc llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1027911fc)
#10 0x000000010751341e llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10278f41e)
#11 0x00000001056d52f8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1009512f8)
#12 0x0000000105c2af05 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100ea6f05)
#13 0x0000000105c34d94 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100eb0d94)
#14 0x0000000105c2bcd5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100ea7cd5)
#15 0x0000000106a9e340 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101d1a340)
#16 0x000000010690306c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101b7f06c)
#17 0x0000000107e2dcf9 clang::ParseAST(clang::Sema&, bool, bool) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1030a9cf9)
#18 0x0000000106e741f5 clang::FrontendAction::Execute() (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1020f01f5)
#19 0x0000000106dae570 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10202a570)
#20 0x0000000106f70a5a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1021eca5a)
#21 0x0000000104e21480 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10009d480)
#22 0x0000000104e1db2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100099b2a)
#23 0x0000000106bee02e void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const::$_0>(long) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e6a02e)
#24 0x00000001060c9ed8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101345ed8)
#25 0x0000000106bed8c3 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e698c3)
#26 0x0000000106ba6d79 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e22d79)
#27 0x0000000106ba705f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&, bool) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e2305f)
#28 0x0000000106bcb730 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e47730)
#29 0x0000000104e1cc33 clang_main(int, char**, llvm::ToolContext const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100098c33)
#30 0x0000000104e2da2c main (/home/code/emsdk/upstream/bin/clang-19+0x1000a9a2c)
#31 0x000000020c21c366
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 19.0.0git (https:/github.com/llvm/llvm-project c00ada070207979f092be9046a02fcfff8b9f9ce)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/code/emscripten/emsdk/upstream/bin
clang++: note: diagnostic msg:
llvmbot commented 5 months ago

@llvm/issue-subscribers-backend-webassembly

Author: Sumant Hanumante (sumant85)

I am getting `Clang frontend command failed with exit code 139` when compiling code using setjmp/longjmp to webassembly with emscripten 3.1.62. The same code compiles fine with an older (3.1.44) version of emscripten. The code also compiles if all calls to setjmp/longjmp are removed or if optimization level is set to `-O0` [Crash artifacts (preprocessed source and script)](https://github.com/user-attachments/files/16075525/crash.zip) Backtrace: ``` 0. Program arguments: /home/code/emscripten/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr --sysroot=/home/code/emscripten/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -I/Users/home/code/libcvd -I/home/code/libcvd/build/include -isystem /home/code/toon/include/toon -isystem /home/code/jpeg/include/S -isystem /home/code/libpng/include/png -isystem //home/code/zlib/include/zlib -fwasm-exceptions -Wno-error=enum-constexpr-conversion -fcolor-diagnostics -Oz -DNDEBUG -std=gnu++20 -fvisibility=hidden -MD -c /home/code/libcvd/cvd_src/image_io/jpeg.cxx -o /tmp/jpeg.cxx.o 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '/home/code/libcvd/cvd_src/image_io/jpeg.cxx'. 4. Running pass 'WebAssembly Instruction Selection' on function '@_ZN3CVD4JPEG9ReadPimplC2ERNSt3__213basic_istreamIcNS2_11char_traitsIcEEEE' #0 0x000000010616eb48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013eab48) #1 0x000000010616c255 llvm::sys::RunSignalHandlers() (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013e8255) #2 0x000000010616df0e llvm::sys::CleanupOnSignal(unsigned long) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1013e9f0e) #3 0x00000001060ca181 CrashRecoverySignalHandler(int) (.llvm.957067972329857832) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101346181) #4 0x00007ff818abafdd (/usr/lib/system/libsystem_platform.dylib+0x7ff80046afdd) #5 0x000000031507bb20 #6 0x000000010738dca7 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x102609ca7) #7 0x00000001075188d4 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, true>, bool&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1027948d4) #8 0x0000000107518432 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x102794432) #9 0x00000001075151fc llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1027911fc) #10 0x000000010751341e llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10278f41e) #11 0x00000001056d52f8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1009512f8) #12 0x0000000105c2af05 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100ea6f05) #13 0x0000000105c34d94 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100eb0d94) #14 0x0000000105c2bcd5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100ea7cd5) #15 0x0000000106a9e340 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__2::unique_ptr<llvm::raw_pwrite_stream, std::__2::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101d1a340) #16 0x000000010690306c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101b7f06c) #17 0x0000000107e2dcf9 clang::ParseAST(clang::Sema&, bool, bool) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1030a9cf9) #18 0x0000000106e741f5 clang::FrontendAction::Execute() (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1020f01f5) #19 0x0000000106dae570 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10202a570) #20 0x0000000106f70a5a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x1021eca5a) #21 0x0000000104e21480 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x10009d480) #22 0x0000000104e1db2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100099b2a) #23 0x0000000106bee02e void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const::$_0>(long) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e6a02e) #24 0x00000001060c9ed8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101345ed8) #25 0x0000000106bed8c3 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__2::optional<llvm::StringRef>>, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>*, bool*) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e698c3) #26 0x0000000106ba6d79 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e22d79) #27 0x0000000106ba705f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&, bool) const (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e2305f) #28 0x0000000106bcb730 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*>>&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x101e47730) #29 0x0000000104e1cc33 clang_main(int, char**, llvm::ToolContext const&) (/home/code/emscripten/emsdk/upstream/bin/clang-19+0x100098c33) #30 0x0000000104e2da2c main (/home/code/emsdk/upstream/bin/clang-19+0x1000a9a2c) #31 0x000000020c21c366 clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation) clang version 19.0.0git (https:/github.com/llvm/llvm-project c00ada070207979f092be9046a02fcfff8b9f9ce) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /home/code/emscripten/emsdk/upstream/bin clang++: note: diagnostic msg: ```
sbc100 commented 5 months ago

@aheejin any ideas what this might be?

@sumant85 any chance you could bisect a little more to figure out exactly which emscripten version caused the regression: https://emscripten.org/docs/contributing/developers_guide.html#bisecting

aheejin commented 5 months ago

I have a suspicion that this is the same issue as https://github.com/emscripten-core/emscripten/issues/22170. The pass that's causing the error is https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp, and the problem is related to generating invalid PHI nodes, which I'm currently investigating. But given that this pass has been stable for a long time, it's a little confusing why two same bug reports are coming at this point. The most recent change to that pass was #84137, but I doubt that PR created another bug.. I think it's possible that PR might have uncovered an existing bug or something. I'm still investigating.

Added: The same error persists even if I revert #84137, so that's not the issue.

sumant85 commented 5 months ago

@sbc100 I've bisected it down to emsdk version 3.1.54 where compilation first started failing. Will do a bisect over emscripten release (per https://emscripten.org/docs/contributing/developers_guide.html#bisecting) and share my findings shortly

sumant85 commented 5 months ago

@sbc100 @aheejin the breaking change is introduced in https://chromium.googlesource.com/emscripten-releases/+/9e09d60dbf6f5e1e0b4bb97b8aba8c5d5969652a

sumant85 commented 4 months ago

@aheejin any other way in which I can help? We'd like to switch to latest emscripten to start experimenting with JSPI (older versions seem to be running into some errors with instrumentWasmImports), but are blocked on this issue.

sumant85 commented 4 months ago

@aheejin should I re-open this since it looks like the PR had to be reverted ?

aheejin commented 4 months ago

It was reapplied: https://github.com/llvm/llvm-project/commit/0af754213507972a0d0301bc195d65414d8dc193