Skip to content

Commit 928e9e1

Browse files
sbc100dschuff
authored andcommitted
[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
1 parent c030ba6 commit 928e9e1

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

lld/ELF/DriverUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
8282
return cl::TokenizeWindowsCommandLine;
8383
return cl::TokenizeGNUCommandLine;
8484
}
85-
if (Triple(sys::getProcessTriple()).getOS() == Triple::Win32)
85+
if (Triple(sys::getProcessTriple()).isOSWindows())
8686
return cl::TokenizeWindowsCommandLine;
8787
return cl::TokenizeGNUCommandLine;
8888
}

lld/test/wasm/responsefile.test

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ RUN: wasm-ld @%t.rsp --initial-memory=655360
55
RUN: llvm-readobj --sections %t.wasm | FileCheck %s
66
CHECK: InitialPages: 10
77

8+
RUN: not wasm-ld --rsp-quoting=foobar @%t.rsp 2>&1 | \
9+
RUN: FileCheck --check-prefix=INVRSP %s
10+
INVRSP: invalid response file quoting: foobar
11+
12+
RUN: echo "blah\foo" > %t.rsp
13+
RUN: not wasm-ld --rsp-quoting=windows @%t.rsp 2>&1 | \
14+
RUN: FileCheck --check-prefix=WINRSP %s
15+
WINRSP: error: cannot open blah\foo:
16+
817
RUN: echo "blah\foo" > %t.rsp
9-
RUN: not wasm-ld @%t.rsp 2>&1 | FileCheck --check-prefix=ESCAPE %s
10-
ESCAPE: error: cannot open blahfoo: {{[Nn]}}o such file or directory
18+
RUN: not wasm-ld --rsp-quoting=posix @%t.rsp 2>&1 | \
19+
RUN: FileCheck --check-prefix=POSRSP %s
20+
POSRSP: error: cannot open blahfoo:

lld/wasm/Driver.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ static void handleColorDiagnostics(opt::InputArgList &args) {
149149
}
150150
}
151151

152+
static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
153+
if (auto *arg = args.getLastArg(OPT_rsp_quoting)) {
154+
StringRef s = arg->getValue();
155+
if (s != "windows" && s != "posix")
156+
error("invalid response file quoting: " + s);
157+
if (s == "windows")
158+
return cl::TokenizeWindowsCommandLine;
159+
return cl::TokenizeGNUCommandLine;
160+
}
161+
if (Triple(sys::getProcessTriple()).isOSWindows())
162+
return cl::TokenizeWindowsCommandLine;
163+
return cl::TokenizeGNUCommandLine;
164+
}
165+
152166
// Find a file by concatenating given paths.
153167
static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
154168
SmallString<128> s;
@@ -164,11 +178,16 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
164178
unsigned missingIndex;
165179
unsigned missingCount;
166180

167-
// Expand response files (arguments in the form of @<filename>)
168-
cl::ExpandResponseFiles(saver, cl::TokenizeGNUCommandLine, vec);
169-
181+
// We need to get the quoting style for response files before parsing all
182+
// options so we parse here before and ignore all the options but
183+
// --rsp-quoting.
170184
opt::InputArgList args = this->ParseArgs(vec, missingIndex, missingCount);
171185

186+
// Expand response files (arguments in the form of @<filename>)
187+
// and then parse the argument again.
188+
cl::ExpandResponseFiles(saver, getQuotingStyle(args), vec);
189+
args = this->ParseArgs(vec, missingIndex, missingCount);
190+
172191
handleColorDiagnostics(args);
173192
for (auto *arg : args.filtered(OPT_UNKNOWN))
174193
error("unknown argument: " + arg->getAsString(args));

lld/wasm/Options.td

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
8989

9090
defm reproduce: Eq<"reproduce", "Dump linker invocation and input files for debugging">;
9191

92+
defm rsp_quoting: Eq<"rsp-quoting", "Quoting style for response files">,
93+
MetaVarName<"[posix,windows]">;
94+
9295
def shared: F<"shared">, HelpText<"Build a shared object">;
9396

9497
def strip_all: F<"strip-all">, HelpText<"Strip all symbols">;

0 commit comments

Comments
 (0)