[lld] r328880 - Improve error message for an unknown --plugin-opt.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 30 10:22:44 PDT 2018
Author: ruiu
Date: Fri Mar 30 10:22:44 2018
New Revision: 328880
URL: http://llvm.org/viewvc/llvm-project?rev=328880&view=rev
Log:
Improve error message for an unknown --plugin-opt.
Before:
$ ld.lld --plugin-opt=-foo
ld.lld: --Unknown command line argument '-abc'
After:
$ ld.lld --plugin-opt=-foo
ld.lld: --plugin-opt: ld.lld --Unknown command line argument '-abc'
Differential Revision: https://reviews.llvm.org/D45075
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/test/ELF/lto-plugin-ignore.s
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=328880&r1=328879&r2=328880&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Mar 30 10:22:44 2018
@@ -601,6 +601,17 @@ static std::vector<StringRef> getSymbolO
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 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZWxneeded = hasZOption(Args, "wxneeded");
// Parse LTO plugin-related options for compatibility with gold.
- std::vector<const char *> LTOOptions({Config->ProgName.data()});
for (auto *Arg : Args.filtered(OPT_plugin_opt)) {
StringRef S = Arg->getValue();
if (S == "disable-verify")
@@ -723,15 +733,15 @@ void LinkerDriver::readConfigs(opt::Inpu
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));
Modified: lld/trunk/test/ELF/lto-plugin-ignore.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto-plugin-ignore.s?rev=328880&r1=328879&r2=328880&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto-plugin-ignore.s (original)
+++ lld/trunk/test/ELF/lto-plugin-ignore.s Fri Mar 30 10:22:44 2018
@@ -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'
More information about the llvm-commits
mailing list