llvm / llvm-project

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

lldwasm: Reporting stack dump due to lld crash #114651

Open anutosh491 opened 2 weeks ago

anutosh491 commented 2 weeks ago

1) I am building an executable against emscripten 2) I am making this call target_link_libraries(target PUBLIC ... clangCppInterOp ....)

Now how clangCppInterOp is framed is i) We basically unzip and extract object file out of these using ar/emar x libs

clangInterpreter;lldWasm;clangAST;clangAnalysis;clangBasic;clangCodeGen;clangDriver;clangFrontend;clangFrontendTool;clangLex;clangParse;clangSema;clangSerialization;LLVMCore;LLVMMC;LLVMOption;LLVMOrcJIT;LLVMOrcDebugging;LLVMOrcShared;LLVMOrcTargetProcess;LLVMSupport;LLVMTarget;LLVMTargetParser;LLVMWebAssemblyCodeGen;LLVMWebAssemblyAsmParser;LLVMWebAssemblyDesc;LLVMWebAssemblyDisassembler;LLVMWebAssemblyInfo;LLVMWebAssemblyUtils;lldCommon;LLVMBinaryFormat;LLVMDemangle;LLVMLTO;LLVMObject;LLVMPasses;LLVMFrontendOpenMP;clangASTMatchers;LLVMAggressiveInstCombine;LLVMAnalysis;LLVMBitReader;LLVMBitWriter;LLVMCodeGenTypes;LLVMCoroutines;LLVMCoverage;LLVMExtensions;LLVMFrontendDriver;LLVMFrontendHLSL;LLVMFrontendOffloading;LLVMHipStdPar;LLVMipo;LLVMIRPrinter;LLVMIRReader;LLVMInstCombine;LLVMInstrumentation;LLVMLinker;LLVMObjCARCOpts;LLVMProfileData;LLVMScalarOpts;LLVMTransformUtils;LLVMWindowsDriver;clangAPINotes;clangEdit;LLVMBitstreamReader;clangExtractAPI;clangRewriteFrontend;clangARCMigrate;clangStaticAnalyzerFrontend;LLVMMCParser;clangSupport;LLVMRemarks;LLVMDebugInfoCodeView;LLVMExecutionEngine;LLVMJITLink;LLVMRuntimeDyld;LLVMDebugInfoDWARF;LLVMAsmPrinter;LLVMCodeGen;LLVMSelectionDAG;LLVMMCDisassembler;LLVMTextAPI;LLVMCFGuard;LLVMVectorize;LLVMAsmParser;LLVMSymbolize;clangIndex;clangInstallAPI;clangRewrite;clangCrossTU;clangStaticAnalyzerCheckers;clangStaticAnalyzerCore;LLVMDebugInfoPDB;LLVMDebugInfoBTF;clangFormat;clangToolingCore;LLVMTextAPIBinaryReader;LLVMDebugInfoMSF;clangToolingInclusions, LLVMSupport

All these are static libraries obtained from a wasm build for llvm

ii) Then we club these into a final libclangCppInterOp.a using ar/emar qc ...

Now when i move onto my executable using clangCppInterOp (linking with it) .... although the build works I end up getting this error. It says maybe reporting the crash would help

[100%] Linking CXX executable xcpp.js
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/wasm-ld -o xcpp.wasm --whole-archive CMakeFiles/xcpp.dir/src/main_emscripten_kernel.cpp.o /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus-lite.a libxeus-cpp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libclangCppInterOp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libpugixml.a -L/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lembind-rtti -lGL -lal -lhtml5 -lstubs -lc-asan -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -lasan_rt -lasan_js -lubsan_rt -llsan_common_rt -lsanitizer_common_rt --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=malloc --export-if-defined=__errno_location --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=memcpy --export-if-defined=free --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=emscripten_builtin_memalign --export-if-defined=__cxa_is_pointer_type --export-if-defined=setTempRet0 --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__get_exception_message --export-if-defined=fileno --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=sleep --export-if-defined=__getTypeName /var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/tmpzt4d3u33libemscripten_js_symbols.so --import-undefined --import-memory --strip-debug --export-dynamic --export-if-defined=main --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_argc_argv --export-if-defined=__wasm_apply_data_relocs --export-if-defined=fflush --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__errno_location --export-if-defined=memalign --export-if-defined=emscripten_builtin_memalign --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=_asan_c_load_1 --export-if-defined=_asan_c_load_1u --export-if-defined=_asan_c_load_2 --export-if-defined=_asan_c_load_2u --export-if-defined=_asan_c_load_4 --export-if-defined=_asan_c_load_4u --export-if-defined=_asan_c_load_f --export-if-defined=_asan_c_load_d --export-if-defined=_asan_c_store_1 --export-if-defined=_asan_c_store_1u --export-if-defined=_asan_c_store_2 --export-if-defined=_asan_c_store_2u --export-if-defined=_asan_c_store_4 --export-if-defined=_asan_c_store_4u --export-if-defined=_asan_c_store_f --export-if-defined=_asan_c_store_d --export-if-defined=__funcs_on_exit --export-if-defined=malloc --export-if-defined=free --export-if-defined=__cxa_is_pointer_type --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=setThrew --export-if-defined=__cxa_free_exception --export-if-defined=__wasm_call_ctors --experimental-pic -pie -z stack-size=67108864 --initial-memory=575275008 --max-memory=2147483648 --no-entry
 #0 0x0000000102365e50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100125e50)
 #1 0x0000000102363e60 llvm::sys::RunSignalHandlers() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100123e60)
 #2 0x0000000102366a24 SignalHandler(int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100126a24)
 #3 0x0000000195057584 (/usr/lib/system/libsystem_platform.dylib+0x180477584)
 #4 0x00000001026bc38c lld::wasm::ElemSection::writeBody() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x10047c38c)
 #5 0x00000001026d4454 lld::wasm::SyntheticSection::finalizeContents() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100494454)
 #6 0x00000001026d0330 lld::wasm::(anonymous namespace)::Writer::run() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100490330)
 #7 0x00000001026c7174 lld::wasm::writeResult() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100487174)
 #8 0x00000001026960b8 lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1004560b8)
 #9 0x00000001026921ac lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1004521ac)
#10 0x0000000102377144 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100137144)
#11 0x00000001022c156c lld_main(int, char**, llvm::ToolContext const&) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x10008156c)
#12 0x00000001022c1bf0 main (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100081bf0)
#13 0x0000000194c9e0e0 
em++: error: '/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/wasm-ld -o xcpp.wasm --whole-archive CMakeFiles/xcpp.dir/src/main_emscripten_kernel.cpp.o /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus-lite.a libxeus-cpp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libclangCppInterOp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libpugixml.a -L/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lembind-rtti -lGL -lal -lhtml5 -lstubs -lc-asan -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -lasan_rt -lasan_js -lubsan_rt -llsan_common_rt -lsanitizer_common_rt --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=malloc --export-if-defined=__errno_location --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=memcpy --export-if-defined=free --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=emscripten_builtin_memalign --export-if-defined=__cxa_is_pointer_type --export-if-defined=setTempRet0 --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__get_exception_message --export-if-defined=fileno --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=sleep --export-if-defined=__getTypeName /var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/tmpzt4d3u33libemscripten_js_symbols.so --import-undefined --import-memory --strip-debug --export-dynamic --export-if-defined=main --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_argc_argv --export-if-defined=__wasm_apply_data_relocs --export-if-defined=fflush --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__errno_location --export-if-defined=memalign --export-if-defined=emscripten_builtin_memalign --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=_asan_c_load_1 --export-if-defined=_asan_c_load_1u --export-if-defined=_asan_c_load_2 --export-if-defined=_asan_c_load_2u --export-if-defined=_asan_c_load_4 --export-if-defined=_asan_c_load_4u --export-if-defined=_asan_c_load_f --export-if-defined=_asan_c_load_d --export-if-defined=_asan_c_store_1 --export-if-defined=_asan_c_store_1u --export-if-defined=_asan_c_store_2 --export-if-defined=_asan_c_store_2u --export-if-defined=_asan_c_store_4 --export-if-defined=_asan_c_store_4u --export-if-defined=_asan_c_store_f --export-if-defined=_asan_c_store_d --export-if-defined=__funcs_on_exit --export-if-defined=malloc --export-if-defined=free --export-if-defined=__cxa_is_pointer_type --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=setThrew --export-if-defined=__cxa_free_exception --export-if-defined=__wasm_call_ctors --experimental-pic -pie -z stack-size=67108864 --initial-memory=575275008 --max-memory=2147483648 --no-entry' failed (received SIGSEGV (-11))
make[2]: *** [xcpp.js] Error 1
make[1]: *** [CMakeFiles/xcpp.dir/all] Error 2
make: *** [all] Error 2
emmake: error: 'make install' failed (returned 2)

Not sure what might be the reason behind this !

llvmbot commented 2 weeks ago

@llvm/issue-subscribers-lld-wasm

Author: Anutosh Bhat (anutosh491)

1) I am building an executable against emscripten 2) I am making this call `target_link_libraries(target PUBLIC ... clangCppInterOp ....)` Now how `clangCppInterOp` is framed is i) We basically unzip and extract object file out of these using `ar/emar x libs` ``` clangInterpreter;lldWasm;clangAST;clangAnalysis;clangBasic;clangCodeGen;clangDriver;clangFrontend;clangFrontendTool;clangLex;clangParse;clangSema;clangSerialization;LLVMCore;LLVMMC;LLVMOption;LLVMOrcJIT;LLVMOrcDebugging;LLVMOrcShared;LLVMOrcTargetProcess;LLVMSupport;LLVMTarget;LLVMTargetParser;LLVMWebAssemblyCodeGen;LLVMWebAssemblyAsmParser;LLVMWebAssemblyDesc;LLVMWebAssemblyDisassembler;LLVMWebAssemblyInfo;LLVMWebAssemblyUtils;lldCommon;LLVMBinaryFormat;LLVMDemangle;LLVMLTO;LLVMObject;LLVMPasses;LLVMFrontendOpenMP;clangASTMatchers;LLVMAggressiveInstCombine;LLVMAnalysis;LLVMBitReader;LLVMBitWriter;LLVMCodeGenTypes;LLVMCoroutines;LLVMCoverage;LLVMExtensions;LLVMFrontendDriver;LLVMFrontendHLSL;LLVMFrontendOffloading;LLVMHipStdPar;LLVMipo;LLVMIRPrinter;LLVMIRReader;LLVMInstCombine;LLVMInstrumentation;LLVMLinker;LLVMObjCARCOpts;LLVMProfileData;LLVMScalarOpts;LLVMTransformUtils;LLVMWindowsDriver;clangAPINotes;clangEdit;LLVMBitstreamReader;clangExtractAPI;clangRewriteFrontend;clangARCMigrate;clangStaticAnalyzerFrontend;LLVMMCParser;clangSupport;LLVMRemarks;LLVMDebugInfoCodeView;LLVMExecutionEngine;LLVMJITLink;LLVMRuntimeDyld;LLVMDebugInfoDWARF;LLVMAsmPrinter;LLVMCodeGen;LLVMSelectionDAG;LLVMMCDisassembler;LLVMTextAPI;LLVMCFGuard;LLVMVectorize;LLVMAsmParser;LLVMSymbolize;clangIndex;clangInstallAPI;clangRewrite;clangCrossTU;clangStaticAnalyzerCheckers;clangStaticAnalyzerCore;LLVMDebugInfoPDB;LLVMDebugInfoBTF;clangFormat;clangToolingCore;LLVMTextAPIBinaryReader;LLVMDebugInfoMSF;clangToolingInclusions, LLVMSupport ``` All these are static libraries obtained from a wasm build for llvm ii) Then we club these into a final `libclangCppInterOp.a` using `ar/emar qc ...` Now when i move onto my executable using `clangCppInterOp` (linking with it) .... although the build works I end up getting this error. It says maybe reporting the crash would help ``` [100%] Linking CXX executable xcpp.js PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/wasm-ld -o xcpp.wasm --whole-archive CMakeFiles/xcpp.dir/src/main_emscripten_kernel.cpp.o /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus-lite.a libxeus-cpp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libclangCppInterOp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libpugixml.a -L/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lembind-rtti -lGL -lal -lhtml5 -lstubs -lc-asan -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -lasan_rt -lasan_js -lubsan_rt -llsan_common_rt -lsanitizer_common_rt --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=malloc --export-if-defined=__errno_location --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=memcpy --export-if-defined=free --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=emscripten_builtin_memalign --export-if-defined=__cxa_is_pointer_type --export-if-defined=setTempRet0 --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__get_exception_message --export-if-defined=fileno --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=sleep --export-if-defined=__getTypeName /var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/tmpzt4d3u33libemscripten_js_symbols.so --import-undefined --import-memory --strip-debug --export-dynamic --export-if-defined=main --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_argc_argv --export-if-defined=__wasm_apply_data_relocs --export-if-defined=fflush --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__errno_location --export-if-defined=memalign --export-if-defined=emscripten_builtin_memalign --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=_asan_c_load_1 --export-if-defined=_asan_c_load_1u --export-if-defined=_asan_c_load_2 --export-if-defined=_asan_c_load_2u --export-if-defined=_asan_c_load_4 --export-if-defined=_asan_c_load_4u --export-if-defined=_asan_c_load_f --export-if-defined=_asan_c_load_d --export-if-defined=_asan_c_store_1 --export-if-defined=_asan_c_store_1u --export-if-defined=_asan_c_store_2 --export-if-defined=_asan_c_store_2u --export-if-defined=_asan_c_store_4 --export-if-defined=_asan_c_store_4u --export-if-defined=_asan_c_store_f --export-if-defined=_asan_c_store_d --export-if-defined=__funcs_on_exit --export-if-defined=malloc --export-if-defined=free --export-if-defined=__cxa_is_pointer_type --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=setThrew --export-if-defined=__cxa_free_exception --export-if-defined=__wasm_call_ctors --experimental-pic -pie -z stack-size=67108864 --initial-memory=575275008 --max-memory=2147483648 --no-entry #0 0x0000000102365e50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100125e50) #1 0x0000000102363e60 llvm::sys::RunSignalHandlers() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100123e60) #2 0x0000000102366a24 SignalHandler(int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100126a24) #3 0x0000000195057584 (/usr/lib/system/libsystem_platform.dylib+0x180477584) #4 0x00000001026bc38c lld::wasm::ElemSection::writeBody() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x10047c38c) #5 0x00000001026d4454 lld::wasm::SyntheticSection::finalizeContents() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100494454) #6 0x00000001026d0330 lld::wasm::(anonymous namespace)::Writer::run() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100490330) #7 0x00000001026c7174 lld::wasm::writeResult() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100487174) #8 0x00000001026960b8 lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1004560b8) #9 0x00000001026921ac lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1004521ac) #10 0x0000000102377144 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100137144) #11 0x00000001022c156c lld_main(int, char**, llvm::ToolContext const&) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x10008156c) #12 0x00000001022c1bf0 main (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100081bf0) #13 0x0000000194c9e0e0 em++: error: '/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/wasm-ld -o xcpp.wasm --whole-archive CMakeFiles/xcpp.dir/src/main_emscripten_kernel.cpp.o /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus-lite.a libxeus-cpp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libclangCppInterOp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libpugixml.a -L/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lembind-rtti -lGL -lal -lhtml5 -lstubs -lc-asan -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -lasan_rt -lasan_js -lubsan_rt -llsan_common_rt -lsanitizer_common_rt --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=malloc --export-if-defined=__errno_location --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=memcpy --export-if-defined=free --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=emscripten_builtin_memalign --export-if-defined=__cxa_is_pointer_type --export-if-defined=setTempRet0 --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__get_exception_message --export-if-defined=fileno --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=sleep --export-if-defined=__getTypeName /var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/tmpzt4d3u33libemscripten_js_symbols.so --import-undefined --import-memory --strip-debug --export-dynamic --export-if-defined=main --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_argc_argv --export-if-defined=__wasm_apply_data_relocs --export-if-defined=fflush --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__errno_location --export-if-defined=memalign --export-if-defined=emscripten_builtin_memalign --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=_asan_c_load_1 --export-if-defined=_asan_c_load_1u --export-if-defined=_asan_c_load_2 --export-if-defined=_asan_c_load_2u --export-if-defined=_asan_c_load_4 --export-if-defined=_asan_c_load_4u --export-if-defined=_asan_c_load_f --export-if-defined=_asan_c_load_d --export-if-defined=_asan_c_store_1 --export-if-defined=_asan_c_store_1u --export-if-defined=_asan_c_store_2 --export-if-defined=_asan_c_store_2u --export-if-defined=_asan_c_store_4 --export-if-defined=_asan_c_store_4u --export-if-defined=_asan_c_store_f --export-if-defined=_asan_c_store_d --export-if-defined=__funcs_on_exit --export-if-defined=malloc --export-if-defined=free --export-if-defined=__cxa_is_pointer_type --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=setThrew --export-if-defined=__cxa_free_exception --export-if-defined=__wasm_call_ctors --experimental-pic -pie -z stack-size=67108864 --initial-memory=575275008 --max-memory=2147483648 --no-entry' failed (received SIGSEGV (-11)) make[2]: *** [xcpp.js] Error 1 make[1]: *** [CMakeFiles/xcpp.dir/all] Error 2 make: *** [all] Error 2 emmake: error: 'make install' failed (returned 2) ``` Not sure what might be the reason behind this !
EugeneZelenko commented 2 weeks ago

@anutosh491: Could you please provide reproducer?

anutosh491 commented 2 weeks ago

Hmm, don't have an immediate minimalistic repoducer but if you are looking for the command responsible for this I have shared it above /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/wasm-ld -o xcpp.wasm --whole-archive CMakeFiles/xcpp.dir/src/main_emscripten_kernel.cpp.o /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus-lite.a libxeus-cpp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libxeus.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libclangCppInterOp.a /Users/anutosh491/micromamba/envs/xeus-cpp-wasm-host/lib/libpugixml.a -L/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic -lembind-rtti -lGL -lal -lhtml5 -lstubs -lc-asan -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -lasan_rt -lasan_js -lubsan_rt -llsan_common_rt -lsanitizer_common_rt --no-whole-archive -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export-if-defined=setThrew --export-if-defined=malloc --export-if-defined=__errno_location --export-if-defined=htons --export-if-defined=ntohs --export-if-defined=memcpy --export-if-defined=free --export-if-defined=htonl --export-if-defined=_emscripten_timeout --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=emscripten_builtin_memalign --export-if-defined=__cxa_is_pointer_type --export-if-defined=setTempRet0 --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__get_exception_message --export-if-defined=fileno --export-if-defined=__dl_seterr --export-if-defined=memcmp --export-if-defined=sleep --export-if-defined=__getTypeName /var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/tmpzt4d3u33libemscripten_js_symbols.so --import-undefined --import-memory --strip-debug --export-dynamic --export-if-defined=main --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_argc_argv --export-if-defined=__wasm_apply_data_relocs --export-if-defined=fflush --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__errno_location --export-if-defined=memalign --export-if-defined=emscripten_builtin_memalign --export-if-defined=emscripten_builtin_malloc --export-if-defined=emscripten_builtin_free --export-if-defined=_asan_c_load_1 --export-if-defined=_asan_c_load_1u --export-if-defined=_asan_c_load_2 --export-if-defined=_asan_c_load_2u --export-if-defined=_asan_c_load_4 --export-if-defined=_asan_c_load_4u --export-if-defined=_asan_c_load_f --export-if-defined=_asan_c_load_d --export-if-defined=_asan_c_store_1 --export-if-defined=_asan_c_store_1u --export-if-defined=_asan_c_store_2 --export-if-defined=_asan_c_store_2u --export-if-defined=_asan_c_store_4 --export-if-defined=_asan_c_store_4u --export-if-defined=_asan_c_store_f --export-if-defined=_asan_c_store_d --export-if-defined=__funcs_on_exit --export-if-defined=malloc --export-if-defined=free --export-if-defined=__cxa_is_pointer_type --export-if-defined=__cxa_can_catch --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=setThrew --export-if-defined=__cxa_free_exception --export-if-defined=__wasm_call_ctors --experimental-pic -pie -z stack-size=67108864 --initial-memory=575275008 --max-memory=2147483648 --no-entry

anutosh491 commented 2 weeks ago

Using 3.1.45-asserts gives us some more info

Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /opt/s/w/ir/cache/builder/emscripten-releases/llvm-project/llvm/include/llvm/Support/Casting.h, line 578.
......
 #0 0x0000000106ccffac llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/lib/libLLVM.dylib+0x15bfac)
 #1 0x0000000106ccdfb4 llvm::sys::RunSignalHandlers() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/lib/libLLVM.dylib+0x159fb4)
 #2 0x0000000106cd0620 SignalHandler(int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/lib/libLLVM.dylib+0x15c620)
 #3 0x0000000195057584 (/usr/lib/system/libsystem_platform.dylib+0x180477584)
 #4 0x0000000195026c20 (/usr/lib/system/libsystem_pthread.dylib+0x180446c20)
 #5 0x0000000194f33a30 (/usr/lib/system/libsystem_c.dylib+0x180353a30)
 #6 0x0000000194f32d20 (/usr/lib/system/libsystem_c.dylib+0x180352d20)
 #7 0x00000001024fb690 lld::wasm::FunctionSymbol::setFunctionIndex(unsigned int) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x10031f690)
 #8 0x0000000102503cc4 lld::wasm::ElemSection::writeBody() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100327cc4)
 #9 0x000000010251ede8 lld::wasm::SyntheticSection::finalizeContents() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100342de8)
#10 0x000000010251aab4 lld::wasm::(anonymous namespace)::Writer::run() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x10033eab4)
#11 0x0000000102512ad8 lld::wasm::writeResult() (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100336ad8)
#12 0x00000001024d9a98 lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1002fda98)
#13 0x00000001024d62c0 lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1002fa2c0)
#14 0x00000001021def20 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100002f20)
#15 0x00000001021dda64 lld_main(int, char**, llvm::ToolContext const&) (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x100001a64)
#16 0x00000001021de0dc main (/Users/anutosh491/micromamba/envs/xeus-cpp-wasm-build/lib/python3.13/site-packages/emsdk/upstream/bin/lld+0x1000020dc)
#17 0x0000000194c9e0e0 
sbc100 commented 2 weeks ago

One way to share a reproducer for a crash in wasm-ld is it add the --reproduce=filename.tar to the linker flags. For clang flags that would be -Wl,--reproduce=filename.tar.

anutosh491 commented 2 weeks ago

Ohh didn't know about this flag. Shall give it a try and get back

Untill then these are somethings I could observe

1) I see quite some similar issues on emscripten/llvm. Some of them were raised with a LTO context and I see some fixes relevant fixes were made too (https://github.com/llvm/llvm-project/pull/73095). Now although the issue being encountered is the same (isa<To>(Val) && "cast<Ty>() argument of incompatible type!") I haven't used the lto flag anywhere (would using that help ... my attempt says not really)

3) I was not sure about some flags and hence was just experimenting around i) Also just getting rid of libclangCppInterOp.a in the linking step atleast gives us xcpp.js and xcpp.wasm (although we obviously need to link against it ... not sure this confirms if the error comes out of libclangCppInterOp.a) ii) getting rid of the whole-archive and the no-whole-archive flags doesn't help (and also moving libclangCppInterOp.a in and out) iii) Increasing max-memory from 2GB to 4GB ( --max-memory=4294967296) didn't help

sbc100 commented 2 weeks ago

Ohh didn't know about this flag. Shall give it a try and get back

Untill then these are somethings I could observe

  1. I see quite some similar issues on emscripten/llvm. Some of them were raised with a LTO context and I see some fixes relevant fixes were made too ([lld][WebAssembly] Fix bitcode LTO order in archive parsing #73095). Now although the issue being encountered is the same (isa<To>(Val) && "cast<Ty>() argument of incompatible type!") I haven't used the lto flag anywhere (would using that help ... my attempt says not really)

No, adding LTO would only complicate things.

  1. I was not sure about some flags and hence was just experimenting around i) Also just getting rid of libclangCppInterOp.a in the linking step atleast gives us xcpp.js and xcpp.wasm (although we obviously need to link against it ... not sure this confirms if the error comes out of libclangCppInterOp.a) ii) getting rid of the whole-archive and the no-whole-archive flags doesn't help (and also moving libclangCppInterOp.a in and out) iii) Increasing max-memory from 2GB to 4GB ( --max-memory=4294967296) didn't help

I think this bug needs to be addressed regardless of any workaround you might be able to find.

anutosh491 commented 2 weeks ago

Hey @sbc100 @EugeneZelenko as suggested I ran the build against the reproduce flag and generated a .tar file.

I hope this would be enough as a repoducer. Please let me know.

Also as we can't upload/share files above 25MB on github, the only way I could achieve this was through making a dummy repo followed by a dummy release (https://github.com/anutosh491/lld-crash/releases/tag/trial) . The file is present at the above link, let me know if something else is required.

anutosh491 commented 1 week ago

Hey @sbc100 Did you have a chance to go through my reproducer ?

Can't say if the above is exactly what you were looking for (just followed your instructions above) ... Maybe let me know if I am missing something ?!