[lld] [lld][MachO]Multi-threaded i/o. Twice as fast linking a large project. (PR #147134)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 05:02:37 PDT 2025
DavidSpickett wrote:
This feature has some problems when `LLVM_ENABLE_THREADS` is `OFF`. We first saw them on our 32-bit Arm build (https://lab.llvm.org/buildbot/#/builders/122/builds/2042) and I have been able to reproduce them on 64-bit Arm as well.
Build with threading disabled, then run `stress -c <high number>` in the background. Run `read-worker.s` in a loop and pretty soon it will fail with things like:
```
# RUN: at line 7
ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /home/david.spickett/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk -lSystem -fatal_warnings --read-workers=2 /home/david.spickett/build-llvm-arm/tools/lld/test/MachO/Output/read-workers.s.tmp.o -o /dev/null
# executed command: ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /home/david.spickett/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk -lSystem -fatal_warnings --read-workers=2 /home/david.spickett/build-llvm-arm/tools/lld/test/MachO/Output/read-workers.s.tmp.o -o /dev/null
# .---command stderr------------
# | pure virtual method called
# | terminate called without an active exception
# `-----------------------------
# error: command failed with exit status: -6
# RUN: at line 6
ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/llvm/lld/test/MachO/Inputs/MacOSX.sdk -lSystem -fatal_warnings --read-workers=1 /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/stage1/tools/lld/test/MachO/Output/read-workers.s.tmp.o -o /dev/null
# executed command: ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/llvm/lld/test/MachO/Inputs/MacOSX.sdk -lSystem -fatal_warnings --read-workers=1 /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/stage1/tools/lld/test/MachO/Output/read-workers.s.tmp.o -o /dev/null
# .---command stderr------------
# | terminate called after throwing an instance of 'std::bad_array_new_length'
# | what(): std::bad_array_new_length
# | pure virtual method called
# | terminate called recursively
# `-----------------------------
# error: command failed with exit status: -6
```
(I did try a debug build, but the traceback was no better)
I see you have some `#if` to handle when there are no threads but I don't think it's enough. I think it would be better to not construct this `SerialBackgroundQueue` at all when you know there cannot be extra threads. I don't know if you intended the queue to at least have 1 thread, which is the main process itself.
The option itself would ideally warn or reject values > 1 (or > 0 ?) when threading is not enabled.
Also, the current code produces this warning:
```
$ ninja
[4691/6894] Building CXX object tools/lld/MachO/CMakeFiles/lldMachO.dir/Driver.cpp.o
/home/david.spickett/llvm-project/lld/MachO/Driver.cpp:346:8: warning: unused variable 'preloadDeferredFile' [-Wunused-variable]
346 | auto preloadDeferredFile = [&](const DeferredFile &deferredFile) {
| ^~~~~~~~~~~~~~~~~~~
1 warning generated.
```
If you cannot reproduce it, I can implement the fix instead if you explain the best way to do so without breaking anything else.
https://github.com/llvm/llvm-project/pull/147134
More information about the llvm-commits
mailing list