diff options
| -rw-r--r-- | lld/ELF/LTO.cpp | 37 | ||||
| -rw-r--r-- | lld/ELF/LTO.h | 2 | ||||
| -rw-r--r-- | lld/ELF/SymbolTable.cpp | 5 | ||||
| -rw-r--r-- | lld/test/ELF/lto/thinlto-index-only.ll | 6 |
4 files changed, 31 insertions, 19 deletions
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index c97ff4d2476..4f641d647de 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -211,18 +211,24 @@ void BitcodeCompiler::add(BitcodeFile &F) { checkError(LTOObj->add(std::move(F.Obj), Resols)); } -static void createEmptyIndex(StringRef ModulePath) { - std::string Path = replaceThinLTOSuffix(getThinLTOOutputFile(ModulePath)); - std::unique_ptr<raw_fd_ostream> OS = openFile(Path + ".thinlto.bc"); - if (!OS) - return; - - ModuleSummaryIndex M(/*HaveGVs*/ false); - M.setSkipModuleByDistributedBackend(); - WriteIndexToFile(M, *OS); - - if (Config->ThinLTOEmitImportsFiles) - openFile(Path + ".imports"); +// If LazyObjFile has not been added to link, emit empty index files. +// This is needed because this is what GNU gold plugin does and we have a +// distributed build system that depends on that behavior. +void elf::thinLTOCreateEmptyIndexFiles() { + for (LazyObjFile *F : LazyObjFiles) { + if (F->AddedToLink || !isBitcode(F->MB)) + continue; + std::string Path = replaceThinLTOSuffix(getThinLTOOutputFile(F->getName())); + std::unique_ptr<raw_fd_ostream> OS = openFile(Path + ".thinlto.bc"); + if (!OS) + continue; + + ModuleSummaryIndex M(/*HaveGVs*/ false); + M.setSkipModuleByDistributedBackend(); + WriteIndexToFile(M, *OS); + if (Config->ThinLTOEmitImportsFiles) + openFile(Path + ".imports"); + } } // Merge all the bitcode files we have seen, codegen the result @@ -258,13 +264,8 @@ std::vector<InputFile *> BitcodeCompiler::compile() { openFile(Path + ".imports"); } - // If LazyObjFile has not been added to link, emit empty index files. - // This is needed because this is what GNU gold plugin does and we have a - // distributed build system that depends on that behavior. if (Config->ThinLTOIndexOnly) { - for (LazyObjFile *F : LazyObjFiles) - if (!F->AddedToLink && isBitcode(F->MB)) - createEmptyIndex(F->getName()); + thinLTOCreateEmptyIndexFiles(); if (!Config->LTOObjPath.empty()) saveBuffer(Buf[0], Config->LTOObjPath); diff --git a/lld/ELF/LTO.h b/lld/ELF/LTO.h index 0f0b5bce718..1df1d2bbcfd 100644 --- a/lld/ELF/LTO.h +++ b/lld/ELF/LTO.h @@ -56,6 +56,8 @@ private: std::unique_ptr<llvm::raw_fd_ostream> IndexFile; llvm::DenseSet<StringRef> ThinIndices; }; + +void thinLTOCreateEmptyIndexFiles(); } // namespace elf } // namespace lld diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 2a511a26674..1b017b07f58 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -115,8 +115,11 @@ template <class ELFT> void SymbolTable::addFile(InputFile *File) { // Because all bitcode files that the program consists of are passed // to the compiler at once, it can do whole-program optimization. template <class ELFT> void SymbolTable::addCombinedLTOObject() { - if (BitcodeFiles.empty()) + if (BitcodeFiles.empty()) { + if (Config->ThinLTOIndexOnly) + thinLTOCreateEmptyIndexFiles(); return; + } // Compile bitcode files and replace bitcode symbols. LTO.reset(new BitcodeCompiler); diff --git a/lld/test/ELF/lto/thinlto-index-only.ll b/lld/test/ELF/lto/thinlto-index-only.ll index 6396057c9a3..3abc18e4875 100644 --- a/lld/test/ELF/lto/thinlto-index-only.ll +++ b/lld/test/ELF/lto/thinlto-index-only.ll @@ -38,6 +38,12 @@ ; RUN: ls %t1.o.thinlto.bc ; RUN: ls %t1.o.imports +; Ensure LLD generates an empty index for each bitcode file even if all bitcode files are lazy. +; RUN: rm -f %t1.o.thinlto.bc +; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux-gnu /dev/null -o %tdummy.o +; RUN: ld.lld --plugin-opt=thinlto-index-only -shared %tdummy.o --start-lib %t1.o --end-lib +; RUN: ls %t1.o.thinlto.bc + ; NM: T f ; The backend index for this module contains summaries from itself and |

