Skip to content

Commit 5433ba3

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 fa0971b commit 5433ba3

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
@@ -1224,8 +1224,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
12241224
v.push_back("lld-link (LLVM option parsing)");
12251225
for (auto *arg : args.filtered(OPT_mllvm))
12261226
v.push_back(arg->getValue());
1227-
cl::ResetAllOptionOccurrences();
1228-
cl::ParseCommandLineOptions(v.size(), v.data());
1227+
if (v.size() > 1) {
1228+
cl::ResetAllOptionOccurrences();
1229+
cl::ParseCommandLineOptions(v.size(), v.data());
1230+
}
12291231

12301232
// Handle /errorlimit early, because error() depends on it.
12311233
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
@@ -886,8 +886,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
886886
v.push_back("wasm-ld (LLVM option parsing)");
887887
for (auto *arg : args.filtered(OPT_mllvm))
888888
v.push_back(arg->getValue());
889-
cl::ResetAllOptionOccurrences();
890-
cl::ParseCommandLineOptions(v.size(), v.data());
889+
if (v.size() > 1) {
890+
cl::ResetAllOptionOccurrences();
891+
cl::ParseCommandLineOptions(v.size(), v.data());
892+
}
891893

892894
errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
893895

0 commit comments

Comments
 (0)