diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp --- a/lld/ELF/DriverUtils.cpp +++ b/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; } diff --git a/lld/test/wasm/responsefile.test b/lld/test/wasm/responsefile.test --- a/lld/test/wasm/responsefile.test +++ b/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: diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp --- a/lld/wasm/Driver.cpp +++ b/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 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 @) - 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 @) + // 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)); diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td --- a/lld/wasm/Options.td +++ b/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">;