summaryrefslogtreecommitdiff
path: root/tools/gold
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-09-21 19:12:05 +0000
committerTeresa Johnson <tejohnson@google.com>2016-09-21 19:12:05 +0000
commitb81a1e90283a182e5d444a67d6f7cdf13bccc072 (patch)
treec8fb3fc005eab895a0ef1d51091b0af0c9c4e39d /tools/gold
parent648d6ac61e4e2e24a8437e83e7213d083b422783 (diff)
[ThinLTO] Emit files for distributed builds for all modules
With the new LTO API in r278338, we stopped emitting the individual index files and imports files for some modules in the distributed backend case (thinlto-index-only plugin option). Specifically, this is when the linker decides not to include a module in the link, because it was in an archive library and did not have a strong reference to it. Not creating the expected output files makes the distributed build system implementation more difficult, in terms of checking for the expected outputs of the thin link, and scheduling the backend jobs. To address this, the gold-plugin will write dummy empty .thinlto.bc and .imports files for modules not included in the link (which LTO never sees). Augmented a gold v1.12+ test, since that version of gold has the handling for notifying on modules not being included in the link. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282100 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold')
-rw-r--r--tools/gold/gold-plugin.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index b347f554b87..89a908aec50 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -752,6 +752,34 @@ static std::unique_ptr<LTO> createLTO() {
ParallelCodeGenParallelismLevel);
}
+// Write empty files that may be expected by a distributed build
+// system when invoked with thinlto_index_only. This is invoked when
+// the linker has decided not to include the given module in the
+// final link. Frequently the distributed build system will want to
+// confirm that all expected outputs are created based on all of the
+// modules provided to the linker.
+static void writeEmptyDistributedBuildOutputs(std::string &ModulePath,
+ std::string &OldPrefix,
+ std::string &NewPrefix) {
+ std::string NewModulePath =
+ getThinLTOOutputFile(ModulePath, OldPrefix, NewPrefix);
+ std::error_code EC;
+ {
+ raw_fd_ostream OS(NewModulePath + ".thinlto.bc", EC,
+ sys::fs::OpenFlags::F_None);
+ if (EC)
+ message(LDPL_FATAL, "Failed to write '%s': %s",
+ (NewModulePath + ".thinlto.bc").c_str(), EC.message().c_str());
+ }
+ if (options::thinlto_emit_imports_files) {
+ raw_fd_ostream OS(NewModulePath + ".imports", EC,
+ sys::fs::OpenFlags::F_None);
+ if (EC)
+ message(LDPL_FATAL, "Failed to write '%s': %s",
+ (NewModulePath + ".imports").c_str(), EC.message().c_str());
+ }
+}
+
/// gold informs us that all symbols have been read. At this point, we use
/// get_symbols to see if any of our definitions have been overridden by a
/// native object file. Then, perform optimization and codegen.
@@ -771,13 +799,22 @@ static ld_plugin_status allSymbolsReadHook() {
std::unique_ptr<LTO> Lto = createLTO();
+ std::string OldPrefix, NewPrefix;
+ if (options::thinlto_index_only)
+ getThinLTOOldAndNewPrefix(OldPrefix, NewPrefix);
+
for (claimed_file &F : Modules) {
if (options::thinlto && !HandleToInputFile.count(F.leader_handle))
HandleToInputFile.insert(std::make_pair(
F.leader_handle, llvm::make_unique<PluginInputFile>(F.handle)));
const void *View = getSymbolsAndView(F);
- if (!View)
+ if (!View) {
+ if (options::thinlto_index_only)
+ // Write empty output files that may be expected by the distributed
+ // build system.
+ writeEmptyDistributedBuildOutputs(F.name, OldPrefix, NewPrefix);
continue;
+ }
addModule(*Lto, F, View);
}