diff --git a/lld/ELF/Filesystem.cpp b/lld/ELF/Filesystem.cpp --- a/lld/ELF/Filesystem.cpp +++ b/lld/ELF/Filesystem.cpp @@ -59,8 +59,21 @@ sys::fs::remove(Path); // close and therefore remove TempPath in background. - if (!EC) - std::thread([=] { ::close(FD); }).detach(); + if (!EC) { + std::mutex M; + std::condition_variable CV; + bool Started = false; + std::thread([&, FD] { + { + std::lock_guard L(M); + Started = true; + CV.notify_all(); + } + ::close(FD); + }).detach(); + std::unique_lock L(M); + CV.wait(L, [&] { return Started; }); + } #endif }