[lld] 7a7da69 - [LLD] [COFF] Avoid thread exhaustion on 32-bit Windows host
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 7 12:00:58 PDT 2021
Author: Jeremy Drake
Date: 2021-07-07T22:00:18+03:00
New Revision: 7a7da69fbe288de088bfee47d2f7c21da2132085
URL: https://github.com/llvm/llvm-project/commit/7a7da69fbe288de088bfee47d2f7c21da2132085
DIFF: https://github.com/llvm/llvm-project/commit/7a7da69fbe288de088bfee47d2f7c21da2132085.diff
LOG: [LLD] [COFF] Avoid thread exhaustion on 32-bit Windows host
LLD on 32-bit Windows would frequently fail on large projects with
an exception "thread constructor failed: Exec format error". The stack
trace pointed to this usage of std::async, and looking at the
implementation in libc++ it seems using std::async with
std::launch::async results in the immediate creation of a new thread
for every call. This could result in a potentially unbounded number
of threads, depending on the number of input files. This seems to
be hitting some limit in 32-bit Windows host.
I took the easy route, and only use threads on 64-bit Windows, not all
Windows as before. I was thinking a more proper solution might
involve using a thread pool rather than blindly spawning any number
of new threads, but that may have other unforeseen consequences.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D105506
Added:
Modified:
lld/COFF/Driver.cpp
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6ebd80f741808..8e1292f0a5e8e 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -149,9 +149,10 @@ using MBErrPair = std::pair<std::unique_ptr<MemoryBuffer>, std::error_code>;
// Create a std::future that opens and maps a file using the best strategy for
// the host platform.
static std::future<MBErrPair> createFutureForFile(std::string path) {
-#if _WIN32
+#if _WIN64
// On Windows, file I/O is relatively slow so it is best to do this
- // asynchronously.
+ // asynchronously. But 32-bit has issues with potentially launching tons
+ // of threads
auto strategy = std::launch::async;
#else
auto strategy = std::launch::deferred;
More information about the llvm-commits
mailing list