Handle archives with paths in the names.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 18 Dec 2015 16:07:17 +0000 (16:07 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 18 Dec 2015 16:07:17 +0000 (16:07 +0000)
We always create archives with just he filename as the member name, but
other archives can put a more complicated path in there.

This patches handles it by computing just the filename as we do when
adding a new member.

If storing the path is important for some reason, we should probably
have an orthogonal option for doing that and do it for both old and new
members.

Fixes pr25877.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256001 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/ArchiveWriter.cpp
test/Object/Inputs/pr25877.lib [new file with mode: 0644]
test/Object/pr25877.test [new file with mode: 0644]

index f207dfb..c7343fd 100644 (file)
@@ -415,8 +415,10 @@ llvm::writeArchive(StringRef ArcName,
       ErrorOr<uint32_t> Size = OldMember.getSize();
       if (std::error_code EC = Size.getError())
         return std::make_pair("", EC);
-      printMemberHeader(Out, Kind, Thin, I.getName(), StringMapIndexIter,
-                        ModTime, UID, GID, Perms, Size.get());
+      StringRef FileName = I.getName();
+      printMemberHeader(Out, Kind, Thin, sys::path::filename(FileName),
+                        StringMapIndexIter, ModTime, UID, GID, Perms,
+                        Size.get());
     }
 
     if (!Thin)
diff --git a/test/Object/Inputs/pr25877.lib b/test/Object/Inputs/pr25877.lib
new file mode 100644 (file)
index 0000000..401cbeb
Binary files /dev/null and b/test/Object/Inputs/pr25877.lib differ
diff --git a/test/Object/pr25877.test b/test/Object/pr25877.test
new file mode 100644 (file)
index 0000000..c323d62
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: echo create %t.a > %t.mri
+; RUN: echo addlib %p/Inputs/pr25877.lib >> %t.mri
+; RUN: echo save >> %t.mri
+; RUN: echo end >> %t.mri
+
+; RUN: llvm-ar -M  < %t.mri
+; RUN: llvm-ar t %t.a | FileCheck %s
+
+; CHECK: foo.obj