[PATCH] D58246: [lld] Fix elf::unlinkAsync detached thread
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 14 11:40:47 PST 2019
vitalybuka created this revision.
vitalybuka added a reviewer: ruiu.
Herald added subscribers: llvm-commits, jfb, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
So this patch just make sure that the thread is at least stated
before we return from main.
If we just detach then the thread may be actually be stated just after
the process returned from main and it's calling atexit handers. Then the thread may try to create own function static variable and it will
add new at exit handlers confusing libc.
GLIBC before 2.27 had race in that case which corrupted atexit handlers
list. Support for this use-case for other implementation is also unclear,
so we can try just avoid that.
PR40162
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D58246
Files:
lld/ELF/Filesystem.cpp
Index: lld/ELF/Filesystem.cpp
===================================================================
--- lld/ELF/Filesystem.cpp
+++ 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<std::mutex> L(M);
+ Started = true;
+ CV.notify_all();
+ }
+ ::close(FD);
+ }).detach();
+ std::unique_lock<std::mutex> L(M);
+ CV.wait(L, [&] { return Started; });
+ }
#endif
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58246.186885.patch
Type: text/x-patch
Size: 687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190214/6afdb2b6/attachment.bin>
More information about the llvm-commits
mailing list