[PATCH] D55860: [Object] Deduplicate long archive member names
Peter Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 18 15:30:10 PST 2018
Lekensteyn created this revision.
Lekensteyn added reviewers: mstorsjo, Bigcheese, jyknight.
Herald added subscribers: llvm-commits, dexonsmith, mehdi_amini.
Import libraries as created by llvm-dlltool always use the same archive
member name for every object file (namely, the DLL library name). Ensure
that long names are not repeatedly stored in the string table.
Repository:
rL LLVM
https://reviews.llvm.org/D55860
Files:
lib/Object/ArchiveWriter.cpp
test/Object/archive-format.test
Index: test/Object/archive-format.test
===================================================================
--- test/Object/archive-format.test
+++ 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: lib/Object/ArchiveWriter.cpp
===================================================================
--- lib/Object/ArchiveWriter.cpp
+++ 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,19 @@
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 +445,10 @@
std::vector<MemberData> Ret;
bool HasObject = false;
+ // Deduplicate long member names in the string table and reuse earlier name
+ // offsets. This is especially important for COFF Import libraries.
+ 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 +521,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.178801.patch
Type: text/x-patch
Size: 3192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181218/5b07c61b/attachment.bin>
More information about the llvm-commits
mailing list