[PATCH] D45075: Improve error message for an unknown --plugin-opt.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 30 10:25:48 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD328880: Improve error message for an unknown --plugin-opt. (authored by ruiu, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D45075?vs=140375&id=140452#toc
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D45075
Files:
ELF/Driver.cpp
test/ELF/lto-plugin-ignore.s
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'
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<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 @@
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));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45075.140452.patch
Type: text/x-patch
Size: 2707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180330/8fdd23eb/attachment.bin>
More information about the llvm-commits
mailing list