Index: lld/trunk/ELF/Driver.h =================================================================== --- lld/trunk/ELF/Driver.h +++ lld/trunk/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 @@ void createFiles(llvm::opt::InputArgList &Args); void inferMachineType(); template void link(llvm::opt::InputArgList &Args); + template void compileBitcodeFiles(); // True if we are in --whole-archive and --no-whole-archive. bool InWholeArchive = false; @@ -40,6 +42,9 @@ // True if we are in --start-lib and --end-lib. bool InLib = false; + // For LTO. + std::unique_ptr LTO; + std::vector Files; }; Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -1436,6 +1436,29 @@ 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 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 DummyGroups; + auto *Obj = cast>(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 @@ // // 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(); + compileBitcodeFiles(); if (errorCount()) return; Index: lld/trunk/ELF/SymbolTable.h =================================================================== --- lld/trunk/ELF/SymbolTable.h +++ lld/trunk/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 @@ // is one add* function per symbol type. class SymbolTable { public: - template void addCombinedLTOObject(); void wrap(Symbol *Sym, Symbol *Real, Symbol *Wrap); ArrayRef getSymbols() const { return SymVector; } @@ -92,9 +90,6 @@ // can have the same name. We use this map to handle "extern C++ {}" // directive in version scripts. llvm::Optional>> DemangledSyms; - - // For LTO. - std::unique_ptr LTO; }; extern SymbolTable *Symtab; Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -32,29 +32,6 @@ 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 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 DummyGroups; - auto *Obj = cast>(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 @@ llvm_unreachable("bad symbol kind"); } } - -template void SymbolTable::addCombinedLTOObject(); -template void SymbolTable::addCombinedLTOObject(); -template void SymbolTable::addCombinedLTOObject(); -template void SymbolTable::addCombinedLTOObject();