Index: llvm/include/llvm/LTO/LTO.h =================================================================== --- llvm/include/llvm/LTO/LTO.h +++ llvm/include/llvm/LTO/LTO.h @@ -292,6 +292,7 @@ std::vector Keep; }; std::vector ModsWithSummaries; + std::string EmptyModuleTargetTriple; } RegularLTO; struct ThinLTOState { Index: llvm/lib/LTO/LTO.cpp =================================================================== --- llvm/lib/LTO/LTO.cpp +++ llvm/lib/LTO/LTO.cpp @@ -469,6 +469,9 @@ if (Conf.ResolutionFile) writeToResolutionFile(*Conf.ResolutionFile, Input.get(), Res); + if (RegularLTO.EmptyModuleTargetTriple.empty()) + RegularLTO.EmptyModuleTargetTriple = Input->getTargetTriple(); + const SymbolResolution *ResI = Res.begin(); for (unsigned I = 0; I != Input->Mods.size(); ++I) if (Error Err = addModule(*Input, I, ResI, Res.end())) @@ -737,7 +740,9 @@ unsigned LTO::getMaxTasks() const { CalledGetMaxTasks = true; - return RegularLTO.ParallelCodeGenParallelismLevel + ThinLTO.ModuleMap.size(); + // Reserve one for empty module. + return 1 + RegularLTO.ParallelCodeGenParallelismLevel + + ThinLTO.ModuleMap.size(); } Error LTO::run(AddStreamFn AddStream, NativeObjectCache Cache) { @@ -760,9 +765,21 @@ bool HasRegularLTO = RegularLTO.CombinedModule != nullptr || !RegularLTO.ModsWithSummaries.empty(); // Invoke regular LTO if there was a regular LTO module to start with. - if (HasRegularLTO) + if (HasRegularLTO) { if (auto E = runRegularLTO(AddStream)) return E; + } else { + // Create empty output to have consistency and avoid workarounds on build + // system side for missing build rule output. + std::unique_ptr Mod = + make_unique("empty.o", RegularLTO.Ctx); + Mod->setTargetTriple(RegularLTO.EmptyModuleTargetTriple); + ModuleSummaryIndex EmptyIndex; + if (auto E = + backend(Conf, [&](size_t) { return AddStream(getMaxTasks() - 1); }, + 1, std::move(Mod), EmptyIndex)) + return E; + } return runThinLTO(AddStream, Cache, HasRegularLTO); } Index: llvm/test/ThinLTO/X86/Inputs/distributed_import.ll =================================================================== --- llvm/test/ThinLTO/X86/Inputs/distributed_import.ll +++ llvm/test/ThinLTO/X86/Inputs/distributed_import.ll @@ -1,3 +1,4 @@ +target triple = "x86_64-unknown-linux-gnu" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" @G = internal global i32 7