diff options
Diffstat (limited to 'llvm/tools/gold/gold-plugin.cpp')
-rw-r--r-- | llvm/tools/gold/gold-plugin.cpp | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 34696ba16a9..9bdc7abc5b4 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -675,24 +675,6 @@ static void getThinLTOOldAndNewPrefix(std::string &OldPrefix, NewPrefix = Split.second.str(); } -namespace { -// Define the LTOOutput handling -class LTOOutput : public lto::NativeObjectOutput { - StringRef Path; - -public: - LTOOutput(StringRef Path) : Path(Path) {} - // Open the filename \p Path and allocate a stream. - std::unique_ptr<raw_pwrite_stream> getStream() override { - int FD; - std::error_code EC = sys::fs::openFileForWrite(Path, FD, sys::fs::F_None); - if (EC) - message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str()); - return llvm::make_unique<llvm::raw_fd_ostream>(FD, true); - } -}; -} - static std::unique_ptr<LTO> createLTO() { Config Conf; ThinBackend Backend; @@ -831,21 +813,27 @@ static ld_plugin_status allSymbolsReadHook() { std::vector<uintptr_t> IsTemporary(MaxTasks); std::vector<SmallString<128>> Filenames(MaxTasks); - auto AddOutput = - [&](size_t Task) -> std::unique_ptr<lto::NativeObjectOutput> { - auto &OutputName = Filenames[Task]; - getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, OutputName, + auto AddStream = + [&](size_t Task) -> std::unique_ptr<lto::NativeObjectStream> { + IsTemporary[Task] = !SaveTemps; + getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, Filenames[Task], MaxTasks > 1 ? Task : -1); - IsTemporary[Task] = !SaveTemps && options::cache_dir.empty(); - if (options::cache_dir.empty()) - return llvm::make_unique<LTOOutput>(OutputName); - - return llvm::make_unique<CacheObjectOutput>( - options::cache_dir, - [&OutputName](std::string EntryPath) { OutputName = EntryPath; }); + int FD; + std::error_code EC = + sys::fs::openFileForWrite(Filenames[Task], FD, sys::fs::F_None); + if (EC) + message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str()); + return llvm::make_unique<lto::NativeObjectStream>( + llvm::make_unique<llvm::raw_fd_ostream>(FD, true)); }; - check(Lto->run(AddOutput)); + auto AddFile = [&](size_t Task, StringRef Path) { Filenames[Task] = Path; }; + + NativeObjectCache Cache; + if (!options::cache_dir.empty()) + Cache = localCache(options::cache_dir, AddFile); + + check(Lto->run(AddStream, Cache)); if (options::TheOutputType == options::OT_DISABLE || options::TheOutputType == options::OT_BC_ONLY) |