diff options
| author | Rui Ueyama <ruiu@google.com> | 2019-05-23 09:26:27 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2019-05-23 09:26:27 +0000 |
| commit | 0baaf45be707c9e13e9f4d74001cb87701a519c1 (patch) | |
| tree | 5f0f579917b4a866bb848b0dd2181b508a4e7406 | |
| parent | 39192043bbfca8d4fe8562e2a2105012edaff8c3 (diff) | |
| download | bcm5719-llvm-0baaf45be707c9e13e9f4d74001cb87701a519c1.tar.gz bcm5719-llvm-0baaf45be707c9e13e9f4d74001cb87701a519c1.zip | |
Move SymbolTable::addCombinedLTOObject() to LinkerDriver.
Also renames it LinkerDriver::compileBitcodeFiles.
The function doesn't logically belong to SymbolTable. We added this
function to the symbol table because symbol table used to be a
container of input files. This is no longer the case.
Differential Revision: https://reviews.llvm.org/D62291
llvm-svn: 361469
| -rw-r--r-- | lld/ELF/Driver.cpp | 25 | ||||
| -rw-r--r-- | lld/ELF/Driver.h | 5 | ||||
| -rw-r--r-- | lld/ELF/SymbolTable.cpp | 28 | ||||
| -rw-r--r-- | lld/ELF/SymbolTable.h | 5 |
4 files changed, 29 insertions, 34 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index cad182ea3ee..6bd00e46b91 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1436,6 +1436,29 @@ template <class ELFT> static Symbol *addUndefined(StringRef Name) { Undefined{nullptr, Name, STB_GLOBAL, STV_DEFAULT, 0}); } +// This function is where all the optimizations of link-time +// optimization takes place. When LTO is in use, some input files are +// not in native object file format but in the LLVM bitcode format. +// This function compiles bitcode files into a few big native files +// using LLVM functions and replaces bitcode symbols with the results. +// Because all bitcode files that the program consists of are passed to +// the compiler at once, it can do a whole-program optimization. +template <class ELFT> void LinkerDriver::compileBitcodeFiles() { + // Compile bitcode files and replace bitcode symbols. + LTO.reset(new BitcodeCompiler); + for (BitcodeFile *File : BitcodeFiles) + LTO->add(*File); + + for (InputFile *File : LTO->compile()) { + DenseMap<CachedHashStringRef, const InputFile *> DummyGroups; + auto *Obj = cast<ObjFile<ELFT>>(File); + Obj->parse(DummyGroups); + for (Symbol *Sym : Obj->getGlobalSymbols()) + Sym->parseSymbolVersion(); + ObjectFiles.push_back(File); + } +} + // The --wrap option is a feature to rename symbols so that you can write // wrappers for existing functions. If you pass `-wrap=foo`, all // occurrences of symbol `foo` are resolved to `wrap_foo` (so, you are @@ -1645,7 +1668,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { // // With this the symbol table should be complete. After this, no new names // except a few linker-synthesized ones will be added to the symbol table. - Symtab->addCombinedLTOObject<ELFT>(); + compileBitcodeFiles<ELFT>(); if (errorCount()) return; diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h index 91d52c63723..76b91be2119 100644 --- a/lld/ELF/Driver.h +++ b/lld/ELF/Driver.h @@ -9,6 +9,7 @@ #ifndef LLD_ELF_DRIVER_H #define LLD_ELF_DRIVER_H +#include "LTO.h" #include "SymbolTable.h" #include "lld/Common/LLVM.h" #include "lld/Common/Reproduce.h" @@ -33,6 +34,7 @@ private: void createFiles(llvm::opt::InputArgList &Args); void inferMachineType(); template <class ELFT> void link(llvm::opt::InputArgList &Args); + template <class ELFT> void compileBitcodeFiles(); // True if we are in --whole-archive and --no-whole-archive. bool InWholeArchive = false; @@ -40,6 +42,9 @@ private: // True if we are in --start-lib and --end-lib. bool InLib = false; + // For LTO. + std::unique_ptr<BitcodeCompiler> LTO; + std::vector<InputFile *> Files; }; diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index b6d1741f856..44fdb96b3e0 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -32,29 +32,6 @@ using namespace lld::elf; SymbolTable *elf::Symtab; -// This function is where all the optimizations of link-time -// optimization happens. When LTO is in use, some input files are -// not in native object file format but in the LLVM bitcode format. -// This function compiles bitcode files into a few big native files -// using LLVM functions and replaces bitcode symbols with the results. -// 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() { - // Compile bitcode files and replace bitcode symbols. - LTO.reset(new BitcodeCompiler); - for (BitcodeFile *F : BitcodeFiles) - LTO->add(*F); - - for (InputFile *File : LTO->compile()) { - DenseMap<CachedHashStringRef, const InputFile *> DummyGroups; - auto *Obj = cast<ObjFile<ELFT>>(File); - Obj->parse(DummyGroups); - for (Symbol *Sym : Obj->getGlobalSymbols()) - Sym->parseSymbolVersion(); - ObjectFiles.push_back(File); - } -} - // Set a flag for --trace-symbol so that we can print out a log message // if a new symbol with the same name is inserted into the symbol table. void SymbolTable::trace(StringRef Name) { @@ -609,8 +586,3 @@ void elf::resolveSymbol(Symbol *Old, const Symbol &New) { llvm_unreachable("bad symbol kind"); } } - -template void SymbolTable::addCombinedLTOObject<ELF32LE>(); -template void SymbolTable::addCombinedLTOObject<ELF32BE>(); -template void SymbolTable::addCombinedLTOObject<ELF64LE>(); -template void SymbolTable::addCombinedLTOObject<ELF64BE>(); diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index f77d04516b9..25b73fa5481 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -10,7 +10,6 @@ #define LLD_ELF_SYMBOL_TABLE_H #include "InputFiles.h" -#include "LTO.h" #include "lld/Common/Strings.h" #include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseMap.h" @@ -40,7 +39,6 @@ class Undefined; // is one add* function per symbol type. class SymbolTable { public: - template <class ELFT> void addCombinedLTOObject(); void wrap(Symbol *Sym, Symbol *Real, Symbol *Wrap); ArrayRef<Symbol *> getSymbols() const { return SymVector; } @@ -92,9 +90,6 @@ private: // can have the same name. We use this map to handle "extern C++ {}" // directive in version scripts. llvm::Optional<llvm::StringMap<std::vector<Symbol *>>> DemangledSyms; - - // For LTO. - std::unique_ptr<BitcodeCompiler> LTO; }; extern SymbolTable *Symtab; |

