[llvm] r251748 - Simplify handling of archive Symbol tables.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 31 14:03:29 PDT 2015


Author: rafael
Date: Sat Oct 31 16:03:29 2015
New Revision: 251748

URL: http://llvm.org/viewvc/llvm-project?rev=251748&view=rev
Log:
Simplify handling of archive Symbol tables.

We only need to store a StringRef.

Modified:
    llvm/trunk/include/llvm/Object/Archive.h
    llvm/trunk/lib/Object/Archive.cpp
    llvm/trunk/tools/llvm-objdump/MachODump.cpp

Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=251748&r1=251747&r2=251748&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Sat Oct 31 16:03:29 2015
@@ -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;

Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=251748&r1=251747&r2=251748&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Sat Oct 31 16:03:29 2015
@@ -233,8 +233,7 @@ ErrorOr<std::unique_ptr<Archive>> Archiv
 }
 
 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,
 
   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,
       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,
 
   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,
   }
 
   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
   return child_end();
 }
 
-bool Archive::hasSymbolTable() const {
-  return SymbolTable != child_end();
-}
+bool Archive::hasSymbolTable() const { return !SymbolTable.empty(); }

Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=251748&r1=251747&r2=251748&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Sat Oct 31 16:03:29 2015
@@ -1452,13 +1452,8 @@ static void printArchiveChild(Archive::C
 }
 
 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);
   }




More information about the llvm-commits mailing list