Skip to content

Commit

Permalink
[LLD] [COFF] Avoid thread exhaustion on 32-bit Windows host
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jeremyd2019 authored and mstorsjo committed Jul 7, 2021
1 parent d20b013 commit 7a7da69
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7a7da69

Please sign in to comment.