[lld] r324340 - [ELF] - Re-commit r324322 "Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.".

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 29 17:54:05 PDT 2018


The error message generated by this patch is confusing as shown below.

  $ ld.lld --plugin-opt=foobar
  ld.lld: Unknown command line argument '-foobar'.  Try: 'bin/ld.lld -help'
  ld.lld: Did you mean '-color'?

It says "-foobar" although I didn't pass that option. What I passed is
--plugin-opt=foobar.


On Tue, Feb 6, 2018 at 4:21 AM George Rimar via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: grimar
> Date: Tue Feb  6 04:20:05 2018
> New Revision: 324340
>
> URL: http://llvm.org/viewvc/llvm-project?rev=324340&view=rev
> Log:
> [ELF] - Re-commit r324322 "Use
> InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO
> options.".
>
> With fix:
> Keep logic that ignores -plugin-opt=mcpu=x86-64 -plugin-opt=thinlto,
> add checks for those to testcases.
>
> Original commit message:
>
> [ELF] - Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for
> parsing LTO options.
>
> gold plugin uses InitTargetOptionsFromCodeGenFlags +
> ParseCommandLineOptions for parsing LTO options.
> Patch do the same change for LLD.
>
> Such change helps to avoid parsing/whitelisting LTO
> plugin options again on linker side, what can help LLD
> to automatically support new -plugin-opt=xxx options
> passed.
>
> Differential revision: https://reviews.llvm.org/D42733
>
>
>
> 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=324340&r1=324339&r2=324340&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Tue Feb  6 04:20:05 2018
> @@ -42,6 +42,7 @@
>  #include "lld/Common/Driver.h"
>  #include "lld/Common/ErrorHandler.h"
>  #include "lld/Common/Memory.h"
> +#include "lld/Common/TargetOptionsCommandFlags.h"
>  #include "lld/Common/Threads.h"
>  #include "lld/Common/Version.h"
>  #include "llvm/ADT/StringExtras.h"
> @@ -252,18 +253,11 @@ void LinkerDriver::addLibrary(StringRef
>  // LTO calls LLVM functions to compile bitcode files to native code.
>  // Technically this can be delayed until we read bitcode files, but
>  // we don't bother to do lazily because the initialization is fast.
> -static void initLLVM(opt::InputArgList &Args) {
> +static void initLLVM() {
>    InitializeAllTargets();
>    InitializeAllTargetMCs();
>    InitializeAllAsmPrinters();
>    InitializeAllAsmParsers();
> -
> -  // Parse and evaluate -mllvm options.
> -  std::vector<const char *> V;
> -  V.push_back("lld (LLVM option parsing)");
> -  for (auto *Arg : Args.filtered(OPT_mllvm))
> -    V.push_back(Arg->getValue());
> -  cl::ParseCommandLineOptions(V.size(), V.data());
>  }
>
>  // Some command line options or some combinations of them are not allowed.
> @@ -372,7 +366,7 @@ void LinkerDriver::main(ArrayRef<const c
>    }
>
>    readConfigs(Args);
> -  initLLVM(Args);
> +  initLLVM();
>    createFiles(Args);
>    inferMachineType();
>    setConfigs(Args);
> @@ -696,6 +690,7 @@ 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->Argv[0].data()});
>    for (auto *Arg : Args.filtered(OPT_plugin_opt)) {
>      StringRef S = Arg->getValue();
>      if (S == "disable-verify")
> @@ -710,10 +705,13 @@ void LinkerDriver::readConfigs(opt::Inpu
>        Config->ThinLTOJobs = parseInt(S.substr(5), Arg);
>      else if (!S.startswith("/") && !S.startswith("-fresolution=") &&
>               !S.startswith("-pass-through=") && !S.startswith("mcpu=") &&
> -             !S.startswith("thinlto") && S != "-function-sections" &&
> -             S != "-data-sections")
> -      error(Arg->getSpelling() + ": unknown option: " + S);
> +             !S.startswith("thinlto"))
> +      LTOOptions.push_back(S.data());
>    }
> +  // Parse and evaluate -mllvm options.
> +  for (auto *Arg : Args.filtered(OPT_mllvm))
> +    LTOOptions.push_back(Arg->getValue());
> +  cl::ParseCommandLineOptions(LTOOptions.size(), LTOOptions.data());
>
>    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=324340&r1=324339&r2=324340&view=diff
>
> ==============================================================================
> --- lld/trunk/test/ELF/lto-plugin-ignore.s (original)
> +++ lld/trunk/test/ELF/lto-plugin-ignore.s Tue Feb  6 04:20:05 2018
> @@ -3,9 +3,10 @@
>  # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
>  # RUN: ld.lld %t -plugin-opt=/foo/bar -plugin-opt=-fresolution=zed \
>  # RUN:   -plugin-opt=-pass-through=-lgcc -plugin-opt=-function-sections \
> -# RUN:   -plugin-opt=-data-sections -o /dev/null
> +# RUN:   -plugin-opt=-data-sections -plugin-opt=mcpu=x86-64 \
> +# RUN:   -plugin-opt=thinlto -o /dev/null
>
> -# RUN: not ld.lld %t -plugin-opt=-data-sectionssss \
> -# RUN:   -plugin-opt=-function-sectionsss 2>&1 | FileCheck %s
> -# CHECK: unknown option: -data-sectionsss
> -# CHECK: unknown option: -function-sectionsss
> +# 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'
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180330/752998f8/attachment.html>


More information about the llvm-commits mailing list