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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288280 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Callahan 2016-11-30 22:32:58 +00:00
parent 3143430807
commit bcdc161524
3 changed files with 23 additions and 3 deletions

View File

@ -25,6 +25,7 @@ struct NewArchiveMember {
sys::TimePoint<std::chrono::seconds> ModTime;
unsigned UID = 0, GID = 0, Perms = 0644;
bool IsNew = false;
NewArchiveMember() = default;
NewArchiveMember(MemoryBufferRef BufRef);

View File

@ -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> 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<std::chrono::seconds>(
@ -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";

View File

@ -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