[lld] r359788 - [ELF] --plugin-opt=thinlto-index-only: create empty index files even if all bitcode files are lazy
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 07:05:20 PDT 2019
Author: maskray
Date: Thu May 2 07:05:20 2019
New Revision: 359788
URL: http://llvm.org/viewvc/llvm-project?rev=359788&view=rev
Log:
[ELF] --plugin-opt=thinlto-index-only: create empty index files even if all bitcode files are lazy
Summary:
The gold plugin behavior (creating empty index files for lazy bitcode
files) was added in D46034, but it missed the case when there is no
non-lazy bitcode files, e.g.
ld.lld -shared crti.o crtbeginS.o --start-lib bitcode.o --end-lib ...
crti.o crtbeginS.o are not bitcode, but our distributed build system
wants bitcode.o.thinlto.bc to confirm all expected outputs are created
based on all of the modules provided to the linker.
Differential Revision: https://reviews.llvm.org/D61420
Modified:
lld/trunk/ELF/LTO.cpp
lld/trunk/ELF/LTO.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/test/ELF/lto/thinlto-index-only.ll
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=359788&r1=359787&r2=359788&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Thu May 2 07:05:20 2019
@@ -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
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);
Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=359788&r1=359787&r2=359788&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Thu May 2 07:05:20 2019
@@ -56,6 +56,8 @@ 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=359788&r1=359787&r2=359788&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu May 2 07:05:20 2019
@@ -115,8 +115,11 @@ 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 (BitcodeFiles.empty()) {
+ if (Config->ThinLTOIndexOnly)
+ thinLTOCreateEmptyIndexFiles();
return;
+ }
// Compile bitcode files and replace bitcode symbols.
LTO.reset(new BitcodeCompiler);
Modified: lld/trunk/test/ELF/lto/thinlto-index-only.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/thinlto-index-only.ll?rev=359788&r1=359787&r2=359788&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/thinlto-index-only.ll (original)
+++ lld/trunk/test/ELF/lto/thinlto-index-only.ll Thu May 2 07:05:20 2019
@@ -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
More information about the llvm-commits
mailing list