From f3994e4dfa0214b2a09a0e327ba37e6b38bbcdb3 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 7 May 2019 10:40:26 +0000 Subject: [PATCH] [ELF] Reorder BitcodeFiles.empty() to call thinLTOCreateEmptyIndexFiles() in only one place It makes the --plugin-opt=obj-path= and --plugin-opt=thinlto-index-only= behavior more consistent - the files will be created in the BitcodeFiles.empty() case, but I assume whether it behaves this way is not required by anyone. LTOObj->run() cannot run with empty BitcodeFiles. There would be an error: ld.lld: error: No available targets are compatible with triple "" Differential Revision: https://reviews.llvm.org/D61635 llvm-svn: 360129 --- lld/ELF/LTO.cpp | 15 ++++++++------- lld/ELF/LTO.h | 2 -- lld/ELF/SymbolTable.cpp | 6 ------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 4f641d647de3..ea0d17e81aab 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -214,7 +214,7 @@ void BitcodeCompiler::add(BitcodeFile &F) { // 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() { +static void thinLTOCreateEmptyIndexFiles() { for (LazyObjFile *F : LazyObjFiles) { if (F->AddedToLink || !isBitcode(F->MB)) continue; @@ -249,12 +249,13 @@ std::vector BitcodeCompiler::compile() { Files[Task] = std::move(MB); })); - checkError(LTOObj->run( - [&](size_t Task) { - return llvm::make_unique( - llvm::make_unique(Buf[Task])); - }, - Cache)); + if (!BitcodeFiles.empty()) + checkError(LTOObj->run( + [&](size_t Task) { + return llvm::make_unique( + llvm::make_unique(Buf[Task])); + }, + Cache)); // Emit empty index files for non-indexed files for (StringRef S : ThinIndices) { diff --git a/lld/ELF/LTO.h b/lld/ELF/LTO.h index 1df1d2bbcfd5..0f0b5bce7180 100644 --- a/lld/ELF/LTO.h +++ b/lld/ELF/LTO.h @@ -56,8 +56,6 @@ private: std::unique_ptr IndexFile; llvm::DenseSet ThinIndices; }; - -void thinLTOCreateEmptyIndexFiles(); } // namespace elf } // namespace lld diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 1b017b07f584..6e69b25c61e0 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -115,12 +115,6 @@ template 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 void SymbolTable::addCombinedLTOObject() { - if (BitcodeFiles.empty()) { - if (Config->ThinLTOIndexOnly) - thinLTOCreateEmptyIndexFiles(); - return; - } - // Compile bitcode files and replace bitcode symbols. LTO.reset(new BitcodeCompiler); for (BitcodeFile *F : BitcodeFiles)