[lld] r329039 - Merge LazyArchive::fetch() and ArchiveFile::getMember(). NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 2 19:06:57 PDT 2018
Author: ruiu
Date: Mon Apr 2 19:06:57 2018
New Revision: 329039
URL: http://llvm.org/viewvc/llvm-project?rev=329039&view=rev
Log:
Merge LazyArchive::fetch() and ArchiveFile::getMember(). NFC.
They are to pull out an object file for a symbol, but for a historical
reason the code is written in two separate functions. This patch
merges them.
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=329039&r1=329038&r2=329039&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Apr 2 19:06:57 2018
@@ -742,27 +742,26 @@ template <class ELFT> void ArchiveFile::
}
// Returns a buffer pointing to a member file containing a given symbol.
-std::pair<MemoryBufferRef, uint64_t>
-ArchiveFile::getMember(const Archive::Symbol *Sym) {
+InputFile *ArchiveFile::fetch(const Archive::Symbol &Sym) {
Archive::Child C =
- CHECK(Sym->getMember(), toString(this) +
- ": could not get the member for symbol " +
- Sym->getName());
+ CHECK(Sym.getMember(), toString(this) +
+ ": could not get the member for symbol " +
+ Sym.getName());
if (!Seen.insert(C.getChildOffset()).second)
- return {MemoryBufferRef(), 0};
+ return nullptr;
- MemoryBufferRef Ret =
+ MemoryBufferRef MB =
CHECK(C.getMemoryBufferRef(),
toString(this) +
": could not get the buffer for the member defining symbol " +
- Sym->getName());
+ Sym.getName());
- if (C.getParent()->isThin() && Tar)
- Tar->append(relativeToRoot(CHECK(C.getFullName(), this)), Ret.getBuffer());
- if (C.getParent()->isThin())
- return {Ret, 0};
- return {Ret, C.getChildOffset()};
+ if (Tar && C.getParent()->isThin())
+ Tar->append(relativeToRoot(CHECK(C.getFullName(), this)), MB.getBuffer());
+
+ return createObjectFile(MB, getName(),
+ C.getParent()->isThin() ? 0 : C.getChildOffset());
}
template <class ELFT>
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=329039&r1=329038&r2=329039&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Mon Apr 2 19:06:57 2018
@@ -267,11 +267,11 @@ public:
static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
template <class ELFT> void parse();
- // Returns a memory buffer for a given symbol and the offset in the archive
- // for the member. An empty memory buffer and an offset of zero
- // is returned if we have already returned the same memory buffer.
- // (So that we don't instantiate same members more than once.)
- std::pair<MemoryBufferRef, uint64_t> getMember(const Archive::Symbol *Sym);
+ // Pulls out an object file that contains a definition for Sym and
+ // returns it. If the same file was instantiated before, this
+ // function returns a nullptr (so we don't instantiate the same file
+ // more than once.)
+ InputFile *fetch(const Archive::Symbol &Sym);
private:
std::unique_ptr<Archive> File;
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=329039&r1=329038&r2=329039&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Mon Apr 2 19:06:57 2018
@@ -548,9 +548,8 @@ void SymbolTable::addLazyArchive(StringR
S->Binding = STB_WEAK;
return;
}
- std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
- if (!MBInfo.first.getBuffer().empty())
- addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
+ if (InputFile *File = F.fetch(Sym))
+ addFile<ELFT>(File);
}
template <class ELFT>
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=329039&r1=329038&r2=329039&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Apr 2 19:06:57 2018
@@ -208,23 +208,12 @@ void Symbol::parseSymbolVersion() {
}
InputFile *Lazy::fetch() {
- if (auto *S = dyn_cast<LazyArchive>(this))
- return S->fetch();
- return cast<LazyObject>(this)->fetch();
+ if (auto *Sym = dyn_cast<LazyArchive>(this))
+ return Sym->fetch();
+ return cast<LazyObjFile>(File)->fetch();
}
-InputFile *LazyArchive::fetch() {
- auto *F = cast<ArchiveFile>(File);
- std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
-
- // getMember returns an empty buffer if the member was already
- // read from the library.
- if (MBInfo.first.getBuffer().empty())
- return nullptr;
- return createObjectFile(MBInfo.first, F->getName(), MBInfo.second);
-}
-
-InputFile *LazyObject::fetch() { return cast<LazyObjFile>(File)->fetch(); }
+InputFile *LazyArchive::fetch() { return cast<ArchiveFile>(File)->fetch(Sym); }
uint8_t Symbol::computeBinding() const {
if (Config->Relocatable)
More information about the llvm-commits
mailing list