summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2019-02-14 23:41:23 +0000
committerNick Desaulniers <ndesaulniers@google.com>2019-02-14 23:41:23 +0000
commitc3aefedc4697869f47f993f7003bc389aa97dd98 (patch)
tree1391e2fc68384e938ebb91a07a5de706ee3e0ccb
parent289d70cf5810e89fd950c4f505898fc9e38d1d24 (diff)
downloadbcm5719-llvm-c3aefedc4697869f47f993f7003bc389aa97dd98.tar.gz
bcm5719-llvm-c3aefedc4697869f47f993f7003bc389aa97dd98.zip
Revert "Revert "[lld] Fix elf::unlinkAsync detached thread""
This reverts commit 9934f2ff02dba9fdabe6e27a83f9f95388bf4132. llvm-svn: 354081
-rw-r--r--lld/ELF/Filesystem.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/lld/ELF/Filesystem.cpp b/lld/ELF/Filesystem.cpp
index 957534a0a41..5c8475fbdd0 100644
--- a/lld/ELF/Filesystem.cpp
+++ b/lld/ELF/Filesystem.cpp
@@ -58,9 +58,26 @@ void elf::unlinkAsync(StringRef Path) {
std::error_code EC = sys::fs::openFileForRead(Path, FD);
sys::fs::remove(Path);
+ if (EC)
+ return;
+
// close and therefore remove TempPath in background.
- if (!EC)
- std::thread([=] { ::close(FD); }).detach();
+ std::mutex M;
+ std::condition_variable CV;
+ bool Started = false;
+ std::thread([&, FD] {
+ {
+ std::lock_guard<std::mutex> L(M);
+ Started = true;
+ CV.notify_all();
+ }
+ ::close(FD);
+ }).detach();
+
+ // GLIBC 2.26 and earlier have race condition that crashes an entire process
+ // if the main thread calls exit(2) while other thread is starting up.
+ std::unique_lock<std::mutex> L(M);
+ CV.wait(L, [&] { return Started; });
#endif
}
OpenPOWER on IntegriCloud