diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2017-03-17 00:34:07 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-03-17 00:34:07 +0000 |
commit | 128423f99becbbaba396b9b19489d48ba7e4b9d7 (patch) | |
tree | 194ba526d94cc3c1623314a34fb59088ab4d901b /llvm/tools/gold/gold-plugin.cpp | |
parent | 3735006063d321f53f828dc2432fe6e78a7532e8 (diff) | |
download | bcm5719-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/gold/gold-plugin.cpp')
-rw-r--r-- | llvm/tools/gold/gold-plugin.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 123d90df890..38674d20717 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -831,11 +831,15 @@ static ld_plugin_status allSymbolsReadHook() { llvm::make_unique<llvm::raw_fd_ostream>(FD, true)); }; - auto AddFile = [&](size_t Task, StringRef Path) { Filenames[Task] = Path; }; + auto AddBuffer = [&](size_t Task, std::unique_ptr<MemoryBuffer> MB) { + // Note that this requires that the memory buffers provided to AddBuffer are + // backed by a file. + Filenames[Task] = MB->getBufferIdentifier(); + }; NativeObjectCache Cache; if (!options::cache_dir.empty()) - Cache = check(localCache(options::cache_dir, AddFile)); + Cache = check(localCache(options::cache_dir, AddBuffer)); check(Lto->run(AddStream, Cache)); |