[llvm] r325618 - [ThinLTO/gold] Avoid race with cache pruner by copying to temp files

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 11:51:30 PST 2018


Author: tejohnson
Date: Tue Feb 20 11:51:30 2018
New Revision: 325618

URL: http://llvm.org/viewvc/llvm-project?rev=325618&view=rev
Log:
[ThinLTO/gold] Avoid race with cache pruner by copying to temp files

Summary:
This will avoid the race condition described in the review for D37993.

I believe that the Path parameter to AddBufferFn is no longer utilized.
I would prefer to remove that as a follow up clean up patch to reduce
the diffs in this patch.

Reviewers: pcc

Reviewed By: pcc

Subscribers: inglorion, llvm-commits

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

Modified:
    llvm/trunk/test/tools/gold/X86/cache.ll
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/test/tools/gold/X86/cache.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/cache.ll?rev=325618&r1=325617&r2=325618&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/cache.ll (original)
+++ llvm/trunk/test/tools/gold/X86/cache.ll Tue Feb 20 11:51:30 2018
@@ -54,10 +54,16 @@
 ; This should remove it.
 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
 ; RUN:     --plugin-opt=thinlto \
+; RUN:     --plugin-opt=save-temps \
 ; RUN:     --plugin-opt=cache-dir=%t.cache \
 ; RUN:     --plugin-opt=cache-policy=cache_size_bytes=32k:prune_interval=0s \
-; RUN:     -o %t3.o %t2.o %t.o
+; RUN:     -o %t4.o %t2.o %t.o
 ; RUN: ls %t.cache | count 4
+; With save-temps we can confirm that the cached files were copied into temp
+; files to avoid a race condition with the cached files being pruned, since the
+; gold plugin-api only accepts native objects passed back as files.
+; RUN: ls %t4.o.o1
+; RUN: ls %t4.o.o2
 
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=325618&r1=325617&r2=325618&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Tue Feb 20 11:51:30 2018
@@ -919,9 +919,7 @@ static ld_plugin_status allSymbolsReadHo
 
   auto AddBuffer = [&](size_t Task, std::unique_ptr<MemoryBuffer> MB,
                        StringRef Path) {
-    // Note that this requires that the memory buffers provided to AddBuffer are
-    // backed by a file.
-    Filenames[Task] = Path;
+    *AddStream(Task)->OS << MB->getBuffer();
   };
 
   NativeObjectCache Cache;




More information about the llvm-commits mailing list