[PATCH] D55860: [Object] Deduplicate long archive member names

Peter Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 19 08:18:22 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL349637: [Object] Deduplicate long archive member names (authored by Lekensteyn, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55860?vs=178892&id=178893#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55860/new/

https://reviews.llvm.org/D55860

Files:
  llvm/trunk/lib/Object/ArchiveWriter.cpp
  llvm/trunk/test/Object/archive-format.test


Index: llvm/trunk/test/Object/archive-format.test
===================================================================
--- llvm/trunk/test/Object/archive-format.test
+++ llvm/trunk/test/Object/archive-format.test
@@ -15,8 +15,7 @@
 RUN: cat %t.a | FileCheck -strict-whitespace %s
 
 CHECK:      !<arch>
-CHECK-NEXT: //                                              36        `
-CHECK-NEXT: 0123456789abcdef/
+CHECK-NEXT: //                                              18        `
 CHECK-NEXT: 0123456789abcdef/
 CHECK-NEXT: 0123456789abcde/0           0     0     644     4         `
 CHECK-NEXT: bar.
@@ -24,7 +23,7 @@
 CHECK-NEXT: zed.
 CHECK-SAME: 0123456789abcde/0           0     0     644     4         `
 CHECK-NEXT: bar2
-CHECK-SAME: /18             0           0     0     644     4         `
+CHECK-SAME: /0              0           0     0     644     4         `
 CHECK-NEXT: zed2
 
 RUN: rm -f %t.a
Index: llvm/trunk/lib/Object/ArchiveWriter.cpp
===================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp
@@ -250,6 +250,7 @@
 
 static void printMemberHeader(raw_ostream &Out, uint64_t Pos,
                               raw_ostream &StringTable,
+                              StringMap<uint64_t> &MemberNames,
                               object::Archive::Kind Kind, bool Thin,
                               StringRef ArcName, const NewArchiveMember &M,
                               sys::TimePoint<std::chrono::seconds> ModTime,
@@ -262,8 +263,20 @@
     return printGNUSmallMemberHeader(Out, M.MemberName, ModTime, M.UID, M.GID,
                                      M.Perms, Size);
   Out << '/';
-  uint64_t NamePos = StringTable.tell();
-  addToStringTable(StringTable, ArcName, M, Thin);
+  uint64_t NamePos;
+  if (Thin) {
+    NamePos = StringTable.tell();
+    addToStringTable(StringTable, ArcName, M, Thin);
+  } else {
+    StringMap<uint64_t>::const_iterator it = MemberNames.find(M.MemberName);
+    if (it == MemberNames.end()) {
+      NamePos = StringTable.tell();
+      addToStringTable(StringTable, ArcName, M, Thin);
+      MemberNames[M.MemberName] = NamePos;
+    } else {
+      NamePos = it->second;
+    }
+  }
   printWithSpacePadding(Out, NamePos, 15);
   printRestOfMemberHeader(Out, ModTime, M.UID, M.GID, M.Perms, Size);
 }
@@ -433,6 +446,11 @@
   std::vector<MemberData> Ret;
   bool HasObject = false;
 
+  // Deduplicate long member names in the string table and reuse earlier name
+  // offsets. This especially saves space for COFF Import libraries where all
+  // members have the same name.
+  StringMap<uint64_t> MemberNames;
+
   // UniqueTimestamps is a special case to improve debugging on Darwin:
   //
   // The Darwin linker does not link debug info into the final
@@ -505,8 +523,8 @@
       ModTime = sys::toTimePoint(FilenameCount[M.MemberName]++);
     else
       ModTime = M.ModTime;
-    printMemberHeader(Out, Pos, StringTable, Kind, Thin, ArcName, M, ModTime,
-                      Buf.getBufferSize() + MemberPadding);
+    printMemberHeader(Out, Pos, StringTable, MemberNames, Kind, Thin, ArcName,
+                      M, ModTime, Buf.getBufferSize() + MemberPadding);
     Out.flush();
 
     Expected<std::vector<unsigned>> Symbols =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55860.178893.patch
Type: text/x-patch
Size: 3309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181219/b67620c3/attachment.bin>


More information about the llvm-commits mailing list