[PATCH] D47500: [WebAssembly] Add support for response file parsing

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 15:07:25 PDT 2018


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
sbc100 edited the summary of this revision.

Fixes PR37620


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47500

Files:
  test/wasm/responsefile.test
  wasm/Driver.cpp
  wasm/Options.td


Index: wasm/Options.td
===================================================================
--- wasm/Options.td
+++ wasm/Options.td
@@ -73,6 +73,9 @@
 
 def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
 
+defm rsp_quoting: Eq<"rsp-quoting">,
+  HelpText<"Quoting style for response files. Values supported: windows|posix">;
+
 def strip_all: F<"strip-all">, HelpText<"Strip all symbols">;
 
 def strip_debug: F<"strip-debug">, HelpText<"Strip debugging information">;
Index: wasm/Driver.cpp
===================================================================
--- wasm/Driver.cpp
+++ wasm/Driver.cpp
@@ -128,6 +128,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()).getOS() == Triple::Win32)
+    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;
@@ -144,6 +158,11 @@
   unsigned MissingCount;
   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->getSpelling());
Index: test/wasm/responsefile.test
===================================================================
--- /dev/null
+++ test/wasm/responsefile.test
@@ -0,0 +1,25 @@
+RUN: llc -filetype=obj -o %t.o %p/Inputs/ret32.ll
+
+RUN: echo -o %t.wasm -e ret32 %t.o > %t.rsp
+RUN: wasm-ld @%t.rsp --initial-memory=655360
+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 @%t.rsp -o dummy 2>&1 | \
+RUN:     FileCheck --check-prefix=DEFRSP %s
+DEFRSP: error: cannot open blah/foo: No such file or directory
+
+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: No such file or directory
+
+RUN: echo "blah\foo" > %t.rsp
+RUN: not wasm-ld --rsp-quoting=posix @%t.rsp 2>&1 | \
+RUN:     FileCheck --check-prefix=POSRSP %s
+POSRSP: error: cannot open blahfoo: No such file or directory


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47500.148991.patch
Type: text/x-patch
Size: 2947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180529/9ec4139e/attachment.bin>


More information about the llvm-commits mailing list