Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -601,6 +601,17 @@ return Names.takeVector(); } +static void parseClangOption(StringRef Opt, const Twine &Msg) { + std::string Err; + raw_string_ostream OS(Err); + + const char *Argv[] = {Config->ProgName.data(), Opt.data()}; + if (cl::ParseCommandLineOptions(2, Argv, "", &OS)) + return; + OS.flush(); + error(Msg + ": " + StringRef(Err).trim()); +} + // Initializes Config members by the command line options. void LinkerDriver::readConfigs(opt::InputArgList &Args) { errorHandler().Verbose = Args.hasArg(OPT_verbose); @@ -709,7 +720,6 @@ Config->ZWxneeded = hasZOption(Args, "wxneeded"); // Parse LTO plugin-related options for compatibility with gold. - std::vector LTOOptions({Config->ProgName.data()}); for (auto *Arg : Args.filtered(OPT_plugin_opt)) { StringRef S = Arg->getValue(); if (S == "disable-verify") @@ -723,15 +733,15 @@ else if (S.startswith("jobs=")) Config->ThinLTOJobs = parseInt(S.substr(5), Arg); else if (S.startswith("mcpu=")) - LTOOptions.push_back(Saver.save("-" + S).data()); + parseClangOption(Saver.save("-" + S), Arg->getSpelling()); else if (!S.startswith("/") && !S.startswith("-fresolution=") && !S.startswith("-pass-through=") && !S.startswith("thinlto")) - LTOOptions.push_back(S.data()); + parseClangOption(S, Arg->getSpelling()); } - // Parse and evaluate -mllvm options. + + // Parse -mllvm options. for (auto *Arg : Args.filtered(OPT_mllvm)) - LTOOptions.push_back(Arg->getValue()); - cl::ParseCommandLineOptions(LTOOptions.size(), LTOOptions.data()); + parseClangOption(Arg->getValue(), Arg->getSpelling()); if (Config->LTOO > 3) error("invalid optimization level for LTO: " + Twine(Config->LTOO)); Index: test/ELF/lto-plugin-ignore.s =================================================================== --- test/ELF/lto-plugin-ignore.s +++ test/ELF/lto-plugin-ignore.s @@ -5,7 +5,6 @@ # RUN: -plugin-opt=-pass-through=-lgcc -plugin-opt=-function-sections \ # RUN: -plugin-opt=-data-sections -plugin-opt=thinlto -o /dev/null -# RUN: not ld.lld %t -plugin-opt=-data-sectionxxx \ -# RUN: -plugin-opt=-function-sectionxxx 2>&1 | FileCheck %s -# CHECK: Unknown command line argument '-data-sectionxxx' -# CHECK: Unknown command line argument '-function-sectionxxx' +# RUN: not ld.lld %t -plugin-opt=-abc -plugin-opt=-xyz 2>&1 | FileCheck %s +# CHECK: error: --plugin-opt: ld.lld: Unknown command line argument '-abc' +# CHECK: error: --plugin-opt: ld.lld: Unknown command line argument '-xyz'