From: Rafael Espindola Date: Sat, 31 Oct 2015 21:03:29 +0000 (+0000) Subject: Simplify handling of archive Symbol tables. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=2825a232535b88858fc05b1aa84184466138e9c7;p=oota-llvm.git Simplify handling of archive Symbol tables. We only need to store a StringRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251748 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h index 0d394fd98b6..acf22b8f7e7 100644 --- a/include/llvm/Object/Archive.h +++ b/include/llvm/Object/Archive.h @@ -208,16 +208,11 @@ public: child_iterator findSym(StringRef name) const; bool hasSymbolTable() const; - child_iterator getSymbolTableChild() const { return SymbolTable; } - StringRef getSymbolTable() const { - // We know that the symbol table is not an external file, - // so we just assert there is no error. - return *SymbolTable->getBuffer(); - } + StringRef getSymbolTable() const { return SymbolTable; } uint32_t getNumberOfSymbols() const; private: - child_iterator SymbolTable; + StringRef SymbolTable; StringRef StringTable; child_iterator FirstRegular; unsigned Format : 2; diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index 2e71b8205d4..4bb50a0f757 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -233,8 +233,7 @@ ErrorOr> Archive::create(MemoryBufferRef Source) { } Archive::Archive(MemoryBufferRef Source, std::error_code &ec) - : Binary(Binary::ID_Archive, Source), SymbolTable(child_end()), - FirstRegular(child_end()) { + : Binary(Binary::ID_Archive, Source), FirstRegular(child_end()) { StringRef Buffer = Data.getBuffer(); // Check for sufficient magic. if (Buffer.startswith(ThinMagic)) { @@ -278,7 +277,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec) if (Name == "__.SYMDEF") { Format = K_BSD; - SymbolTable = i; + // We know that the symbol table is not an external file, so we just assert + // there is no error. + SymbolTable = *i->getBuffer(); ++i; FirstRegular = i; ec = std::error_code(); @@ -294,7 +295,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec) return; Name = NameOrErr.get(); if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") { - SymbolTable = i; + // We know that the symbol table is not an external file, so we just + // assert there is no error. + SymbolTable = *i->getBuffer(); ++i; } FirstRegular = i; @@ -308,7 +311,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec) bool has64SymTable = false; if (Name == "/" || Name == "/SYM64/") { - SymbolTable = i; + // We know that the symbol table is not an external file, so we just assert + // there is no error. + SymbolTable = *i->getBuffer(); if (Name == "/SYM64/") has64SymTable = true; @@ -344,7 +349,9 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec) } Format = K_COFF; - SymbolTable = i; + // We know that the symbol table is not an external file, so we just assert + // there is no error. + SymbolTable = *i->getBuffer(); ++i; if (i == e) { @@ -551,6 +558,4 @@ Archive::child_iterator Archive::findSym(StringRef name) const { return child_end(); } -bool Archive::hasSymbolTable() const { - return SymbolTable != child_end(); -} +bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3ea6fe4c99b..b94b6d0f0cf 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -1452,13 +1452,8 @@ static void printArchiveChild(Archive::Child &C, bool verbose, } static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) { - if (A->hasSymbolTable()) { - Archive::child_iterator S = A->getSymbolTableChild(); - Archive::Child C = *S; - printArchiveChild(C, verbose, print_offset); - } - for (Archive::child_iterator I = A->child_begin(), E = A->child_end(); I != E; - ++I) { + for (Archive::child_iterator I = A->child_begin(false), E = A->child_end(); + I != E; ++I) { Archive::Child C = *I; printArchiveChild(C, verbose, print_offset); }