Simplify handling of archive Symbol tables.
authorRafael Espindola <rafael.espindola@gmail.com>
Sat, 31 Oct 2015 21:03:29 +0000 (21:03 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sat, 31 Oct 2015 21:03:29 +0000 (21:03 +0000)
We only need to store a StringRef.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251748 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0d394fd98b6a349286f0b0003aa1c9d32a00d437..acf22b8f7e7b4bcd30883fd9141ec426d4e36079 100644 (file)
@@ -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;
index 2e71b8205d4e392bd9248cfdb762f88ab2fc1b6f..4bb50a0f7570c0d2e01f8aa83fd028620e746116 100644 (file)
@@ -233,8 +233,7 @@ ErrorOr<std::unique_ptr<Archive>> 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(); }
index 3ea6fe4c99b7220e9400907380bcdf5eeef07e19..b94b6d0f0cff78e0ea32586874c73bda40780d98 100644 (file)
@@ -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);
   }