[llvm] r251746 - Simplify the handling of the archive string table.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 31 13:06:13 PDT 2015


Author: rafael
Date: Sat Oct 31 15:06:13 2015
New Revision: 251746

URL: http://llvm.org/viewvc/llvm-project?rev=251746&view=rev
Log:
Simplify the handling of the archive string table.

We only need to store a StringRef

Modified:
    llvm/trunk/include/llvm/Object/Archive.h
    llvm/trunk/lib/Object/Archive.cpp

Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=251746&r1=251745&r2=251746&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Sat Oct 31 15:06:13 2015
@@ -218,7 +218,7 @@ public:
 
 private:
   child_iterator SymbolTable;
-  child_iterator StringTable;
+  StringRef StringTable;
   child_iterator FirstRegular;
   unsigned Format : 2;
   unsigned IsThin : 1;

Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=251746&r1=251745&r2=251746&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Sat Oct 31 15:06:13 2015
@@ -179,17 +179,11 @@ ErrorOr<StringRef> Archive::Child::getNa
     std::size_t offset;
     if (name.substr(1).rtrim(" ").getAsInteger(10, offset))
       llvm_unreachable("Long name offset is not an integer");
-    const char *addr = Parent->StringTable->Data.begin()
-                       + sizeof(ArchiveMemberHeader)
-                       + offset;
+
     // Verify it.
-    if (Parent->StringTable == Parent->child_end()
-        || addr < (Parent->StringTable->Data.begin()
-                   + sizeof(ArchiveMemberHeader))
-        || addr > (Parent->StringTable->Data.begin()
-                   + sizeof(ArchiveMemberHeader)
-                   + Parent->StringTable->getSize()))
+    if (offset >= Parent->StringTable.size())
       return object_error::parse_failed;
+    const char *addr = Parent->StringTable.begin() + offset;
 
     // GNU long file names end with a "/\n".
     if (Parent->kind() == K_GNU || Parent->kind() == K_MIPS64) {
@@ -240,7 +234,7 @@ ErrorOr<std::unique_ptr<Archive>> Archiv
 
 Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
     : Binary(Binary::ID_Archive, Source), SymbolTable(child_end()),
-      StringTable(child_end()), FirstRegular(child_end()) {
+      FirstRegular(child_end()) {
   StringRef Buffer = Data.getBuffer();
   // Check for sufficient magic.
   if (Buffer.startswith(ThinMagic)) {
@@ -328,7 +322,9 @@ Archive::Archive(MemoryBufferRef Source,
 
   if (Name == "//") {
     Format = has64SymTable ? K_MIPS64 : K_GNU;
-    StringTable = i;
+    // The string table is never an external member, so we just assert on the
+    // ErrorOr.
+    StringTable = *i->getBuffer();
     ++i;
     FirstRegular = i;
     ec = std::error_code();
@@ -360,7 +356,9 @@ Archive::Archive(MemoryBufferRef Source,
   Name = i->getRawName();
 
   if (Name == "//") {
-    StringTable = i;
+    // The string table is never an external member, so we just assert on the
+    // ErrorOr.
+    StringTable = *i->getBuffer();
     ++i;
   }
 




More information about the llvm-commits mailing list