From 5cb34077e879c03d460dedad7aaa421bd2bd08a3 Mon Sep 17 00:00:00 2001 From: David Callahan Date: Wed, 30 Nov 2016 22:32:58 +0000 Subject: [PATCH] Only computeRelativePath() on new members Summary: When using thin archives, and processing the same archive multiple times, we were mangling existing entries. The root cause is that we were calling computeRelativePath() more than once. Here, we only call it when adding new members to an archive. Note that D27218 changes the way thin archives are printed, and will break the new unit test included here. Depending on which one lands first, the other will need to be slightly modified. Reviewers: rafael, davide Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27217 llvm-svn: 288280 --- llvm/include/llvm/Object/ArchiveWriter.h | 1 + llvm/lib/Object/ArchiveWriter.cpp | 11 ++++++++--- llvm/test/Object/archive-thin-create.test | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Object/archive-thin-create.test diff --git a/llvm/include/llvm/Object/ArchiveWriter.h b/llvm/include/llvm/Object/ArchiveWriter.h index 6b40843..3e84a58 100644 --- a/llvm/include/llvm/Object/ArchiveWriter.h +++ b/llvm/include/llvm/Object/ArchiveWriter.h @@ -25,6 +25,7 @@ struct NewArchiveMember { sys::TimePoint ModTime; unsigned UID = 0, GID = 0, Perms = 0644; + bool IsNew = false; NewArchiveMember() = default; NewArchiveMember(MemoryBufferRef BufRef); diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index 64d04a0..f8e3c5a 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -45,6 +45,7 @@ NewArchiveMember::getOldMember(const object::Archive::Child &OldMember, return BufOrErr.takeError(); NewArchiveMember M; + assert(M.IsNew == false); M.Buf = MemoryBuffer::getMemBuffer(*BufOrErr, false); if (!Deterministic) { auto ModTimeOrErr = OldMember.getLastModified(); @@ -93,6 +94,7 @@ Expected NewArchiveMember::getFile(StringRef FileName, return errorCodeToError(std::error_code(errno, std::generic_category())); NewArchiveMember M; + M.IsNew = true; M.Buf = std::move(*MemberBufferOrErr); if (!Deterministic) { M.ModTime = std::chrono::time_point_cast( @@ -231,9 +233,12 @@ static void writeStringTable(raw_fd_ostream &Out, StringRef ArcName, } StringMapIndexes.push_back(Out.tell() - StartOffset); - if (Thin) - Out << computeRelativePath(ArcName, Path); - else + if (Thin) { + if (M.IsNew) + Out << computeRelativePath(ArcName, Path); + else + Out << M.Buf->getBufferIdentifier(); + } else Out << Name; Out << "/\n"; diff --git a/llvm/test/Object/archive-thin-create.test b/llvm/test/Object/archive-thin-create.test new file mode 100644 index 0000000..d9ee518 --- /dev/null +++ b/llvm/test/Object/archive-thin-create.test @@ -0,0 +1,14 @@ +RUN: mkdir -p %t +RUN: cd %t +RUN: mkdir -p foo +RUN: touch foo/test1.o +RUN: touch foo/test2.o +RUN: llvm-ar qcT foo/libtest.a foo/test1.o +RUN: llvm-ar qcT foo/libtest.a foo/test1.o +RUN: llvm-ar qcT foo/libtest.a foo/test2.o +RUN: llvm-ar t foo/libtest.a | FileCheck %s + +CHECK: test1.o +CHECK: test1.o +CHECK: test2.o + -- 2.7.4