Skip to content

Commit 79e183e

Browse files
committed
[LDC] LLD: Avoid parsing -mllvm* command-line options if there aren't any
When invoking the integrated LLD from LDC, it somehow uses a different global LLVM command-line parser, one with no registered options, so parsing is guaranteed to fail, even if there are no args. [It's only needed for LTO codegen options anyway.]
1 parent d7b669b commit 79e183e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lld/COFF/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
12941294
v.push_back("lld-link (LLVM option parsing)");
12951295
for (auto *arg : args.filtered(OPT_mllvm))
12961296
v.push_back(arg->getValue());
1297-
cl::ResetAllOptionOccurrences();
1298-
cl::ParseCommandLineOptions(v.size(), v.data());
1297+
if (v.size() > 1) {
1298+
cl::ResetAllOptionOccurrences();
1299+
cl::ParseCommandLineOptions(v.size(), v.data());
1300+
}
12991301

13001302
// Handle /errorlimit early, because error() depends on it.
13011303
if (auto *arg = args.getLastArg(OPT_errorlimit)) {

lld/wasm/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
855855
v.push_back("wasm-ld (LLVM option parsing)");
856856
for (auto *arg : args.filtered(OPT_mllvm))
857857
v.push_back(arg->getValue());
858-
cl::ResetAllOptionOccurrences();
859-
cl::ParseCommandLineOptions(v.size(), v.data());
858+
if (v.size() > 1) {
859+
cl::ResetAllOptionOccurrences();
860+
cl::ParseCommandLineOptions(v.size(), v.data());
861+
}
860862

861863
errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
862864

0 commit comments

Comments
 (0)