[PATCH] D75577: [lld][WebAssembly] Add support for --rsp-quoting

Derek Schuff via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 11:49:23 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG928e9e172305: [lld][WebAssembly] Add support for --rsp-quoting (authored by sbc100, committed by dschuff).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75577/new/

https://reviews.llvm.org/D75577

Files:
  lld/ELF/DriverUtils.cpp
  lld/test/wasm/responsefile.test
  lld/wasm/Driver.cpp
  lld/wasm/Options.td


Index: lld/wasm/Options.td
===================================================================
--- lld/wasm/Options.td
+++ lld/wasm/Options.td
@@ -89,6 +89,9 @@
 
 defm reproduce: Eq<"reproduce", "Dump linker invocation and input files for debugging">;
 
+defm rsp_quoting: Eq<"rsp-quoting", "Quoting style for response files">,
+  MetaVarName<"[posix,windows]">;
+
 def shared: F<"shared">, HelpText<"Build a shared object">;
 
 def strip_all: F<"strip-all">, HelpText<"Strip all symbols">;
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -149,6 +149,20 @@
   }
 }
 
+static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
+  if (auto *arg = args.getLastArg(OPT_rsp_quoting)) {
+    StringRef s = arg->getValue();
+    if (s != "windows" && s != "posix")
+      error("invalid response file quoting: " + s);
+    if (s == "windows")
+      return cl::TokenizeWindowsCommandLine;
+    return cl::TokenizeGNUCommandLine;
+  }
+  if (Triple(sys::getProcessTriple()).isOSWindows())
+    return cl::TokenizeWindowsCommandLine;
+  return cl::TokenizeGNUCommandLine;
+}
+
 // Find a file by concatenating given paths.
 static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
   SmallString<128> s;
@@ -164,11 +178,16 @@
   unsigned missingIndex;
   unsigned missingCount;
 
-  // Expand response files (arguments in the form of @<filename>)
-  cl::ExpandResponseFiles(saver, cl::TokenizeGNUCommandLine, vec);
-
+  // We need to get the quoting style for response files before parsing all
+  // options so we parse here before and ignore all the options but
+  // --rsp-quoting.
   opt::InputArgList args = this->ParseArgs(vec, missingIndex, missingCount);
 
+  // Expand response files (arguments in the form of @<filename>)
+  // and then parse the argument again.
+  cl::ExpandResponseFiles(saver, getQuotingStyle(args), vec);
+  args = this->ParseArgs(vec, missingIndex, missingCount);
+
   handleColorDiagnostics(args);
   for (auto *arg : args.filtered(OPT_UNKNOWN))
     error("unknown argument: " + arg->getAsString(args));
Index: lld/test/wasm/responsefile.test
===================================================================
--- lld/test/wasm/responsefile.test
+++ lld/test/wasm/responsefile.test
@@ -5,6 +5,16 @@
 RUN: llvm-readobj --sections %t.wasm | FileCheck %s
 CHECK: InitialPages: 10
 
+RUN: not wasm-ld --rsp-quoting=foobar @%t.rsp 2>&1 | \
+RUN:     FileCheck --check-prefix=INVRSP %s
+INVRSP: invalid response file quoting: foobar
+
+RUN: echo "blah\foo" > %t.rsp
+RUN: not wasm-ld --rsp-quoting=windows @%t.rsp 2>&1 | \
+RUN:     FileCheck --check-prefix=WINRSP %s
+WINRSP: error: cannot open blah\foo:
+
 RUN: echo "blah\foo" > %t.rsp
-RUN: not wasm-ld @%t.rsp 2>&1 | FileCheck --check-prefix=ESCAPE %s
-ESCAPE: error: cannot open blahfoo: {{[Nn]}}o such file or directory
+RUN: not wasm-ld --rsp-quoting=posix @%t.rsp 2>&1 | \
+RUN:     FileCheck --check-prefix=POSRSP %s
+POSRSP: error: cannot open blahfoo:
Index: lld/ELF/DriverUtils.cpp
===================================================================
--- lld/ELF/DriverUtils.cpp
+++ lld/ELF/DriverUtils.cpp
@@ -82,7 +82,7 @@
       return cl::TokenizeWindowsCommandLine;
     return cl::TokenizeGNUCommandLine;
   }
-  if (Triple(sys::getProcessTriple()).getOS() == Triple::Win32)
+  if (Triple(sys::getProcessTriple()).isOSWindows())
     return cl::TokenizeWindowsCommandLine;
   return cl::TokenizeGNUCommandLine;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75577.248269.patch
Type: text/x-patch
Size: 3534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200304/125c8055/attachment.bin>


More information about the llvm-commits mailing list