Skip to content

Commit

Permalink
[LDC] LLD: Avoid parsing -mllvm* command-line options if there aren…
Browse files Browse the repository at this point in the history
…'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.]
  • Loading branch information
kinke committed Jan 28, 2023
1 parent 8dfdcc7 commit 276022b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
v.push_back("lld-link (LLVM option parsing)");
for (auto *arg : args.filtered(OPT_mllvm))
v.push_back(arg->getValue());
cl::ResetAllOptionOccurrences();
cl::ParseCommandLineOptions(v.size(), v.data());
if (v.size() > 1) {
cl::ResetAllOptionOccurrences();
cl::ParseCommandLineOptions(v.size(), v.data());
}

// Handle /errorlimit early, because error() depends on it.
if (auto *arg = args.getLastArg(OPT_errorlimit)) {
Expand Down
6 changes: 4 additions & 2 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
v.push_back("wasm-ld (LLVM option parsing)");
for (auto *arg : args.filtered(OPT_mllvm))
v.push_back(arg->getValue());
cl::ResetAllOptionOccurrences();
cl::ParseCommandLineOptions(v.size(), v.data());
if (v.size() > 1) {
cl::ResetAllOptionOccurrences();
cl::ParseCommandLineOptions(v.size(), v.data());
}

readConfigs(args);

Expand Down

0 comments on commit 276022b

Please sign in to comment.