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 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 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 @) + // 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: 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">;