[lld] r360129 - [ELF] Reorder BitcodeFiles.empty() to call thinLTOCreateEmptyIndexFiles() in only one place

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 03:40:26 PDT 2019


Author: maskray
Date: Tue May  7 03:40:26 2019
New Revision: 360129

URL: http://llvm.org/viewvc/llvm-project?rev=360129&view=rev
Log:
[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

Modified:
    lld/trunk/ELF/LTO.cpp
    lld/trunk/ELF/LTO.h
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=360129&r1=360128&r2=360129&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Tue May  7 03:40:26 2019
@@ -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<InputFile *> BitcodeCompiler
                           Files[Task] = std::move(MB);
                         }));
 
-  checkError(LTOObj->run(
-      [&](size_t Task) {
-        return llvm::make_unique<lto::NativeObjectStream>(
-            llvm::make_unique<raw_svector_ostream>(Buf[Task]));
-      },
-      Cache));
+  if (!BitcodeFiles.empty())
+    checkError(LTOObj->run(
+        [&](size_t Task) {
+          return llvm::make_unique<lto::NativeObjectStream>(
+              llvm::make_unique<raw_svector_ostream>(Buf[Task]));
+        },
+        Cache));
 
   // Emit empty index files for non-indexed files
   for (StringRef S : ThinIndices) {

Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=360129&r1=360128&r2=360129&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Tue May  7 03:40:26 2019
@@ -56,8 +56,6 @@ private:
   std::unique_ptr<llvm::raw_fd_ostream> IndexFile;
   llvm::DenseSet<StringRef> ThinIndices;
 };
-
-void thinLTOCreateEmptyIndexFiles();
 } // namespace elf
 } // namespace lld
 

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=360129&r1=360128&r2=360129&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue May  7 03:40:26 2019
@@ -115,12 +115,6 @@ template <class ELFT> void SymbolTable::
 // 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 (Config->ThinLTOIndexOnly)
-      thinLTOCreateEmptyIndexFiles();
-    return;
-  }
-
   // Compile bitcode files and replace bitcode symbols.
   LTO.reset(new BitcodeCompiler);
   for (BitcodeFile *F : BitcodeFiles)




More information about the llvm-commits mailing list