[lld] r298020 - LTO: Fix a potential race condition in the caching API.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 16 17:34:08 PDT 2017


Author: pcc
Date: Thu Mar 16 19:34:07 2017
New Revision: 298020

URL: http://llvm.org/viewvc/llvm-project?rev=298020&view=rev
Log:
LTO: Fix a potential race condition in the caching API.

After the call to sys::fs::exists succeeds, indicating a cache hit, we call
AddFile and the client will open the file using the supplied path. If the
client is using cache pruning, there is a potential race between the pruner
and the client. To avoid this, change the caching API so that it provides
a MemoryBuffer to the client, and have clients use that MemoryBuffer where
possible.

This scheme won't work with the gold plugin because the plugin API expects a
file path. So we have the gold plugin use the buffer identifier as a path and
live with the race for now. (Note that the gold plugin isn't actually affected
by the problem at the moment because it doesn't support cache pruning.)

This effectively reverts r279883 modulo the change to use the existing path
in the gold plugin.

Differential Revision: https://reviews.llvm.org/D31063

Modified:
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=298020&r1=298019&r2=298020&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Thu Mar 16 19:34:07 2017
@@ -150,10 +150,11 @@ std::vector<InputFile *> BitcodeCompiler
   // specified, configure LTO to use it as the cache directory.
   lto::NativeObjectCache Cache;
   if (!Config->ThinLTOCacheDir.empty())
-    Cache = check(lto::localCache(
-        Config->ThinLTOCacheDir, [&](size_t Task, StringRef Path) {
-          Files[Task] = check(MemoryBuffer::getFile(Path));
-        }));
+    Cache = check(
+        lto::localCache(Config->ThinLTOCacheDir,
+                        [&](size_t Task, std::unique_ptr<MemoryBuffer> MB) {
+                          Files[Task] = std::move(MB);
+                        }));
 
   checkError(LTOObj->run(
       [&](size_t Task) {




More information about the llvm-commits mailing list