mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.75k stars 176 forks source link

ld.lld.exe segfaulting #418

Closed nidefawl closed 2 months ago

nidefawl commented 3 months ago

Here is a working reproducer for a segfault in lld. I tested 17.0.6 and 18.1.2. Both are crashing. I don't know if this has been reported upstream before.

The crash goes away when I remove either line from the CMakeLists.txt

add_link_options(-Wl,--gc-sections)
add_compile_options(-ffunction-sections -fdata-sections)

It also does not crash when building in release mode without -g

git clone --recursive https://github.com/nidefawl/vst3-lld-crash.git C:\dev\vst3-lld-crash>cmake -G"Ninja Multi-Config" -S . -Bbuild

-- The C compiler identification is Clang 18.1.2
-- The CXX compiler identification is Clang 18.1.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/dev/bin/llvm-mingw-20240320-ucrt-x86_64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/dev/bin/llvm-mingw-20240320-ucrt-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- [SMTG] SMTG_AAX_SDK_PATH is not set. If you need it, please download the AAX SDK!
-- Could NOT find LIBJACK (missing: LIBJACK_LIBRARIES LIBJACK_INCLUDE_DIR) 
-- Performing Test SMTG_USE_STDATOMIC_H
-- Performing Test SMTG_USE_STDATOMIC_H - Success
-- Configuring done (1.6s)
-- Generating done (0.2s)
-- Build files have been written to: C:/dev/vst3-lld-crash/build

C:\dev\vst3-lld-crash>cmake --build build --config Debug --target test_vst3sdk

... 5 warnings generated. [38/38 100% :: 4.379] Linking CXX executable Debug\test_vst3sdk.exe FAILED: Debug/test_vst3sdk.exe C:\WINDOWS\system32\cmd.exe /C "cd . && C:\dev\bin\llvm-mingw-20240320-ucrt-x86_64\bin\clang++.exe -g -Wl,--gc-sections CMakeFiles/test_vst3sdk.dir/Debug/main.cpp.obj -o Debug\test_vst3sdk.exe -Wl,--out-implib,Debug\libtest_vst3sdk.dll.a -Wl,--major-image-version,0,--minor-image-version,0 lib/Debug/libsdk_hosting.a lib/Debug/libsdk_common.a lib/Debug/libbase.a lib/Debug/libpluginterfaces.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Exception Code: 0xC0000005

0 0x00007ff7df950145 (C:\dev\bin\llvm-mingw-20240320-ucrt-x86_64\bin\ld.lld.exe+0x2d0145)

1 0x00007ff95a6d3efd std::1::deque<std::1::function<void ()>, std::1::allocator<std::1::function<void ()>>>::__add_back_capacity() (C:\dev\bin\llvm-mingw-20240320-ucrt-x86_64\bin\libLLVM-18.dll+0xd3efd)

2 0x00007ff95a6d3e0c std::1::deque<std::1::function<void ()>, std::1::allocator<std::1::function<void ()>>>::__add_back_capacity() (C:\dev\bin\llvm-mingw-20240320-ucrt-x86_64\bin\libLLVM-18.dll+0xd3e0c)

3 0x00007ff95a6d27f5 std::1::vector<std::1::thread, std::1::allocator<std::1::thread>>::__append(unsigned long long) (C:\dev\bin\llvm-mingw-20240320-ucrt-x86_64\bin\libLLVM-18.dll+0xd27f5)

4 0x00007ff95a6d29b0 std::1::vector<std::1::thread, std::1::allocator<std::1::thread>>::__append(unsigned long long) (C:\dev\bi

ninja: build stopped: subcommand failed. n\llvm-mingw-20240320-ucrt-x86_64\bin\libLLVM-18.dll+0xd29b0)

5 0x00007ff99df81bb2 (C:\WINDOWS\System32\ucrtbase.dll+0x21bb2)

6 0x00007ff99e377344 (C:\WINDOWS\System32\KERNEL32.DLL+0x17344)

7 0x00007ff9a00826b1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526b1)

clang-18: error: linker command failed due to signal (use -v to see invocation)

mstorsjo commented 3 months ago

Thanks for the report, I've managed to reproduce it. I'll try to look into it a bit later.

mstorsjo commented 2 months ago

I posted a potential fix for this at https://github.com/llvm/llvm-project/pull/88487.

mstorsjo commented 2 months ago

This issue should have been fixed now, in https://github.com/mstorsjo/llvm-mingw/releases/tag/20240417.

nidefawl commented 2 months ago

I can confirm this is fixed in the latest release. Thanks a lot!