summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-04-03 17:16:52 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-04-03 17:16:52 +0000
commit1ef746ba21c9b999f25bcb6dfecea59da90f29a9 (patch)
treea66292101fc8ed1626fcfc3f5abd3982e297f022
parent428e9d9d878441c010daf6b62399d1df69bc9433 (diff)
downloadbcm5719-llvm-1ef746ba21c9b999f25bcb6dfecea59da90f29a9.tar.gz
bcm5719-llvm-1ef746ba21c9b999f25bcb6dfecea59da90f29a9.zip
[ELF] - Eliminate Lazy class.
Patch removes Lazy class which is just an excessive layer. Differential revision: https://reviews.llvm.org/D45083 llvm-svn: 329086
-rw-r--r--lld/ELF/Driver.cpp8
-rw-r--r--lld/ELF/InputFiles.h1
-rw-r--r--lld/ELF/SymbolTable.cpp30
-rw-r--r--lld/ELF/SymbolTable.h3
-rw-r--r--lld/ELF/Symbols.cpp6
-rw-r--r--lld/ELF/Symbols.h32
6 files changed, 31 insertions, 49 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index df9f32a61e3..04da6caba2e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1081,12 +1081,16 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
// Handle the `--undefined <sym>` options.
for (StringRef S : Config->Undefined)
- Symtab->fetchIfLazy<ELFT>(S);
+ if (Symbol *Sym = Symtab->find(S))
+ if (InputFile *F = Symtab->fetchIfLazy(Sym))
+ Symtab->addFile<ELFT>(F);
// If an entry symbol is in a static archive, pull out that file now
// to complete the symbol table. After this, no new names except a
// few linker-synthesized ones will be added to the symbol table.
- Symtab->fetchIfLazy<ELFT>(Config->Entry);
+ if (Symbol *Sym = Symtab->find(Config->Entry))
+ if (InputFile *F = Symtab->fetchIfLazy(Sym))
+ Symtab->addFile<ELFT>(F);
// Return if there were name resolution errors.
if (errorCount())
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index 635c6600882..ab12bb1dac5 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -46,7 +46,6 @@ namespace elf {
using llvm::object::Archive;
-class Lazy;
class Symbol;
// If -reproduce option is given, all input files are written
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index e27a48ae5b0..2e81ee031e7 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -309,12 +309,12 @@ Symbol *SymbolTable::addUndefined(StringRef Name, uint8_t Binding,
if (!Config->GcSections)
SS->getFile<ELFT>().IsNeeded = true;
}
- if (auto *L = dyn_cast<Lazy>(S)) {
+ if (S->isLazy()) {
// An undefined weak will not fetch archive members. See comment on Lazy in
// Symbols.h for the details.
if (Binding == STB_WEAK)
- L->Type = Type;
- else if (InputFile *F = L->fetch())
+ S->Type = Type;
+ else if (InputFile *F = Symtab->fetchIfLazy(S))
addFile<ELFT>(F);
}
return S;
@@ -574,16 +574,15 @@ void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
addFile<ELFT>(F);
}
-// If we already saw this symbol, force loading its file.
-template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
- if (Symbol *B = find(Name)) {
- // Mark the symbol not to be eliminated by LTO
- // even if it is a bitcode symbol.
- B->IsUsedInRegularObj = true;
- if (auto *L = dyn_cast<Lazy>(B))
- if (InputFile *File = L->fetch())
- addFile<ELFT>(File);
- }
+InputFile *SymbolTable::fetchIfLazy(Symbol *Sym) {
+ // Mark the symbol not to be eliminated by LTO
+ // even if it is a bitcode symbol.
+ Sym->IsUsedInRegularObj = true;
+ if (LazyArchive *L = dyn_cast<LazyArchive>(Sym))
+ return L->fetch();
+ if (LazyObject *L = dyn_cast<LazyObject>(Sym))
+ return cast<LazyObjFile>(L->File)->fetch();
+ return nullptr;
}
// Initialize DemangledSyms with a map from demangled symbols to symbol
@@ -806,8 +805,3 @@ template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> &,
template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> &,
const typename ELF64BE::Sym &,
uint32_t Alignment, uint32_t);
-
-template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
-template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
-template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
-template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);
diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h
index 7937a2a4a31..ad8b3eff45d 100644
--- a/lld/ELF/SymbolTable.h
+++ b/lld/ELF/SymbolTable.h
@@ -77,7 +77,8 @@ public:
uint8_t Visibility, bool CanOmitFromDynSym,
InputFile *File);
- template <class ELFT> void fetchIfLazy(StringRef Name);
+ InputFile *fetchIfLazy(Symbol *Sym);
+
void scanVersionScript();
Symbol *find(StringRef Name);
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 1bcb051316d..b932c318e55 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -207,12 +207,6 @@ void Symbol::parseSymbolVersion() {
Verstr);
}
-InputFile *Lazy::fetch() {
- if (auto *Sym = dyn_cast<LazyArchive>(this))
- return Sym->fetch();
- return cast<LazyObjFile>(File)->fetch();
-}
-
InputFile *LazyArchive::fetch() { return cast<ArchiveFile>(File)->fetch(Sym); }
uint8_t Symbol::computeBinding() const {
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 32d7cd4398a..81c85aa72f9 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -99,7 +99,7 @@ public:
// True if this is an undefined weak symbol. This only works once
// all input files have been added.
bool isUndefWeak() const {
- // See comment on Lazy for details.
+ // See comment on lazy symbols for details.
return isWeak() && (isUndefined() || isLazy());
}
@@ -248,38 +248,27 @@ public:
uint32_t Alignment;
};
-// This represents a symbol that is not yet in the link, but we know where to
-// find it if needed. If the resolver finds both Undefined and Lazy for the same
-// name, it will ask the Lazy to load a file.
+// LazyArchive and LazyObject represent a symbols that is not yet in the link,
+// but we know where to find it if needed. If the resolver finds both Undefined
+// and Lazy for the same name, it will ask the Lazy to load a file.
//
// A special complication is the handling of weak undefined symbols. They should
// not load a file, but we have to remember we have seen both the weak undefined
// and the lazy. We represent that with a lazy symbol with a weak binding. This
// means that code looking for undefined symbols normally also has to take lazy
// symbols into consideration.
-class Lazy : public Symbol {
-public:
- static bool classof(const Symbol *S) { return S->isLazy(); }
-
- // Returns an object file for this symbol, or a nullptr if the file
- // was already returned.
- InputFile *fetch();
-
-protected:
- Lazy(Kind K, InputFile &File, StringRef Name, uint8_t Type)
- : Symbol(K, &File, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT,
- Type) {}
-};
// This class represents a symbol defined in an archive file. It is
// created from an archive file header, and it knows how to load an
// object file from an archive to replace itself with a defined
// symbol.
-class LazyArchive : public Lazy {
+class LazyArchive : public Symbol {
public:
LazyArchive(InputFile &File, const llvm::object::Archive::Symbol S,
uint8_t Type)
- : Lazy(LazyArchiveKind, File, S.getName(), Type), Sym(S) {}
+ : Symbol(LazyArchiveKind, &File, S.getName(), llvm::ELF::STB_GLOBAL,
+ llvm::ELF::STV_DEFAULT, Type),
+ Sym(S) {}
static bool classof(const Symbol *S) { return S->kind() == LazyArchiveKind; }
@@ -291,10 +280,11 @@ private:
// LazyObject symbols represents symbols in object files between
// --start-lib and --end-lib options.
-class LazyObject : public Lazy {
+class LazyObject : public Symbol {
public:
LazyObject(InputFile &File, StringRef Name, uint8_t Type)
- : Lazy(LazyObjectKind, File, Name, Type) {}
+ : Symbol(LazyObjectKind, &File, Name, llvm::ELF::STB_GLOBAL,
+ llvm::ELF::STV_DEFAULT, Type) {}
static bool classof(const Symbol *S) { return S->kind() == LazyObjectKind; }
};
OpenPOWER on IntegriCloud