-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows lld hangs when multi-threading is enabled #855
Comments
@pirama-arumuga-nainar @stephenhines the upstream the OP mentioned seems unlikely considering that it was marked fixed in October 2017... any thoughts on this? |
I believe this is related to this bug in winpthreads: https://sourceforge.net/p/mingw-w64/bugs/774/ It's pretty easy to work around within LLVM with a change like this: There's another similar bug with LLD threading on Windows (https://reviews.llvm.org/D53968), that only happens if the core LLVM libraries are linked in a different DLL than LLD, but that doesn't seem to be the case within the NDK so that's not the issue here. The reason for winpthreads being involved at all is that libstdc++ requires it for implementing C++11 threads, which LLVM/LLD rely on. A completely different approach, with larger effort of course, would be to build the NDK with a toolchain with libc++ instead of libstdc++. My own mingw toolchains at https://github.com/mstorsjo/llvm-mingw are set up that way (and use clang/lld and other llvm tools throughout the whole toolchain). |
@mstorsjo Thanks for pointing this out. Didn't realize the connection to winpthreads. The windows Clang builds are still being built with gcc-4.8/libstdc++. My plan is to move to using Clang/libc++/win32-threads within this quarter. That should circumvent this issue. |
It would of course be good to verify that this really is the culprit before jumping to conclusions. But the symtoms do match (hanging sometimes but not always). |
We won't be getting a new toolchain in the next week, so moving to r21. |
This only affects ndk-build because CMake can't currently check if it is using LLD since our toolchain file has finished running by the time the user can add ldflags. Not enabling this with standalone toolchains since we can't enable it for the built in toolchains without recompiling Clang and those are supposed to match. Will disable in the driver in a follow up if a workaround is not found. Test: ./checkbuild.py Bug: android/ndk#855 Change-Id: I4a24166adce463bea47ca4bf0e97d5375c69f40e (cherry picked from commit 144b244)
`cmake` 3.10 is the current version of the tool in the Android SDK, an update from the much older 3.6. This update brings it closer to the host `cmake` versions (currently mostly 3.12.*) Bump NDK to release [19b][0] (a.k.a. 19.1), with the following changes: * [Issue 855][1]: ndk-build automatically disables multithreaded linking for LLD on Windows, where it may hang. It is not possible for the NDK to detect this situation for CMake, so CMake users and custom build systems must pass `-Wl,--no-threads` when linking with LLD on Windows. * [Issue 849][2]: Fixed unused command line argument warning when using standalone toolchains to compile C code. * [Issue 890][3]: Fixed CMAKE_FIND_ROOT_PATH. CMake projects will no longer search the host's sysroot for headers and libraries. * [Issue 907][4]: Fixed find_path for NDK headers in CMake. [0]: https://github.com/android-ndk/ndk/wiki/Changelog-r19#r19b [1]: android/ndk#855 [2]: android/ndk#849 [3]: android/ndk#890 [4]: android/ndk#907
`cmake` 3.10 is the current version of the tool in the Android SDK, an update from the much older 3.6. This update brings it closer to the host `cmake` versions (currently mostly 3.12.*) Bump NDK to release [19b][0] (a.k.a. 19.1), with the following changes: * [Issue 855][1]: ndk-build automatically disables multithreaded linking for LLD on Windows, where it may hang. It is not possible for the NDK to detect this situation for CMake, so CMake users and custom build systems must pass `-Wl,--no-threads` when linking with LLD on Windows. * [Issue 849][2]: Fixed unused command line argument warning when using standalone toolchains to compile C code. * [Issue 890][3]: Fixed CMAKE_FIND_ROOT_PATH. CMake projects will no longer search the host's sysroot for headers and libraries. * [Issue 907][4]: Fixed find_path for NDK headers in CMake. [0]: https://github.com/android-ndk/ndk/wiki/Changelog-r19#r19b [1]: android/ndk#855 [2]: android/ndk#849 [3]: android/ndk#890 [4]: android/ndk#907
`cmake` 3.10 is the current version of the tool in the Android SDK, an update from the much older 3.6. This update brings it closer to the host `cmake` versions (currently mostly 3.12.*) Bump NDK to release [19b][0] (a.k.a. 19.1), which changes: * [Issue 855][1]: ndk-build automatically disables multithreaded linking for LLD on Windows, where it may hang. It is not possible for the NDK to detect this situation for CMake, so CMake users and custom build systems must pass `-Wl,--no-threads` when linking with LLD on Windows. * [Issue 849][2]: Fixed unused command line argument warning when using standalone toolchains to compile C code. * [Issue 890][3]: Fixed CMAKE_FIND_ROOT_PATH. CMake projects will no longer search the host's sysroot for headers and libraries. * [Issue 907][4]: Fixed find_path for NDK headers in CMake. [0]: https://github.com/android-ndk/ndk/wiki/Changelog-r19#r19b [1]: android/ndk#855 [2]: android/ndk#849 [3]: android/ndk#890 [4]: android/ndk#907
The Once the NDK upgrades to this toolchain, I think we can close this issue. |
If I read things correctly, NDK r20 does include the updated toolchain, and this bug should now be gone? (The NDK r20 changelog still included this as a known issue.) |
r20 has Clang r346389c, which is not new enough to have the fix for this. The reason we don't have an r21 beta out yet is actually because we are waiting for a new toolchain that has this fix, among other. r353983c mentioned above had too many regressions for us to ship, so we're waiting for the new new toolchain. |
Ah, sorry for the misread - I just read the last few chars of the Clang rev number, and mixed up "...983c" with "...389c". Ok, then things are clear. |
Here's a repro program with a |
Test: ./checkbuild.py && ./run_tests.py Bug: android/ndk#855 Bug: android/ndk#884 Change-Id: I231e74e78b83b695e5675d0b21473ecc3f30ffbd
Fix is in r21. |
Test: ./checkbuild.py && ./run_tests.py Bug: android/ndk#855 Change-Id: I3f404dec7a020db07adbbbdaf03865ca143c9a3c
* Update ndk from branch 'ndk-release-r19' to 4009daf2819776a9cc273050f16976379f7c85f5 - Merge "Disable multithreaded linking for Windows LLD." into ndk-release-r19 - Disable multithreaded linking for Windows LLD. This only affects ndk-build because CMake can't currently check if it is using LLD since our toolchain file has finished running by the time the user can add ldflags. Not enabling this with standalone toolchains since we can't enable it for the built in toolchains without recompiling Clang and those are supposed to match. Will disable in the driver in a follow up if a workaround is not found. Test: ./checkbuild.py Bug: android/ndk#855 Change-Id: I4a24166adce463bea47ca4bf0e97d5375c69f40e (cherry picked from commit 144b2449de418b486b53d35a0d9916b75c7d5265)
In both NDK r18b and r19 beta1 for Windows 64-bit, ld.lld.exe will hang most of the time when linking our project (1078 source files). Possibly it's the same bug reported here:
https://bugs.llvm.org/show_bug.cgi?id=34806
Disabling threads prevents the hang but we would like multi-threading as link times are slow with our project without it. A snippet of CMakeLists.txt to workaround the hang and another unrelated issue with fix-cortex-a8:
I downloaded and compiled the latest lld and it does not hang however is also does not appear to be multithreaded even after removing the --no-threads flag, as CPU usage remains at 25% on my quad-core during the link stage. Explicitly setting the --threads flag to lld didn't help. However it's possible I didn't compile it correctly with multi-threading enabled:
<installed LLVM tools, llvm-config.exe in my path>
<downloaded source from https://android.googlesource.com/toolchain/lld>
cd lld
mkdir build
cd build
cmake -G "Visual Studio 15 2017" -A x64 -T host=x64 ..
cmake --build . --target ALL_BUILD --config Release
copy Release\bin\ld.lld.exe \AndroidTools\android-ndk-r18b\toolchains\llvm\prebuilt\windows-x86_64\bin /Y
Environment:
Windows 10 64-bit
Intel i3 8300, 16GB ram, 250GB NVMe drive
ABI= tried armeabi-v7a, armeabi-v8a
Android build tools= 28.0.3
Android platform API= tried 21, 26, 28
Gradle= 4.6
The text was updated successfully, but these errors were encountered: