summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-lto2
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-03-17 00:34:07 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-03-17 00:34:07 +0000
commit128423f99becbbaba396b9b19489d48ba7e4b9d7 (patch)
tree194ba526d94cc3c1623314a34fb59088ab4d901b /llvm/tools/llvm-lto2
parent3735006063d321f53f828dc2432fe6e78a7532e8 (diff)
downloadbcm5719-llvm-128423f99becbbaba396b9b19489d48ba7e4b9d7.tar.gz
bcm5719-llvm-128423f99becbbaba396b9b19489d48ba7e4b9d7.zip
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 llvm-svn: 298020
Diffstat (limited to 'llvm/tools/llvm-lto2')
-rw-r--r--llvm/tools/llvm-lto2/llvm-lto2.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index 3fe0487476f..ce0f4b98425 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -275,18 +275,13 @@ int main(int argc, char **argv) {
return llvm::make_unique<lto::NativeObjectStream>(std::move(S));
};
- auto AddFile = [&](size_t Task, StringRef Path) {
- auto ReloadedBufferOrErr = MemoryBuffer::getFile(Path);
- if (auto EC = ReloadedBufferOrErr.getError())
- report_fatal_error(Twine("Can't reload cached file '") + Path + "': " +
- EC.message() + "\n");
-
- *AddStream(Task)->OS << (*ReloadedBufferOrErr)->getBuffer();
+ auto AddBuffer = [&](size_t Task, std::unique_ptr<MemoryBuffer> MB) {
+ *AddStream(Task)->OS << MB->getBuffer();
};
NativeObjectCache Cache;
if (!CacheDir.empty())
- Cache = check(localCache(CacheDir, AddFile), "failed to create cache");
+ Cache = check(localCache(CacheDir, AddBuffer), "failed to create cache");
check(Lto.run(AddStream, Cache), "LTO::run failed");
}
OpenPOWER on IntegriCloud