<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61765>61765</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            LLD: segmentation fault while linking mingw-x86_64 static libraries with LTO
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sztomi
      </td>
    </tr>
</table>

<pre>
    I'm running into a crash in lld while linking a certain project. I noticed this crash in LLVM 15.0.7 but it also reproduced with 16.0.0. 

I rebuilt lld in a debug config (in hopes of a somewhat better stacktrace) but it doesn't contain that much more information:

```
Stack dump:
0.      Program arguments: /home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld --sysroot=/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32 -m i386pep -Bdynamic -o bin/EasyAudioEncoder.exe /home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32/lib/crt2.o /home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32/lib/crtbegin.o -L/home/tamas/.conan_plex/.conan/data/libuv/1.9.2-b3209ba1-15/plex/stable/package/1da38749d7d69a41e19333c02769694399b64f4a/lib -L/home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib -L/home/tamas/.conan_plex/.conan/data/bzip2/1.0.6-37/plex/stable/package/50c9c82d1a46779ce81d2758efb770934195d011/lib -L/home/tamas/.conan_plex/.conan/data/zlib/1.2.11-31/plex/stable/package/1da38749d7d69a41e19333c02769694399b64f4a/lib -L/home/tamas/.conan_plex/.conan/data/iconv/1.16-31/plex/stable/package/74a075e40b20cf7758a936e74675f60019744b66/lib -L/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../lib/x86_64-w64-windows-gnu -L/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32/x86_64-w64-mingw32/lib -L/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32/x86_64-w64-mingw32/mingw/lib -L/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32/lib -L/home/tamas/.plex_toolchain/16.0.0+6610dc6da/lib/clang/16/lib/x86_64-w64-windows-gnu -lunwind --gc-sections -O2 watchfolder/CMakeFiles/EasyAudioEncoder.dir/codec.cpp.obj watchfolder/CMakeFiles/EasyAudioEncoder.dir/codec_ddp_udc.cpp.obj watchfolder/CMakeFiles/EasyAudioEncoder.dir/codec_truehd_dec.cpp.obj watchfolder/CMakeFiles/EasyAudioEncoder.dir/codec_ddp_enc.cpp.obj watchfolder/CMakeFiles/EasyAudioEncoder.dir/main.cpp.obj watchfolder/CMakeFiles/EasyAudioEncoder.dir/wav.cpp.obj watchfolder/CMakeFiles/EasyAudioEncoder.dir/sha-256.c.obj --out-implib lib/libEasyAudioEncoder.dll.a --major-image-version 0 --minor-image-version 0 lib/libdolby_ddp_dec.a lib/libdolby_ddp_enc.a lib/libdolby_truehd_dec.a lib/libdolby_intrinsics.a -lpthread /home/tamas/.conan_plex/.conan/data/libuv/1.9.2-b3209ba1-15/plex/stable/package/1da38749d7d69a41e19333c02769694399b64f4a/lib/uv.lib -lws2_32 -liphlpapi -luserenv -lpsapi /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_atomic.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_chrono.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_date_time.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_filesystem.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_iostreams.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_json.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_program_options.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_random.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_regex.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_system.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_thread.lib /home/tamas/.conan_plex/.conan/data/boost/1.81.0-11/plex/stable/package/42723bcf168290e3f1e46c1cfbd7557f5536c919/lib/boost_timer.lib -lbcrypt /home/tamas/.conan_plex/.conan/data/bzip2/1.0.6-37/plex/stable/package/50c9c82d1a46779ce81d2758efb770934195d011/lib/bz2.lib /home/tamas/.conan_plex/.conan/data/zlib/1.2.11-31/plex/stable/package/1da38749d7d69a41e19333c02769694399b64f4a/lib/z.lib /home/tamas/.conan_plex/.conan/data/iconv/1.16-31/plex/stable/package/74a075e40b20cf7758a936e74675f60019744b66/lib/charset.lib /home/tamas/.conan_plex/.conan/data/iconv/1.16-31/plex/stable/package/74a075e40b20cf7758a936e74675f60019744b66/lib/iconv.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -Bstatic -lc++ -Bdynamic -lmingw32 /home/tamas/.plex_toolchain/16.0.0+6610dc6da/lib/clang/16/lib/x86_64-w64-windows-gnu/libclang_rt.builtins.a -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 /home/tamas/.plex_toolchain/16.0.0+6610dc6da/lib/clang/16/lib/x86_64-w64-windows-gnu/libclang_rt.builtins.a -lmoldname -lmingwex -lmsvcrt -lkernel32 /home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/../targets/x86_64-w64-mingw32/lib/crtend.o
 #0 0x0000556dc35da1e6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x36d61e6)
 #1 0x0000556dc35da6ab (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x36d66ab)
 #2 0x0000556dc35d893d llvm::sys::RunSignalHandlers() (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x36d493d)
 #3 0x0000556dc35db793 (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x36d7793)
 #4 0x00007ff2d5c3bcf0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bcf0)
 #5 0x0000556dc599c909 (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x5a98909)
 #6 0x0000556dc5981138 (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x5a7d138)
 #7 0x0000556dc596bc72 (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x5a67c72)
 #8 0x0000556dc341cb25 llvm::LowerTypeTestsPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x3518b25)
 #9 0x0000556dc341cab4 (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x3518ab4)
#10 0x0000556dc34921e4 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x358e1e4)
#11 0x0000556dc4ed317e (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x4fcf17e)
#12 0x0000556dc4ed260a llvm::lto::opt(llvm::lto::Config const&, llvm::TargetMachine*, unsigned int, llvm::Module&, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*, std::__2::vector<unsigned char, std::__2::allocator<unsigned char>> const&) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x4fce60a)
#13 0x0000556dc4ed33a9 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/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x4fcf3a9)
#14 0x0000556dc4ea7701 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/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x4fa3701)
#15 0x0000556dc4ea6998 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&)>, std::__2::function<llvm::Expected<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::StringRef, llvm::Twine const&)>) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x4fa2998)
#16 0x0000556dc36c7665 lld::coff::BitcodeCompiler::compile() (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x37c3665)
#17 0x0000556dc36e31f8 lld::coff::SymbolTable::compileBitcodeFiles() (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x37df1f8)
#18 0x0000556dc361a96c lld::coff::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x371696c)
#19 0x0000556dc3614056 lld::coff::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x3710056)
#20 0x0000556dc3bae1b4 lld::mingw::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x3caa1b4)
#21 0x0000556dc34f3e2c (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x35efe2c)
#22 0x0000556dc348e051 lld_main(int, char**) (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x358a051)
#23 0x0000556dc348dfb2 main (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x3589fb2)
#24 0x00007ff2d5c23510 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#25 0x00007ff2d5c235c9 call_init ./csu/../csu/libc-start.c:128:20
#26 0x00007ff2d5c235c9 __libc_start_main ./csu/../csu/libc-start.c:368:5
#27 0x0000556dc34ddbd1 _start (/home/tamas/.plex_toolchain/16.0.0+6610dc6da/bin/ld.lld+0x35d9bd1)
```

I tried minimizing the command line, but removing libraries causes it fail before LTO. Other flags (like `-Bdynamic` and `-O2`) seemed to have no effect. 

The mingw commit I initially used was `d0dec04461345121f7079d62e07f036ca7446c6c` but `0f2264e7b8fedbe225921367e82aeb97ddfed46b` also reproduces the issue (the latter I picked from @mstorsjo's llvm-mingw repo). 

Another interesting bit is that this does not happen on x86, only x86_64. 

Any advice on minimizing the repro would be appreciated (all components that being compiled here are open source, too). 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW19v27iy_zTKC2FBIiVKesiDm9a4BVJ0sQ3uq0GRI5sNReqSVBzvp78g5SSW69PuaZ3dnLNAEFMiZ-Y3_8ghJTHn5EYDXCflu6R8f8VGvzX22v3hTS-vWiP21x8TXPXIjlpLvUFSe4MY4pa5LZIaKSXQbisVICX1fRjBEAfrmdRosOYrcJ-ij0gbLzkI5LfSvRDf3v7vJ5SXaZZWqB09kh4x5QyyMFgjxkCwk36LcppmaZaiJHufZMvp_0dkoR2l8hGC1IghAe24QdzoTm5Qgmup0dYM4JDpEEPO9LDbMo9a8B4scp7xe28ZhwQ3T-KFAacTXPnAJirhA0k_8i3qjQUkdWdsz7w0OiHLY0AJzQ5_8fJLYI_E2A_P47I0yZrfrNlY1iNmN2MP2ruELFGCV1vTQ4JXnvXMJXiVDgoe194YxbdM6gSvJiMk-B2leSY4FSzBqzZ2KZEGIywWbu-sMT4h73-RY5pGSrsBH2gfa7qmxWJHi0Uv9WZHMFr0SJKaDjCgxTux16yXHC0Mmug_MLdfjkKaD5obATaFR_hVLX-IKVhCtglecetxav5SeS1spE4NWtyekcqNZnodZD9fJXglmGcTi_EhIEmbFC9agrOmZfkiLxO8OpA4z1oVOA6M37NNaOWCkboqGlEJ2rAih7whhPAMV7ShTUGapqVFVxwE_ASs1hjnI6w6T7NFnn8XToErTFre5bTGTQaky6GgPOddK6qyrLqyJJQ3efPzcP6QA45wspQuSPVdNGXGG15jkbOCVlXDoc4FrsoauraqsoYUeVOKLKr0c2j-mPyepzjN8wX5vm1e3VWSGz1FUE5_BKYqWFaVUGQtznhXVWXNGkKhKmhVdjTL8qYqipbS74H5t5NostZRAu2kFmbnFhs9XkjED_L0XyXv3yg9tv5KFL8o6DDVKaY3ccgP_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