[ELF] Don't replace path separators on *NIX.
authorDavide Italiano <davide@freebsd.org>
Wed, 16 Nov 2016 19:35:36 +0000 (19:35 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 16 Nov 2016 19:35:36 +0000 (19:35 +0000)
Apparently this is wrong because it's legal to have a filename
on UNIX which contains a backslash.

Differential Revision:  https://reviews.llvm.org/D26734

llvm-svn: 287143

lld/lib/Core/Reproduce.cpp
lld/test/ELF/reproduce-backslash.s [new file with mode: 0644]

index a6f5019..5ff668e 100644 (file)
@@ -53,7 +53,9 @@ static void writeMember(raw_fd_ostream &OS, StringRef Path, StringRef Data) {
 // Converts path to use unix path separators so the cpio can be extracted on
 // both unix and windows.
 static void convertToUnixPathSeparator(SmallString<128> &Path) {
+#ifdef LLVM_ON_WIN32
   std::replace(Path.begin(), Path.end(), '\\', '/');
+#endif
 }
 
 void CpioFile::append(StringRef Path, StringRef Data) {
diff --git a/lld/test/ELF/reproduce-backslash.s b/lld/test/ELF/reproduce-backslash.s
new file mode 100644 (file)
index 0000000..a694bfc
--- /dev/null
@@ -0,0 +1,9 @@
+# REQUIRES: x86, cpio, shell
+
+# Test that we don't erroneously replace \ with / on UNIX, as it's
+# legal for a filename to contain backslashes.
+# RUN: llvm-mc %s -o foo\\.o -filetype=obj -triple=x86_64-pc-linux
+# RUN: ld.lld foo\\.o --reproduce repro
+# RUN: cpio -t < repro.cpio | FileCheck %s
+
+# CHECK: repro/{{.*}}/foo\.o