[lld] 928e9e1 - [lld][WebAssembly] Add support for --rsp-quoting
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 11:42:08 PST 2020
Author: Sam Clegg
Date: 2020-03-04T11:41:33-08:00
New Revision: 928e9e172305752583a75a8174ab5a87b4e09d80
URL: https://github.com/llvm/llvm-project/commit/928e9e172305752583a75a8174ab5a87b4e09d80
DIFF: https://github.com/llvm/llvm-project/commit/928e9e172305752583a75a8174ab5a87b4e09d80.diff
LOG: [lld][WebAssembly] Add support for --rsp-quoting
This also changes to default style to match the host.
Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D75577
Added:
Modified:
lld/ELF/DriverUtils.cpp
lld/test/wasm/responsefile.test
lld/wasm/Driver.cpp
lld/wasm/Options.td
Removed:
################################################################################
diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index 03336b384500..443255d53d91 100644
--- a/lld/ELF/DriverUtils.cpp
+++ b/lld/ELF/DriverUtils.cpp
@@ -82,7 +82,7 @@ static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
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
index 11f805997b26..ba2afd0cc8fd 100644
--- a/lld/test/wasm/responsefile.test
+++ b/lld/test/wasm/responsefile.test
@@ -5,6 +5,16 @@ 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 --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
index f9ea83add7c6..468fefd39190 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -149,6 +149,20 @@ static void handleColorDiagnostics(opt::InputArgList &args) {
}
}
+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 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
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));
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index fb5adc860a7f..d0275cf5cd49 100644
--- a/lld/wasm/Options.td
+++ b/lld/wasm/Options.td
@@ -89,6 +89,9 @@ def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
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">;
More information about the llvm-commits
mailing list