I want to compile the png library and a small c++ wrapper as a loadable side module. The linking step fails with a wasm-ld crash.
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 5.0.0 (a7c5deabd7c88ba1c38ebe988112256775f944c6)
clang version 23.0.0git (https:/github.com/llvm/llvm-project 358db292cc6a9a8a5448a296f643312289f328d7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/playground/emsdk_5.0.0/emsdk/upstream/bin
The crash can be reproduced without the png (and zlib) libraries. Simply create a file pngerror.c with the following content :
#include "setjmp.h"
extern void call_free(void* ptr);
void png_free_jmpbuf(jmp_buf *jb) {
call_free(jb);
jmp_buf free_jmp_buf;
setjmp(free_jmp_buf);
}
and compile it with
emcc -flto -O0 -fPIC -o pngerror.c.o -c pngerror.c && em++ -o libpng.so -sSIDE_MODULE=1 -fwasm-exceptions pngerror.c.o
This results in the following crash:
LLVM ERROR: Cannot select: 0x5cb09e43b200: ch = catchret 0x5cb09e402fa8, BasicBlock:ch< 0x5cb09e434528>, BasicBlock:ch< 0x5cb09e4343c8>
In function: png_free_jmpbuf
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld -o libpng.so --import-memory --strip-debug --export-dynamic --export=__wasm_call_ctors --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --experimental-pic --unresolved-symbols=import-dynamic -shared --stack-first --whole-archive pngerror.c.o -L/home/playground/emsdk_5.0.0/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -L/home/playground/emsdk_5.0.0/emsdk/upstream/emscripten/src/lib --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -wasm-use-legacy-eh -mllvm -disable-lsr -mllvm -wasm-enable-eh -mllvm -wasm-use-legacy-eh -mllvm -exception-model=wasm
1. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2. Running pass 'WebAssembly Instruction Selection' on function '@png_free_jmpbuf'
#0 0x00005cb079fbb0e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x11560e8)
#1 0x00005cb079fb7e25 llvm::sys::RunSignalHandlers() (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1152e25)
#2 0x00005cb079fbbc96 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007352b6645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007352b669eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007352b669eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007352b669eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007352b664527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007352b66288ff abort ./stdlib/abort.c:81:7
#9 0x00005cb079f18216 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x10b3216)
#10 0x00005cb07aefe4dc llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x20994dc)
#11 0x00005cb07aefda55 (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x2098a55)
#12 0x00005cb07a5c0f7e (anonymous namespace)::WebAssemblyDAGToDAGISel::Select(llvm::SDNode*) (.llvm.406094044484436182) WebAssemblyISelDAGToDAG.cpp:0:0
#13 0x00005cb07aef3e5c llvm::SelectionDAGISel::DoInstructionSelection() (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x208ee5c)
#14 0x00005cb07aef3330 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x208e330)
#15 0x00005cb07aef28ad llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x208d8ad)
#16 0x00005cb07aeef1e7 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x208a1e7)
#17 0x00005cb07aeec4a4 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x20874a4)
#18 0x00005cb07b254723 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x23ef723)
#19 0x00005cb07ce6f393 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x400a393)
#20 0x00005cb07ce7756c llvm::FPPassManager::runOnModule(llvm::Module&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x401256c)
#21 0x00005cb07ce70244 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x400b244)
#22 0x00005cb07aadf2f9 codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) LTOBackend.cpp:0:0
#23 0x00005cb07aaddc3d llvm::lto::backend(llvm::lto::Config const&, std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1c78c3d)
#24 0x00005cb07aabfe0e llvm::lto::LTO::runRegularLTO(std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1c5ae0e)
#25 0x00005cb07aabeea7 llvm::lto::LTO::run(std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, llvm::FileCache) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1c59ea7)
#26 0x00005cb07a4d6e58 lld::wasm::BitcodeCompiler::compile() (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1671e58)
#27 0x00005cb07a4dad34 lld::wasm::SymbolTable::compileBitcodeFiles() (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1675d34)
#28 0x00005cb07a4c0601 lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) Driver.cpp:0:0
#29 0x00005cb07a4bae7a lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x1655e7a)
#30 0x00005cb079fbfc2c lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x115ac2c)
#31 0x00005cb079ef47f1 lld_main(int, char**, llvm::ToolContext const&) (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x108f7f1)
#32 0x00005cb079ef4f14 main (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0x108ff14)
#33 0x00007352b662a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#34 0x00007352b662a28b call_init ./csu/../csu/libc-start.c:128:20
#35 0x00007352b662a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#36 0x00005cb079e5b22a _start (/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld+0xff622a)
em++: error: '/home/playground/emsdk_5.0.0/emsdk/upstream/bin/wasm-ld -o libpng.so --import-memory --strip-debug --export-dynamic --export=__wasm_call_ctors --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --experimental-pic --unresolved-symbols=import-dynamic -shared --stack-first --whole-archive pngerror.c.o -L/home/playground/emsdk_5.0.0/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -L/home/playground/emsdk_5.0.0/emsdk/upstream/emscripten/src/lib --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -wasm-use-legacy-eh -mllvm -disable-lsr -mllvm -wasm-enable-eh -mllvm -wasm-use-legacy-eh -mllvm -exception-model=wasm' failed (received SIGABRT (-6))
Removing one of -flto, -fPIC or -fwasm-exceptions doesn't result in a crash...
I want to compile the png library and a small c++ wrapper as a loadable side module. The linking step fails with a wasm-ld crash.
Version of emscripten/emsdk:
The crash can be reproduced without the png (and zlib) libraries. Simply create a file
pngerror.cwith the following content :and compile it with
emcc -flto -O0 -fPIC -o pngerror.c.o -c pngerror.c && em++ -o libpng.so -sSIDE_MODULE=1 -fwasm-exceptions pngerror.c.oThis results in the following crash:
Removing one of -flto, -fPIC or -fwasm-exceptions doesn't result in a crash...