[PATCH] D45516: [ELF] - Refactor lazy symbol duplicated code.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 12 04:13:23 PDT 2018
grimar updated this revision to Diff 142145.
grimar added a comment.
- Reimplemented, addressed comments.
What do you think about this version, Rui? Is it still too much?
https://reviews.llvm.org/D45516
Files:
ELF/SymbolTable.cpp
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -595,50 +595,55 @@
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.
+static void
+replaceOrFetchLazy(StringRef Name,
+ llvm::function_ref<void(Symbol *S, uint8_t Type)> Replace,
+ llvm::function_ref<void(Symbol *S)> Fetch) {
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);
+ Replace(S, Symbol::UnknownType);
return;
}
if (!S->isUndefined())
return;
// 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);
+ Replace(S, S->Type);
S->Binding = STB_WEAK;
return;
}
- if (InputFile *File = F.fetch(Sym))
- addFile<ELFT>(File);
+ Fetch(S);
}
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(Name,
+ [&](Symbol *S, uint8_t Type) {
+ replaceSymbol<LazyArchive>(S, F, Sym, Type);
+ },
+ [&](Symbol *S) {
+ if (InputFile *File = F.fetch(Sym))
+ addFile<ELFT>(File);
+ });
+}
- // 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(Name,
+ [&](Symbol *S, uint8_t Type) {
+ replaceSymbol<LazyObject>(S, Obj, Name, Type);
+ },
+ [&](Symbol *S) {
+ if (InputFile *F = Obj.fetch())
+ addFile<ELFT>(F);
+ });
}
template <class ELFT> void SymbolTable::fetchLazy(Symbol *Sym) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45516.142145.patch
Type: text/x-patch
Size: 2864 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180412/2a43da56/attachment.bin>
More information about the llvm-commits
mailing list