[lld] r330701 - [ELF] - Refactor lazy symbol duplicated code.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 24 02:41:56 PDT 2018
Author: grimar
Date: Tue Apr 24 02:41:56 2018
New Revision: 330701
URL: http://llvm.org/viewvc/llvm-project?rev=330701&view=rev
Log:
[ELF] - Refactor lazy symbol duplicated code.
Our code for LazyObject and LazyArchive duplicates.
This patch extracts the common part to remove
the duplication.
Differential revision: https://reviews.llvm.org/D45516
Modified:
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.h
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=330701&r1=330700&r2=330701&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Apr 24 02:41:56 2018
@@ -595,14 +595,18 @@ Symbol *SymbolTable::find(StringRef Name
return SymVector[It->second];
}
-template <class ELFT>
-void SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F,
- const object::Archive::Symbol Sym) {
+// This is used to handle lazy symbols. May replace existent
+// symbol with lazy version or request to Fetch it.
+template <class ELFT, typename LazyT, typename... ArgT>
+void replaceOrFetchLazy(StringRef Name, InputFile &File,
+ llvm::function_ref<InputFile *()> Fetch,
+ ArgT &&... Arg) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
+ std::tie(S, WasInserted) = Symtab->insert(Name);
if (WasInserted) {
- replaceSymbol<LazyArchive>(S, F, Sym, Symbol::UnknownType);
+ replaceSymbol<LazyT>(S, File, Symbol::UnknownType,
+ std::forward<ArgT>(Arg)...);
return;
}
if (!S->isUndefined())
@@ -611,34 +615,26 @@ void SymbolTable::addLazyArchive(StringR
// An undefined weak will not fetch archive members. See comment on Lazy in
// Symbols.h for the details.
if (S->isWeak()) {
- replaceSymbol<LazyArchive>(S, F, Sym, S->Type);
+ replaceSymbol<LazyT>(S, File, S->Type, std::forward<ArgT>(Arg)...);
S->Binding = STB_WEAK;
return;
}
- if (InputFile *File = F.fetch(Sym))
- addFile<ELFT>(File);
+
+ if (InputFile *F = Fetch())
+ Symtab->addFile<ELFT>(F);
}
template <class ELFT>
-void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
- Symbol *S;
- bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
- if (WasInserted) {
- replaceSymbol<LazyObject>(S, Obj, Name, Symbol::UnknownType);
- return;
- }
- if (!S->isUndefined())
- return;
+void SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F,
+ const object::Archive::Symbol Sym) {
+ replaceOrFetchLazy<ELFT, LazyArchive>(Name, F, [&]() { return F.fetch(Sym); },
+ Sym);
+}
- // See comment for addLazyArchive above.
- if (S->isWeak()) {
- replaceSymbol<LazyObject>(S, Obj, Name, S->Type);
- S->Binding = STB_WEAK;
- return;
- }
- if (InputFile *F = Obj.fetch())
- addFile<ELFT>(F);
+template <class ELFT>
+void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
+ replaceOrFetchLazy<ELFT, LazyObject>(Name, Obj, [&]() { return Obj.fetch(); },
+ Name);
}
template <class ELFT> void SymbolTable::fetchLazy(Symbol *Sym) {
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=330701&r1=330700&r2=330701&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Apr 24 02:41:56 2018
@@ -263,8 +263,8 @@ public:
// symbol.
class LazyArchive : public Symbol {
public:
- LazyArchive(InputFile &File, const llvm::object::Archive::Symbol S,
- uint8_t Type)
+ LazyArchive(InputFile &File, uint8_t Type,
+ const llvm::object::Archive::Symbol S)
: Symbol(LazyArchiveKind, &File, S.getName(), llvm::ELF::STB_GLOBAL,
llvm::ELF::STV_DEFAULT, Type),
Sym(S) {}
@@ -281,7 +281,7 @@ private:
// --start-lib and --end-lib options.
class LazyObject : public Symbol {
public:
- LazyObject(InputFile &File, StringRef Name, uint8_t Type)
+ LazyObject(InputFile &File, uint8_t Type, StringRef Name)
: Symbol(LazyObjectKind, &File, Name, llvm::ELF::STB_GLOBAL,
llvm::ELF::STV_DEFAULT, Type) {}
More information about the llvm-commits
mailing list