[PATCH] D22015: [ELF] Introduce a flag to parse response file according to windows rules

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 11:46:25 PDT 2016


davide added a reviewer: ruiu.
davide removed a subscriber: ruiu.
davide updated this revision to Diff 62926.
davide added a comment.

Attempt to address reviewers comments. This is pretty much what clang does.


http://reviews.llvm.org/D22015

Files:
  ELF/Config.h
  ELF/DriverUtils.cpp
  ELF/Options.td
  test/ELF/basic.s

Index: test/ELF/basic.s
===================================================================
--- test/ELF/basic.s
+++ test/ELF/basic.s
@@ -184,12 +184,18 @@
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 
-# Test for the response file
+# Test for the response file (POSIX quoting style)
 # RUN: echo " -o %t2" > %t.responsefile
-# RUN: ld.lld %t @%t.responsefile
+# RUN: ld.lld %t --rsp-quoting=posix @%t.responsefile
 # RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \
 # RUN:   | FileCheck %s
 
+# Test for the response file (Windows quoting style)
+# RUN: echo " c:\blah\foo" > %t.responsefile
+# RUN: not ld.lld --rsp-quoting=windows %t @%t.responsefile 2>&1 | FileCheck \
+# RUN:   %s --check-prefix=WINRSP
+# WINRSP: cannot open c:\blah\foo
+
 # RUN: not ld.lld %t.foo -o %t2 2>&1 | \
 # RUN:  FileCheck --check-prefix=MISSING %s
 # MISSING: cannot open {{.*}}.foo: {{[Nn]}}o such file or directory
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -156,6 +156,9 @@
 def unresolved_symbols: J<"unresolved-symbols=">,
   HelpText<"Determine how to handle unresolved symbols">;
 
+def rsp_quoting: J<"rsp-quoting=">,
+  HelpText<"Quoting style for response files. Values supported: windows|posix">;
+
 def verbose: F<"verbose">, HelpText<"Verbose mode">;
 
 def version: F<"version">, HelpText<"Display the version number">;
Index: ELF/DriverUtils.cpp
===================================================================
--- ELF/DriverUtils.cpp
+++ ELF/DriverUtils.cpp
@@ -17,6 +17,7 @@
 #include "Error.h"
 #include "lld/Config/Version.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -55,10 +56,27 @@
   unsigned MissingIndex;
   unsigned MissingCount;
 
+  for (const char *F : Argv) {
+    if (strcmp(F, "--rsp-quoting=posix") == 0)
+      Config->RspQuoting = "posix";
+    else if (strcmp(F, "--rsp-quoting=windows") == 0)
+      Config->RspQuoting = "windows";
+  }
+
+  if (Config->RspQuoting.empty())
+    Config->RspQuoting =
+        (Triple(sys::getProcessTriple()).getOS() == Triple::Win32) ? "windows"
+                                                                   : "posix";
+  if (Config->RspQuoting != "windows" && Config->RspQuoting != "posix")
+    error("invalid response file quoting: " + Config->RspQuoting);
+
   // Expand response files. '@<filename>' is replaced by the file's contents.
   SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());
   StringSaver Saver(Alloc);
-  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Vec);
+  cl::TokenizerCallback TC = Config->RspQuoting == "windows"
+                                 ? cl::TokenizeWindowsCommandLine
+                                 : cl::TokenizeGNUCommandLine;
+  cl::ExpandResponseFiles(Saver, TC, Vec);
 
   // Parse options and then do error checking.
   opt::InputArgList Args = this->ParseArgs(Vec, MissingIndex, MissingCount);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -59,6 +59,7 @@
   llvm::StringRef LtoAAPipeline;
   llvm::StringRef LtoNewPmPasses;
   llvm::StringRef OutputFile;
+  llvm::StringRef RspQuoting;
   llvm::StringRef SoName;
   llvm::StringRef Sysroot;
   llvm::StringSet<> TraceSymbol;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22015.62926.patch
Type: text/x-patch
Size: 3446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160706/51367e9e/attachment.bin>


More information about the llvm-commits mailing list