emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.55k stars 3.27k forks source link

ICE with ThinLTO #15432

Open DoDoENT opened 2 years ago

DoDoENT commented 2 years ago

I'm experimenting with using ThinLTO instead of monolithic LTO for my builds. However, when building my code with ThinLTO enabled, I get the following crash:

/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/em++ -O3 -DNDEBUG -s STRICT=1 -s MALLOC=emmalloc -s WASM=1 -s PTHREAD_POOL_SIZE=0 -s USE_PTHREADS=1 -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy -s INITIAL_MEMORY=209715200 -s MAXIMUM_MEMORY=838860800 -s STRICT=0 -s SUPPORT_ERRNO=0 -msimd128 -s ASSERTIONS=0 -s STACK_OVERFLOW_CHECK=0 --closure 1 -s IGNORE_CLOSURE_COMPILER_ERRORS=1 -O3 -flto=thin -Wl,--thinlto-cache-dir=/Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.33-advanced-simd-threads/release/lto.cache -Wl,--thinlto-jobs=all -s DISABLE_EXCEPTION_CATCHING=1 --pre-js /Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.33-advanced-simd-threads/release/wasmthreadhelper.js --emrun --preload-file /Users/dodo/Work/Microblink/Builds/core-neural-network/emscripten-2.0.33-advanced-simd-threads/release/NNUnitTests-res@/ CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/main.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Add.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/BoxTripletFusor.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/CoarseKeypointMatching.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Concat.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Convolution.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/CropAndResizeBilinear.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/CropAndResizeKeypoints.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/DepthwiseConvolution.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/DetectionPostprocessing.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Einsum.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ExpandDims.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/FC.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/GlobalAveragePooling.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/GlobalMaxPooling.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ImageAdjust.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ImageCentralCrop.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ImageCropToAspectRatio.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ImageOutputPostprocessing.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ImageResize.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/LayerNorm.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/LineOCRPostprocessing.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/MaxPooling.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Mul.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/PositionalEncoding.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Preprocessing.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Proposal.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/QuadDetectionPostProcessing.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ReduceMax.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ReduceSum.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Reshape.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ROIAlign.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/ROIPooling.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Sigmoid.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Sinkhorn.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Softmax.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/SpatialExpectation2D.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/TensorResize.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Layers/Upscale2xNN.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/BufferData.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/Hardware.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/Image.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/Inputs.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/MathematicalObjects.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/MemoryMonitor.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/ModelBuilderTest.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/EinsumFormulaParser.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/Padding.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/PrimitiveBestFit.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/QuadDetectionResultRotation.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/String.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/Utils.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/Postprocessing.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/UnitTests/DebugResult.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Utils/Data.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Utils/Expectors.cpp.o CMakeFiles/NNUnitTests.dir/NNUnitTests/Source/Tests/Utils/LayerForward.cpp.o CMakeFiles/NNUnitTests.dir/wasmThreadLimit.cpp.o CMakeFiles/NNUnitTests.dir/Users/dodo/.conan/data/VersionAndPaths/2.2.0/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/Paths.cpp.o CMakeFiles/NNUnitTests.dir/Users/dodo/.conan/data/VersionAndPaths/2.2.0/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/version.cpp.o -o bin/NNUnitTests.html  lib/libBufferData.a  lib/libHardwareInfo.a  lib/libMemoryMonitor.a  lib/libNNModelBuilderLib.a  lib/libNeuralNetwork.a  lib/libTFReader.a  lib/libTelemetry.a  /Users/dodo/.conan/data/TensorFlow/1.13.1.7/microblink/stable/package/8c33b68afd7c189a1398db061a0fffefba931439/lib/libTensorFlow.a  /Users/dodo/.conan/data/Protobuf/3.13.3/microblink/stable/package/97ef2861601bf6968459f53ddb9fa6c664c84a27/lib/libprotobuf-lite.a  /Users/dodo/.conan/data/Protobuf/3.13.3/microblink/stable/package/97ef2861601bf6968459f53ddb9fa6c664c84a27/lib/libprotobuf.a  lib/libBufferData.a  lib/libNeuralNetwork.a  lib/libMemoryMonitor.a  /Users/dodo/.conan/data/XNNPACK/20210616.1/microblink/stable/package/6a3e709b599442a83a4ea350c7afef2851910adc/lib/libXNNPACK.a  /Users/dodo/.conan/data/Protection/10.0.2/microblink/stable/package/5c09109a8ebbea11c7065510543c852e9db56984/lib/libProtection.a  /Users/dodo/.conan/data/Hash/8.0.3/microblink/stable/package/f452476940c585d877838cdfd918971803cbd5c7/lib/libHash.a  /Users/dodo/.conan/data/MicroECC/2.0.1/microblink/stable/package/97ef2861601bf6968459f53ddb9fa6c664c84a27/lib/libMicroECC.a  --bind  lib/libNNUtils.a  /Users/dodo/.conan/data/CoreUtils/8.0.0/microblink/stable/package/743b1eac71af9dee88f7488b9a5a8fbf426c52d6/lib/libCoreUtils.a  /Users/dodo/.conan/data/OpenCV/4.5.3.1/microblink/stable/package/5201d8ac0e988aa9006addf923417b891578f6d6/lib/libopencv_imgproc.a  /Users/dodo/.conan/data/OpenCV/4.5.3.1/microblink/stable/package/5201d8ac0e988aa9006addf923417b891578f6d6/lib/libopencv_core.a  /Users/dodo/.conan/data/CVParallelFor/1.3.5/microblink/stable/package/ee51baaa1276b7bd79858294dbe6732855c61504/lib/libCVParallelFor.a  /Users/dodo/.conan/data/LogAndTimer/2.1.8/microblink/stable/package/1b68a1022ab7ea21b45aebba237fa0b2cf6bc967/lib/libLogAndTimer.a  /Users/dodo/.conan/data/Sweater/10.1.0/microblink/stable/package/3a523ed3a17bb295e44bd8f47da137f5aff3f596/lib/libpthreadpool.a  /Users/dodo/.conan/data/Sweater/10.1.0/microblink/stable/package/3a523ed3a17bb295e44bd8f47da137f5aff3f596/lib/libSweatShop.a  /Users/dodo/.conan/data/cpuinfo/3.0.4/microblink/stable/package/018b01f29ee14620abcb123d984bf08e23e5007b/lib/libcpuinfo.a  /Users/dodo/.conan/data/cpuinfo/3.0.4/microblink/stable/package/018b01f29ee14620abcb123d984bf08e23e5007b/lib/libclog.a  /Users/dodo/.conan/data/libjpeg-turbo/2.1.1/microblink/stable/package/c66be85e85fe0ae3ac63cdf045f1f794e6ba2c58/lib/libjpeg.a  /Users/dodo/.conan/data/libpng/1.6.37.1/microblink/stable/package/4ee85ef7a5871c0b896593de63f56359eecf4567/lib/libpng16.a  /Users/dodo/.conan/data/Zlib/1.2.11/microblink/stable/package/e00f0c1a7fb02114f4d26521d79b1c8a6709204b/lib/libzlibstatic.a  /Users/dodo/.conan/data/icu/69.1.4/microblink/stable/package/c66be85e85fe0ae3ac63cdf045f1f794e6ba2c58/lib/libicuuc.a  /Users/dodo/.conan/data/icu/69.1.4/microblink/stable/package/c66be85e85fe0ae3ac63cdf045f1f794e6ba2c58/lib/libicudata.a  /Users/dodo/.conan/data/GTest/1.10.0.15/microblink/stable/package/c66be85e85fe0ae3ac63cdf045f1f794e6ba2c58/lib/libgtest_main.a  /Users/dodo/.conan/data/GTest/1.10.0.15/microblink/stable/package/c66be85e85fe0ae3ac63cdf045f1f794e6ba2c58/lib/libgtest.a && :
em++: warning: USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libc-mt.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libc-mt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libcompiler_rt-mt.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libcompiler_rt-mt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libc++-mt-noexcept.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libc++-mt-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libc++abi-mt-noexcept.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libc++abi-mt-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libemmalloc-mt-noerrno.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libemmalloc-mt-noerrno.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libc_rt_wasm-mt.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libc_rt_wasm-mt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/thinlto/libsockets-mt.a... (this will be cached in "/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/thinlto/libsockets-mt.a" for subsequent builds)
cache:INFO:  - ok
WidenVectorResult #0: t193: v48f32 = llvm.matrix.transpose nnan ninf nsz arcp contract afn reassoc TargetConstant:i32<187>, t528, TargetConstant:i32<8>, TargetConstant:i32<6>

Do not know how to widen the result of this operator!
UNREACHABLE executed at /opt/s/w/ir/cache/builder/emscripten-releases/llvm-project/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:3035!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Running pass 'Function Pass Manager' on module 'lib/libNeuralNetwork.a(Winograd.cpp.o at 1283406)'.
1.      Running pass 'WebAssembly Instruction Selection' on function '@_ZN2MB2NN6Layers10Production12Convolutions15Winograd3x3BaseILi6EE22InverseTransformerBase9transformEPNS1_16FixedSizedMatrixILt6ELt6EfEE'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.dylib            0x00000001150150db llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1  libLLVM.dylib            0x0000000115013ea8 llvm::sys::RunSignalHandlers() + 248
2  libLLVM.dylib            0x0000000115015740 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff8074e7e2d _sigtramp + 29
4  libsystem_platform.dylib 0x000070000e344530 _sigtramp + 18446726515998967584
5  libsystem_c.dylib        0x00007ff80741ed10 abort + 123
6  libLLVM.dylib            0x0000000114f3af43 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 467
7  libLLVM.dylib            0x00000001158b022d llvm::DAGTypeLegalizer::WidenVectorResult(llvm::SDNode*, unsigned int) + 1389
8  libLLVM.dylib            0x0000000115882bb8 llvm::DAGTypeLegalizer::run() + 2568
9  libLLVM.dylib            0x000000011588813e llvm::SelectionDAG::LegalizeTypes() + 1438
10 libLLVM.dylib            0x0000000115994468 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 1576
11 libLLVM.dylib            0x0000000115993476 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 8566
12 libLLVM.dylib            0x000000011598feca llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 2474
13 libLLVM.dylib            0x000000011544ea6e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 366
14 libLLVM.dylib            0x0000000115197227 llvm::FPPassManager::runOnFunction(llvm::Function&) + 919
15 libLLVM.dylib            0x000000011519fb81 llvm::FPPassManager::runOnModule(llvm::Module&) + 65
16 libLLVM.dylib            0x0000000115197978 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1288
17 libLLVM.dylib            0x00000001168b80bc codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) + 1292
18 libLLVM.dylib            0x00000001168b8f8a llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::StringMap<std::__2::unordered_set<unsigned long long, std::__2::hash<unsigned long long>, std::__2::equal_to<unsigned long long>, std::__2::allocator<unsigned long long> >, llvm::MallocAllocator> const&, llvm::DenseMap<unsigned long long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long long>, llvm::detail::DenseMapPair<unsigned long long, llvm::GlobalValueSummary*> > const&, llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::__2::vector<std::__2::pair<llvm::StringRef, llvm::BitcodeModule>, std::__2::allocator<std::__2::pair<llvm::StringRef, llvm::BitcodeModule> > > >*, std::__2::vector<unsigned char, std::__2::allocator<unsigned char> > const&)::$_2::operator()(llvm::Module&, llvm::TargetMachine*, std::__2::unique_ptr<llvm::ToolOutputFile, std::__2::default_delete<llvm::ToolOutputFile> >) const + 170
19 libLLVM.dylib            0x00000001168b8e0f llvm::lto::thinBackend(llvm::lto::Config const&, unsigned int, std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)>, llvm::Module&, llvm::ModuleSummaryIndex const&, llvm::StringMap<std::__2::unordered_set<unsigned long long, std::__2::hash<unsigned long long>, std::__2::equal_to<unsigned long long>, std::__2::allocator<unsigned long long> >, llvm::MallocAllocator> const&, llvm::DenseMap<unsigned long long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long long>, llvm::detail::DenseMapPair<unsigned long long, llvm::GlobalValueSummary*> > const&, llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::__2::vector<std::__2::pair<llvm::StringRef, llvm::BitcodeModule>, std::__2::allocator<std::__2::pair<llvm::StringRef, llvm::BitcodeModule> > > >*, std::__2::vector<unsigned char, std::__2::allocator<unsigned char> > const&) + 2911
20 libLLVM.dylib            0x00000001168b1a37 (anonymous namespace)::InProcessThinBackend::runThinLTOBackendThread(std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)>, std::__2::function<std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)> (unsigned int, llvm::StringRef)>, unsigned int, llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::StringMap<std::__2::unordered_set<unsigned long long, std::__2::hash<unsigned long long>, std::__2::equal_to<unsigned long long>, std::__2::allocator<unsigned long long> >, llvm::MallocAllocator> const&, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo> > const&, std::__2::map<unsigned long long, llvm::GlobalValue::LinkageTypes, std::__2::less<unsigned long long>, std::__2::allocator<std::__2::pair<unsigned long long const, llvm::GlobalValue::LinkageTypes> > > const&, llvm::DenseMap<unsigned long long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long long>, llvm::detail::DenseMapPair<unsigned long long, llvm::GlobalValueSummary*> > const&, llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::__2::vector<std::__2::pair<llvm::StringRef, llvm::BitcodeModule>, std::__2::allocator<std::__2::pair<llvm::StringRef, llvm::BitcodeModule> > > >&)::'lambda'(std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)>)::operator()(std::__2::function<std::__2::unique_ptr<llvm::NativeObjectStream, std::__2::default_delete<llvm::NativeObjectStream> > (unsigned int)>) const + 279
21 libLLVM.dylib            0x00000001168b1872 void std::__2::__function::__policy_invoker<void ()>::__call_impl<std::__2::__function::__default_alloc_func<std::__2::__bind<(anonymous namespace)::InProcessThinBackend::start(unsigned int, llvm::BitcodeModule, llvm::StringMap<std::__2::unordered_set<unsigned long long, std::__2::hash<unsigned long long>, std::__2::equal_to<unsigned long long>, std::__2::allocator<unsigned long long> >, llvm::MallocAllocator> const&, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo> > const&, std::__2::map<unsigned long long, llvm::GlobalValue::LinkageTypes, std::__2::less<unsigned long long>, std::__2::allocator<std::__2::pair<unsigned long long const, llvm::GlobalValue::LinkageTypes> > > const&, llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::__2::vector<std::__2::pair<llvm::StringRef, llvm::BitcodeModule>, std::__2::allocator<std::__2::pair<llvm::StringRef, llvm::BitcodeModule> > > >&)::'lambda'(llvm::BitcodeModule, llvm::ModuleSummaryIndex&, llvm::StringMap<std::__2::unordered_set<unsigned long long, std::__2::hash<unsigned long long>, std::__2::equal_to<unsigned long long>, std::__2::allocator<unsigned long long> >, llvm::MallocAllocator> const&, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo> > const&, std::__2::map<unsigned long long, llvm::GlobalValue::LinkageTypes, std::__2::less<unsigned long long>, std::__2::allocator<std::__2::pair<unsigned long long const, llvm::GlobalValue::LinkageTypes> > > const&, llvm::DenseMap<unsigned long long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long long>, llvm::detail::DenseMapPair<unsigned long long, llvm::GlobalValueSummary*> > const&, llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::__2::vector<std::__2::pair<llvm::StringRef, llvm::BitcodeModule>, std::__2::allocator<std::__2::pair<llvm::StringRef, llvm::BitcodeModule> > > >&), llvm::BitcodeModule&, std::__2::reference_wrapper<llvm::ModuleSummaryIndex>, std::__2::reference_wrapper<llvm::StringMap<std::__2::unordered_set<unsigned long long, std::__2::hash<unsigned long long>, std::__2::equal_to<unsigned long long>, std::__2::allocator<unsigned long long> >, llvm::MallocAllocator> const>, std::__2::reference_wrapper<llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo> > const>, std::__2::reference_wrapper<std::__2::map<unsigned long long, llvm::GlobalValue::LinkageTypes, std::__2::less<unsigned long long>, std::__2::allocator<std::__2::pair<unsigned long long const, llvm::GlobalValue::LinkageTypes> > > const>, std::__2::reference_wrapper<llvm::DenseMap<unsigned long long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long long>, llvm::detail::DenseMapPair<unsigned long long, llvm::GlobalValueSummary*> > const>, std::__2::reference_wrapper<llvm::MapVector<llvm::StringRef, llvm::BitcodeModule, llvm::DenseMap<llvm::StringRef, unsigned int, llvm::DenseMapInfo<llvm::StringRef>, llvm::detail::DenseMapPair<llvm::StringRef, unsigned int> >, std::__2::vector<std::__2::pair<llvm::StringRef, llvm::BitcodeModule>, std::__2::allocator<std::__2::pair<llvm::StringRef, llvm::BitcodeModule> > > > > >, void ()> >(std::__2::__function::__policy_storage const*) + 1458
22 libLLVM.dylib            0x0000000114fb1ff6 void* llvm::thread::ThreadProxy<std::__2::tuple<llvm::ThreadPool::ThreadPool(llvm::ThreadPoolStrategy)::$_0> >(void*) + 678
23 libsystem_pthread.dylib  0x00007ff8074d2514 _pthread_start + 125
24 libsystem_pthread.dylib  0x00007ff8074ce02f thread_start + 15
em++: error: '/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/bin/wasm-ld @/var/folders/w1/67dfjvfs6sd66rd33brg4d5r0000gn/T/emscripten_8ykc1_lm.rsp' failed (received SIGABRT (-6))

Unfortunately, I don't have the minimum reproducible case at the moment and the crash happens with proprietary code that I'm not at liberty to share. I hope the stack trace will be enough for you to determine the cause of the crash.

Emscripten version: 2.0.33 Host: Mac OS Monterey

Note: The exact same crash happens also with Android NDK r23

sbc100 commented 2 years ago

Interesting, since this happens with Android too it seems likely to be an upstream bug in llvm. Do you have local/desktop build you could try with tip-of-tree llvm and thisLTO to confirm this?

DoDoENT commented 2 years ago

Do you have local/desktop build you could try with tip-of-tree llvm and thinLTO to confirm this?

I can try with desktop build using upstream LLVM 13, but I guess that emscripten uses more recent version of LLVM.

I can try building the tip-of-tree LLVM, but not this week (it takes quite a time to build it on my machine...).

sbc100 commented 2 years ago

Great. I think it would be interesting to see if LLVM 13 has this issue. Do you happen to know what version of llvm is shipped in Android NDK r23?

I'm guessing you can't test with older versions of emscripten because we had other issues that prevented you running a thinLTO build?

DoDoENT commented 2 years ago

Great. I think it would be interesting to see if LLVM 13 has this issue. Do you happen to know what version of llvm is shipped in Android NDK r23?

r23 is based on LLVM 12. But so is Xcode 13, which (at least for Intel Mac) builds the same code correctly using ThinLTO (haven't tested iOS and M1 mac build yet).

I'm guessing you can't test with older versions of emscripten because we had other issues that prevented you running a thinLTO build?

Correct, see this issue and this issue (for the second one I still haven't tested with thinLTO, but I since it's a binaryen issue, it's probably present).

Note that by using full LTO I don't get crash (neither on emscripten nor with Android NDK), but the linking time is rather long - this is why I'm experimenting with ThinLTO in the first place, after a suggestion by Danila Kutenin (@danlark1) from this CppCon talk.

DoDoENT commented 2 years ago

Same crash also on LLVM 13 linux.

My guess is that it's somehow lld-related, since it works on Mac, where ld64 is used instead of lld.

DoDoENT commented 2 years ago

Interestingly, if I put -flto on files that define symbols for which instruction selection triggers the crash above, I can get Android and Linux build to work (most of the files are still under ThinLTO, which gives good compilation times - only several files are under monolithic LTO regime).

Unfortunately, on emscripten, this causes a different crash - this time in parser (?!?). However, I believe that this is something 2.0.33-related, as the same file could be normally parsed and compiled with 2.0.31 (the last emscripten that I can successfully use, but only with monolithic LTO).

The parser stack trace is (unfortunately I'm not at liberty of sharing the source code, even in preprocessed form):

Assertion failed: ((D.hasGlobalStorage() || (D.hasLocalStorage() && CGF.getContext().getLangOpts().OpenCLCPlusPlus)) && "VarDecl must have global or local (in the case of OpenCL) storage!"), function EmitDeclInit, file /opt/s/w/ir/cache/builder/emscripten-releases/llvm-project/clang/lib/CodeGen/CGDeclCXX.cpp, line 33.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=33 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/dodo/.conan/data/emsdk_installer/2.0.33/microblink/stable/package/743cf0321be3152777da4d05247a66d1552e70a2/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -DALL_KEYS -DALL_SYMMETRIC_KEYS -DBOOST_NO_EXCEPTIONS -DBOOST_NO_RTTI -DBOOST_SWEATER_EXACT_WORKER_SELECTION=1 -DBOOST_SWEATER_SPIN_BEFORE_SUSPENSION=0 -DBOOST_SWEATER_USE_CALLER_THREAD=1 -DEIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS=16 -DEIGEN_CMAKE_INCLUDED -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=std::int32_t -DEIGEN_DEFAULT_TO_ROW_MAJOR -DEIGEN_FAST_MATH -DEIGEN_MAX_STATIC_ALIGN_BYTES=16 -DEIGEN_MPL2_ONLY -DEIGEN_NO_AUTOMATIC_RESIZING -DEIGEN_STACK_ALLOCATION_LIMIT=0 -DENABLE_RESULT_SIGNATURE -DLOG_LEVEL=0 -DMB_ACCELERATE_Multithreaded=2 -DMB_ACCELERATE_Off=0 -DMB_ACCELERATE_Singlethreaded=1 -DMB_NN_API_BUILD=1 -DMB_NN_DLL=1 -DMB_NN_XNNPACK=1 -DMB_NOEXCEPT_EXCEPT_BADALLOC=TNUN_NOEXCEPT_EXCEPT_BADALLOC -DMB_USE_ACCELERATE=MB_ACCELERATE_Off -DNN_ALIGNED_MODELS -DNN_GRAPH_PER_LAYER_DEBUGGING=1 -DNN_MODEL_DEFAULT_ALIGNMENT=8 -DNN_MODEL_EXTENSION=.strop -DNN_USE_PROTECTION=1 -DNN_WINOGRAD=1 -DPRODUCT_ID=MB::Protection::Product::MicroBlinkCore -DPROTECT -DTNUN_MALLOC_OVERCOMMIT=TNUN_OVERCOMMIT_Partial -DTNUN_NOEXCEPT_EXCEPT_BADALLOC= -DTNUN_OVERCOMMIT_Disabled=0 -DTNUN_OVERCOMMIT_Full=2 -DTNUN_OVERCOMMIT_Partial=1 -DU_EXPORT= -DuECC_SUPPORTS_secp160r1=0 -DuECC_SUPPORTS_secp192r1=0 -DuECC_SUPPORTS_secp224r1=0 -DuECC_SUPPORTS_secp256r1=0 -DuECC_SUPPORTS_secp521r1=0 -I/Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source -I/Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Include -I/Users/dodo/Work/Microblink/core-neural-network/NNUtils/Source -I/Users/dodo/Work/Microblink/core-neural-network/NNUtils/Include -I/Users/dodo/Work/Microblink/core-neural-network/MemoryMonitor/Source -I/Users/dodo/Work/Microblink/core-neural-network/MemoryMonitor/Include -isystem /Users/dodo/.conan/data/Eigen/3.3.9.2/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/Eigen/3.3.9.2/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/unsupported -isystem /Users/dodo/.conan/data/CoreUtils/8.0.0/microblink/stable/package/743b1eac71af9dee88f7488b9a5a8fbf426c52d6/include -isystem /Users/dodo/.conan/data/CMakeBuild/17.0.0/nenad/testing/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/LogAndTimer/2.1.8/microblink/stable/package/1b68a1022ab7ea21b45aebba237fa0b2cf6bc967/include -isystem /Users/dodo/.conan/data/Boost/1.75.1/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/ConfigEx/1.0.4/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/Functionoid/3.0.5/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/Pimpl/1.0.3/microblink/stable/package/5a2681c47898ec950d41f4e071da2bbe213d4d2d/include -isystem /Users/dodo/.conan/data/RapidJSON/1.1.5/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/UTFCpp/3.1.1/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/Sweater/10.1.0/microblink/stable/package/3a523ed3a17bb295e44bd8f47da137f5aff3f596/include -isystem /Users/dodo/.conan/data/cpuinfo/3.0.4/microblink/stable/package/018b01f29ee14620abcb123d984bf08e23e5007b/include -isystem /Users/dodo/.conan/data/ConcurrentQueue/3.0.2/microblink/stable/package/12895d81e42ab236ed6e3b6c1cbda7b1120b44cb/include -isystem /Users/dodo/.conan/data/Err/1.1.4/microblink/stable/package/12895d81e42ab236ed6e3b6c1cbda7b1120b44cb/include -isystem /Users/dodo/.conan/data/OpenCV/4.5.3.1/microblink/stable/package/5201d8ac0e988aa9006addf923417b891578f6d6/include -isystem /Users/dodo/.conan/data/MMap/0.3.1/microblink/stable/package/295bf22980c266f264805adb55ba01c37880f102/include -isystem /Users/dodo/.conan/data/icu/69.1.4/microblink/stable/package/c66be85e85fe0ae3ac63cdf045f1f794e6ba2c58/include -isystem /Users/dodo/.conan/data/range-v3/0.10.0/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/Obfuscation/0.1.1/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/Hash/8.0.3/microblink/stable/package/f452476940c585d877838cdfd918971803cbd5c7/include -isystem /Users/dodo/.conan/data/VersionAndPaths/2.2.0/microblink/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include -isystem /Users/dodo/.conan/data/XNNPACK/20210616.1/microblink/stable/package/6a3e709b599442a83a4ea350c7afef2851910adc/include -isystem /Users/dodo/.conan/data/Protection/10.0.2/microblink/stable/package/5c09109a8ebbea11c7065510543c852e9db56984/include -isystem /Users/dodo/.conan/data/MicroECC/2.0.1/microblink/stable/package/97ef2861601bf6968459f53ddb9fa6c664c84a27/include -O3 -DNDEBUG -fvisibility-inlines-hidden -fstrict-aliasing -fstrict-enums -fvisibility=hidden -fvisibility-inlines-hidden -fPIC -std=gnu++2a -Wheader-guard -fdiagnostics-color -fenable-matrix -fno-PIC -mmutable-globals -mbulk-memory -mnontrapping-fptoint -msign-ext -msimd128 -fomit-frame-pointer -ffunction-sections -fmerge-all-constants -fno-stack-protector -DNDEBUG -fno-unwind-tables -fno-asynchronous-unwind-tables -flto=thin -fno-exceptions -fno-rtti -fno-threadsafe-statics -ffast-math -ffp-contract=fast -Wall -Wextra -Wstrict-aliasing -Wdocumentation -Werror -Wno-error=deprecated-declarations -Wno-error=#warnings -Wno-error=unknown-attributes -Wno-unused-command-line-argument -include/Users/dodo/.conan/data/CMakeBuild/17.0.0/nenad/testing/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/banned.h -O3 -fvectorize -fslp-vectorize -funroll-loops -Wno-sign-compare -std=gnu++20 -flto -MD -MT CMakeFiles/NeuralNetwork.dir/NeuralNetwork/Source/Math/biased_matmul.cpp.o -MF CMakeFiles/NeuralNetwork.dir/NeuralNetwork/Source/Math/biased_matmul.cpp.o.d -c -pthread /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp -o CMakeFiles/NeuralNetwork.dir/NeuralNetwork/Source/Math/biased_matmul.cpp.o
1.      /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp:1362:148: current parser token ';'
2.      /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp:28:1: parsing namespace 'MB'
3.      /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp:31:1: parsing namespace 'MB::Math'
4.      /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp:1322:6: instantiating function definition 'MB::Math::biased_matmul_st_block<MB::Math::Postprocessing::NOP>'
5.      /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp:1322:6: LLVM IR generation of declaration 'MB::Math::biased_matmul_st_block'
6.      /Users/dodo/Work/Microblink/core-neural-network/NeuralNetwork/Source/Math/biased_matmul.cpp:1322:6: Generating code for declaration 'MB::Math::biased_matmul_st_block'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.dylib            0x0000000115f6e0db llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1  libLLVM.dylib            0x0000000115f6cea8 llvm::sys::RunSignalHandlers() + 248
2  libLLVM.dylib            0x0000000115f6d510 llvm::sys::CleanupOnSignal(unsigned long) + 208
3  libLLVM.dylib            0x0000000115e8048a (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 106
4  libLLVM.dylib            0x0000000115e8067e CrashRecoverySignalHandler(int) + 110
5  libsystem_platform.dylib 0x00007ff8074e7e2d _sigtramp + 29
6  libsystem_platform.dylib 0x00007ff7b44f6948 _sigtramp + 18446744072317102904
7  libsystem_c.dylib        0x00007ff80741ed10 abort + 123
8  libsystem_c.dylib        0x00007ff80741e0be err + 0
9  libclang-cpp.dylib       0x000000011033f64a clang::CodeGen::CodeGenFunction::EmitCXXGlobalVarDeclInit(clang::VarDecl const&, llvm::Constant*, bool) + 3178
10 libclang-cpp.dylib       0x00000001105c8c43 (anonymous namespace)::ItaniumCXXABI::EmitGuardedInit(clang::CodeGen::CodeGenFunction&, clang::VarDecl const&, llvm::GlobalVariable*, bool) + 2563
11 libclang-cpp.dylib       0x000000011033285d clang::CodeGen::CodeGenFunction::AddInitializerToStaticVarDecl(clang::VarDecl const&, llvm::GlobalVariable*) + 701
12 libclang-cpp.dylib       0x00000001103310cf clang::CodeGen::CodeGenFunction::EmitStaticVarDecl(clang::VarDecl const&, llvm::GlobalValue::LinkageTypes) + 255
13 libclang-cpp.dylib       0x00000001103341e7 clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) + 855
14 libclang-cpp.dylib       0x0000000110330df5 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) + 293
15 libclang-cpp.dylib       0x0000000110330801 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) + 369
16 libclang-cpp.dylib       0x00000001104c23eb clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) + 155
17 libclang-cpp.dylib       0x00000001104b6cd2 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) + 594
18 libclang-cpp.dylib       0x00000001104b5be4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) + 164
19 libclang-cpp.dylib       0x00000001104c34c0 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) + 512
20 libclang-cpp.dylib       0x0000000110526e4e clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 1630
21 libclang-cpp.dylib       0x000000011054603e clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 446
22 libclang-cpp.dylib       0x000000011053e978 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 488
23 libclang-cpp.dylib       0x0000000110542c95 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) + 1237
24 libclang-cpp.dylib       0x000000011054a5eb clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 2603
25 libclang-cpp.dylib       0x00000001105e9ddf (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 159
26 libclang-cpp.dylib       0x0000000110518c15 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 181
27 libclang-cpp.dylib       0x0000000110130b5f clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) + 2911
28 libclang-cpp.dylib       0x000000010ffe8038 clang::Sema::ActOnExplicitInstantiation(clang::Scope*, clang::SourceLocation, clang::SourceLocation, clang::Declarator&) + 5080
29 libclang-cpp.dylib       0x000000010f13b36c clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) + 412
30 libclang-cpp.dylib       0x000000010f13c9f9 clang::Parser::ParseDeclarationAfterDeclarator(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&) + 105
31 libclang-cpp.dylib       0x000000010f1ff444 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 2628
32 libclang-cpp.dylib       0x000000010f1fd305 clang::Parser::ParseExplicitInstantiation(clang::DeclaratorContext, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 181
33 libclang-cpp.dylib       0x000000010f1fd17a clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 282
34 libclang-cpp.dylib       0x000000010f130ea6 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) + 726
35 libclang-cpp.dylib       0x000000010f21268f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 175
36 libclang-cpp.dylib       0x000000010f155601 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) + 209
37 libclang-cpp.dylib       0x000000010f154f8a clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) + 7386
38 libclang-cpp.dylib       0x000000010f130f22 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) + 850
39 libclang-cpp.dylib       0x000000010f21268f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 175
40 libclang-cpp.dylib       0x000000010f155601 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) + 209
41 libclang-cpp.dylib       0x000000010f154f8a clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) + 7386
42 libclang-cpp.dylib       0x000000010f130f22 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) + 850
43 libclang-cpp.dylib       0x000000010f21268f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 175
44 libclang-cpp.dylib       0x000000010f210c28 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) + 1176
45 libclang-cpp.dylib       0x000000010f1191ad clang::ParseAST(clang::Sema&, bool, bool) + 749
46 libclang-cpp.dylib       0x0000000110b297e3 clang::FrontendAction::Execute() + 99
47 libclang-cpp.dylib       0x0000000110aa407f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 831
48 libclang-cpp.dylib       0x0000000110bae26c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 540
49 clang-14                 0x000000010ba0817e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1438
50 clang-14                 0x000000010ba05ddb ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) + 283
51 libclang-cpp.dylib       0x000000011075b027 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >*, bool*) const::$_1>(long) + 23
52 libLLVM.dylib            0x0000000115e8039c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 236
53 libclang-cpp.dylib       0x000000011075aa91 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >*, bool*) const + 305
54 libclang-cpp.dylib       0x0000000110725926 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const + 726
55 libclang-cpp.dylib       0x0000000110725d5d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*> >&) const + 125
56 libclang-cpp.dylib       0x000000011073f01c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__2::pair<int, clang::driver::Command const*> >&) + 396
57 clang-14                 0x000000010ba053f4 main + 10868
58 dyld                     0x000000011a2b14fe start + 462
sbc100 commented 2 years ago

One difference with emscripten is that we also do LTO of the all the system libraries too. Can you try disabling that to see if that makes the problem go away.

(To do this you would need to modity get_base_cflags in tools/system_libs.py and remove the flags += ['-flto=' + settings.LTO] line and then run emcc --clear-cache).. when the cache rebuilds the system libs should be non-LTO

DoDoENT commented 2 years ago

I can try that next week but I don't have high hopes that it will help as the same crash also happens on Android NDK where the system libraries are not built with -flto (I've built them manually for our case, but kept the possibility to use the default ones just in case a client requires us to link an ABI-compatible system lib).

I've tried both using default system NDK libs and my own (that are built with LTO) and a crash happened in both cases.

Same crash also on LLVM 13 Linux.

My guess is that it's somehow lld-related since it works on Mac, where ld64 is used instead of lld.

I also plan to test using gold instead of LLD next week. I have a hunch that this is LLD-related because both Xcode 13 and Android NDK r23 are built from similar commits. My assumption is based on the bug that we encountered on both NDK r23 and Xcode 13, which is, ironically, also LTO-related. Furthermore, the files on which I had to put -flto to work around this issue, as described above, are also heavy users of clang's builtin matrix support.

🤔, maybe those two bugs are somehow related.

Have a nice weekend!

DoDoENT commented 2 years ago

Unfortunately, on emscripten, this causes a different crash - this time in parser (?!?). However, I believe that this is something 2.0.33-related, as the same file could be normally parsed and compiled with 2.0.31 (the last emscripten that I can successfully use, but only with monolithic LTO).

I've reported this as a new issue and I've been successful in creating a repro case for that.

DoDoENT commented 2 years ago

I also plan to test using gold instead of LLD next week. I have a hunch that this is LLD-related because both Xcode 13 and Android NDK r23 are built from similar commits

The hunch was wrong - I get the same crash also when using gold 😞 (tested on Linux since NDK dropped support for gold and emscripten never had it (AFAIK)).

DoDoENT commented 2 years ago

Just found this on Twitter - it's got a very similar stack trace to ours and it's reported here (crash in DAG legalizer).