<div dir="ltr">The error message generated by this patch is confusing as shown below.<div><br></div><div>  $ ld.lld --plugin-opt=foobar</div><div>  ld.lld: Unknown command line argument '-foobar'.  Try: 'bin/ld.lld -help'</div><div>  ld.lld: Did you mean '-color'?</div><div><br></div><div>It says "-foobar" although I didn't pass that option. What I passed is --plugin-opt=foobar.</div></div><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 6, 2018 at 4:21 AM George Rimar via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: grimar<br>
Date: Tue Feb  6 04:20:05 2018<br>
New Revision: 324340<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=324340&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=324340&view=rev</a><br>
Log:<br>
[ELF] - Re-commit r324322 "Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.".<br>
<br>
With fix:<br>
Keep logic that ignores -plugin-opt=mcpu=x86-64 -plugin-opt=thinlto,<br>
add checks for those to testcases.<br>
<br>
Original commit message:<br>
<br>
[ELF] - Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.<br>
<br>
gold plugin uses InitTargetOptionsFromCodeGenFlags +<br>
ParseCommandLineOptions for parsing LTO options.<br>
Patch do the same change for LLD.<br>
<br>
Such change helps to avoid parsing/whitelisting LTO<br>
plugin options again on linker side, what can help LLD<br>
to automatically support new -plugin-opt=xxx options<br>
passed.<br>
<br>
Differential revision: <a href="https://reviews.llvm.org/D42733" rel="noreferrer" target="_blank">https://reviews.llvm.org/D42733</a><br>
<br>
<br>
<br>
Modified:<br>
    lld/trunk/ELF/Driver.cpp<br>
    lld/trunk/test/ELF/lto-plugin-ignore.s<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=324340&r1=324339&r2=324340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=324340&r1=324339&r2=324340&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Tue Feb  6 04:20:05 2018<br>
@@ -42,6 +42,7 @@<br>
 #include "lld/Common/Driver.h"<br>
 #include "lld/Common/ErrorHandler.h"<br>
 #include "lld/Common/Memory.h"<br>
+#include "lld/Common/TargetOptionsCommandFlags.h"<br>
 #include "lld/Common/Threads.h"<br>
 #include "lld/Common/Version.h"<br>
 #include "llvm/ADT/StringExtras.h"<br>
@@ -252,18 +253,11 @@ void LinkerDriver::addLibrary(StringRef<br>
 // LTO calls LLVM functions to compile bitcode files to native code.<br>
 // Technically this can be delayed until we read bitcode files, but<br>
 // we don't bother to do lazily because the initialization is fast.<br>
-static void initLLVM(opt::InputArgList &Args) {<br>
+static void initLLVM() {<br>
   InitializeAllTargets();<br>
   InitializeAllTargetMCs();<br>
   InitializeAllAsmPrinters();<br>
   InitializeAllAsmParsers();<br>
-<br>
-  // Parse and evaluate -mllvm options.<br>
-  std::vector<const char *> V;<br>
-  V.push_back("lld (LLVM option parsing)");<br>
-  for (auto *Arg : Args.filtered(OPT_mllvm))<br>
-    V.push_back(Arg->getValue());<br>
-  cl::ParseCommandLineOptions(V.size(), V.data());<br>
 }<br>
<br>
 // Some command line options or some combinations of them are not allowed.<br>
@@ -372,7 +366,7 @@ void LinkerDriver::main(ArrayRef<const c<br>
   }<br>
<br>
   readConfigs(Args);<br>
-  initLLVM(Args);<br>
+  initLLVM();<br>
   createFiles(Args);<br>
   inferMachineType();<br>
   setConfigs(Args);<br>
@@ -696,6 +690,7 @@ void LinkerDriver::readConfigs(opt::Inpu<br>
   Config->ZWxneeded = hasZOption(Args, "wxneeded");<br>
<br>
   // Parse LTO plugin-related options for compatibility with gold.<br>
+  std::vector<const char *> LTOOptions({Config->Argv[0].data()});<br>
   for (auto *Arg : Args.filtered(OPT_plugin_opt)) {<br>
     StringRef S = Arg->getValue();<br>
     if (S == "disable-verify")<br>
@@ -710,10 +705,13 @@ void LinkerDriver::readConfigs(opt::Inpu<br>
       Config->ThinLTOJobs = parseInt(S.substr(5), Arg);<br>
     else if (!S.startswith("/") && !S.startswith("-fresolution=") &&<br>
              !S.startswith("-pass-through=") && !S.startswith("mcpu=") &&<br>
-             !S.startswith("thinlto") && S != "-function-sections" &&<br>
-             S != "-data-sections")<br>
-      error(Arg->getSpelling() + ": unknown option: " + S);<br>
+             !S.startswith("thinlto"))<br>
+      LTOOptions.push_back(S.data());<br>
   }<br>
+  // Parse and evaluate -mllvm options.<br>
+  for (auto *Arg : Args.filtered(OPT_mllvm))<br>
+    LTOOptions.push_back(Arg->getValue());<br>
+  cl::ParseCommandLineOptions(LTOOptions.size(), LTOOptions.data());<br>
<br>
   if (Config->LTOO > 3)<br>
     error("invalid optimization level for LTO: " + Twine(Config->LTOO));<br>
<br>
Modified: lld/trunk/test/ELF/lto-plugin-ignore.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto-plugin-ignore.s?rev=324340&r1=324339&r2=324340&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto-plugin-ignore.s?rev=324340&r1=324339&r2=324340&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/lto-plugin-ignore.s (original)<br>
+++ lld/trunk/test/ELF/lto-plugin-ignore.s Tue Feb  6 04:20:05 2018<br>
@@ -3,9 +3,10 @@<br>
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
 # RUN: ld.lld %t -plugin-opt=/foo/bar -plugin-opt=-fresolution=zed \<br>
 # RUN:   -plugin-opt=-pass-through=-lgcc -plugin-opt=-function-sections \<br>
-# RUN:   -plugin-opt=-data-sections -o /dev/null<br>
+# RUN:   -plugin-opt=-data-sections -plugin-opt=mcpu=x86-64 \<br>
+# RUN:   -plugin-opt=thinlto -o /dev/null<br>
<br>
-# RUN: not ld.lld %t -plugin-opt=-data-sectionssss \<br>
-# RUN:   -plugin-opt=-function-sectionsss 2>&1 | FileCheck %s<br>
-# CHECK: unknown option: -data-sectionsss<br>
-# CHECK: unknown option: -function-sectionsss<br>
+# RUN: not ld.lld %t -plugin-opt=-data-sectionxxx \<br>
+# RUN:   -plugin-opt=-function-sectionxxx 2>&1 | FileCheck %s<br>
+# CHECK: Unknown command line argument '-data-sectionxxx'<br>
+# CHECK: Unknown command line argument '-function-sectionxxx'<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>