Skip to content

Commit 0baaf45

Browse files
committedMay 23, 2019
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
1 parent 3919204 commit 0baaf45

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed
 

Diff for: ‎lld/ELF/Driver.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,29 @@ template <class ELFT> static Symbol *addUndefined(StringRef Name) {
14361436
Undefined{nullptr, Name, STB_GLOBAL, STV_DEFAULT, 0});
14371437
}
14381438

1439+
// This function is where all the optimizations of link-time
1440+
// optimization takes place. When LTO is in use, some input files are
1441+
// not in native object file format but in the LLVM bitcode format.
1442+
// This function compiles bitcode files into a few big native files
1443+
// using LLVM functions and replaces bitcode symbols with the results.
1444+
// Because all bitcode files that the program consists of are passed to
1445+
// the compiler at once, it can do a whole-program optimization.
1446+
template <class ELFT> void LinkerDriver::compileBitcodeFiles() {
1447+
// Compile bitcode files and replace bitcode symbols.
1448+
LTO.reset(new BitcodeCompiler);
1449+
for (BitcodeFile *File : BitcodeFiles)
1450+
LTO->add(*File);
1451+
1452+
for (InputFile *File : LTO->compile()) {
1453+
DenseMap<CachedHashStringRef, const InputFile *> DummyGroups;
1454+
auto *Obj = cast<ObjFile<ELFT>>(File);
1455+
Obj->parse(DummyGroups);
1456+
for (Symbol *Sym : Obj->getGlobalSymbols())
1457+
Sym->parseSymbolVersion();
1458+
ObjectFiles.push_back(File);
1459+
}
1460+
}
1461+
14391462
// The --wrap option is a feature to rename symbols so that you can write
14401463
// wrappers for existing functions. If you pass `-wrap=foo`, all
14411464
// 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) {
16451668
//
16461669
// With this the symbol table should be complete. After this, no new names
16471670
// except a few linker-synthesized ones will be added to the symbol table.
1648-
Symtab->addCombinedLTOObject<ELFT>();
1671+
compileBitcodeFiles<ELFT>();
16491672
if (errorCount())
16501673
return;
16511674

Diff for: ‎lld/ELF/Driver.h

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLD_ELF_DRIVER_H
1010
#define LLD_ELF_DRIVER_H
1111

12+
#include "LTO.h"
1213
#include "SymbolTable.h"
1314
#include "lld/Common/LLVM.h"
1415
#include "lld/Common/Reproduce.h"
@@ -33,13 +34,17 @@ class LinkerDriver {
3334
void createFiles(llvm::opt::InputArgList &Args);
3435
void inferMachineType();
3536
template <class ELFT> void link(llvm::opt::InputArgList &Args);
37+
template <class ELFT> void compileBitcodeFiles();
3638

3739
// True if we are in --whole-archive and --no-whole-archive.
3840
bool InWholeArchive = false;
3941

4042
// True if we are in --start-lib and --end-lib.
4143
bool InLib = false;
4244

45+
// For LTO.
46+
std::unique_ptr<BitcodeCompiler> LTO;
47+
4348
std::vector<InputFile *> Files;
4449
};
4550

Diff for: ‎lld/ELF/SymbolTable.cpp

-28
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,6 @@ using namespace lld::elf;
3232

3333
SymbolTable *elf::Symtab;
3434

35-
// This function is where all the optimizations of link-time
36-
// optimization happens. When LTO is in use, some input files are
37-
// not in native object file format but in the LLVM bitcode format.
38-
// This function compiles bitcode files into a few big native files
39-
// using LLVM functions and replaces bitcode symbols with the results.
40-
// Because all bitcode files that the program consists of are passed
41-
// to the compiler at once, it can do whole-program optimization.
42-
template <class ELFT> void SymbolTable::addCombinedLTOObject() {
43-
// Compile bitcode files and replace bitcode symbols.
44-
LTO.reset(new BitcodeCompiler);
45-
for (BitcodeFile *F : BitcodeFiles)
46-
LTO->add(*F);
47-
48-
for (InputFile *File : LTO->compile()) {
49-
DenseMap<CachedHashStringRef, const InputFile *> DummyGroups;
50-
auto *Obj = cast<ObjFile<ELFT>>(File);
51-
Obj->parse(DummyGroups);
52-
for (Symbol *Sym : Obj->getGlobalSymbols())
53-
Sym->parseSymbolVersion();
54-
ObjectFiles.push_back(File);
55-
}
56-
}
57-
5835
// Set a flag for --trace-symbol so that we can print out a log message
5936
// if a new symbol with the same name is inserted into the symbol table.
6037
void SymbolTable::trace(StringRef Name) {
@@ -609,8 +586,3 @@ void elf::resolveSymbol(Symbol *Old, const Symbol &New) {
609586
llvm_unreachable("bad symbol kind");
610587
}
611588
}
612-
613-
template void SymbolTable::addCombinedLTOObject<ELF32LE>();
614-
template void SymbolTable::addCombinedLTOObject<ELF32BE>();
615-
template void SymbolTable::addCombinedLTOObject<ELF64LE>();
616-
template void SymbolTable::addCombinedLTOObject<ELF64BE>();

Diff for: ‎lld/ELF/SymbolTable.h

-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define LLD_ELF_SYMBOL_TABLE_H
1111

1212
#include "InputFiles.h"
13-
#include "LTO.h"
1413
#include "lld/Common/Strings.h"
1514
#include "llvm/ADT/CachedHashString.h"
1615
#include "llvm/ADT/DenseMap.h"
@@ -40,7 +39,6 @@ class Undefined;
4039
// is one add* function per symbol type.
4140
class SymbolTable {
4241
public:
43-
template <class ELFT> void addCombinedLTOObject();
4442
void wrap(Symbol *Sym, Symbol *Real, Symbol *Wrap);
4543

4644
ArrayRef<Symbol *> getSymbols() const { return SymVector; }
@@ -92,9 +90,6 @@ class SymbolTable {
9290
// can have the same name. We use this map to handle "extern C++ {}"
9391
// directive in version scripts.
9492
llvm::Optional<llvm::StringMap<std::vector<Symbol *>>> DemangledSyms;
95-
96-
// For LTO.
97-
std::unique_ptr<BitcodeCompiler> LTO;
9893
};
9994

10095
extern SymbolTable *Symtab;

0 commit comments

Comments
 (0)
Please sign in to comment.