[ELF] - Use backward slashes inside response files
authorGeorge Rimar <grimar@accesssoftek.com>
Fri, 11 Nov 2016 13:23:13 +0000 (13:23 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Fri, 11 Nov 2016 13:23:13 +0000 (13:23 +0000)
Patch replaces forward slashes with backward inside response.txt

This is https://llvm.org/bugs/show_bug.cgi?id=30951.

Differential revision: https://reviews.llvm.org/D26443

llvm-svn: 286589

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

index 47738ce..015e84e 100644 (file)
@@ -50,6 +50,12 @@ static void writeMember(raw_fd_ostream &OS, StringRef Path, StringRef Data) {
   OS << Data;                            // c_filedata
 }
 
+// Converts path to use unix path separators so the cpio can be extracted on
+// both unix and windows.
+static void convertToUnixPathSeparator(SmallString<128> &Path) {
+  std::replace(Path.begin(), Path.end(), '\\', '/');
+}
+
 void CpioFile::append(StringRef Path, StringRef Data) {
   if (!Seen.insert(Path).second)
     return;
@@ -59,10 +65,7 @@ void CpioFile::append(StringRef Path, StringRef Data) {
   // (i.e. in that case we are creating baz.cpio.)
   SmallString<128> Fullpath;
   path::append(Fullpath, Basename, Path);
-
-  // Use unix path separators so the cpio can be extracted on both unix and
-  // windows.
-  std::replace(Fullpath.begin(), Fullpath.end(), '\\', '/');
+  convertToUnixPathSeparator(Fullpath);
 
   writeMember(*OS, Fullpath, Data);
 
@@ -76,6 +79,8 @@ void CpioFile::append(StringRef Path, StringRef Data) {
 // Makes a given pathname an absolute path first, and then remove
 // beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
 // assuming that the current directory is "/home/john/bar".
+// Returned string is a backslash-separated path even on Windows to avoid
+// a mess with backslash-as-escape and backslash-as-path-separator.
 std::string lld::relativeToRoot(StringRef Path) {
   SmallString<128> Abs = Path;
   if (sys::fs::make_absolute(Abs))
@@ -93,6 +98,7 @@ std::string lld::relativeToRoot(StringRef Path) {
     Res = Root.substr(2);
 
   path::append(Res, path::relative_path(Abs));
+  convertToUnixPathSeparator(Res);
 
   return Res.str();
 }
diff --git a/lld/test/ELF/reproduce-windows2.s b/lld/test/ELF/reproduce-windows2.s
new file mode 100644 (file)
index 0000000..d428288
--- /dev/null
@@ -0,0 +1,11 @@
+# REQUIRES: system-windows, x86, cpio
+
+# Test that a response.txt file always uses / instead of \.
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/build
+# RUN: llvm-mc %s -o %t.dir/build/foo.o -filetype=obj -triple=x86_64-pc-linux
+# RUN: cd %t.dir
+# RUN: ld.lld build/foo.o --reproduce repro
+# RUN: echo "*response.txt" > list.txt
+# RUN: cpio -i --to-stdout --pattern-file=list.txt < repro.cpio | FileCheck %s
+# CHECK: {{.*}}/build/foo.o
index 5cc10ad..ab34254 100644 (file)
@@ -207,6 +207,10 @@ if platform.system() in ['Darwin']:
 if platform.system() in ['FreeBSD', 'Linux']:
     config.available_features.add('system-linker-elf')
 
+# Running on Windows
+if platform.system() in ['Windows']:
+    config.available_features.add('system-windows')
+
 # Set if host-cxxabi's demangler can handle target's symbols.
 if platform.system() not in ['Windows']:
     config.available_features.add('demangler')