[PATCH] D42733: [ELF] - Use InitTargetOptionsFromCodeGenFlags/ParseCommandLineOptions for parsing LTO options.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 31 15:32:53 PST 2018
The testcase for -plugin-opt=-debugger-tune=xxx could be added to this
patch, no?
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar created this revision.
> grimar added reviewers: ruiu, espindola.
> Herald added subscribers: inglorion, emaste.
>
> 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.
>
>
> https://reviews.llvm.org/D42733
>
> Files:
> ELF/Driver.cpp
> ELF/Driver.h
> 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,7 @@
> # RUN: -plugin-opt=-pass-through=-lgcc -plugin-opt=-function-sections \
> # RUN: -plugin-opt=-data-sections -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'
> Index: ELF/Driver.h
> ===================================================================
> --- ELF/Driver.h
> +++ ELF/Driver.h
> @@ -31,7 +31,7 @@
> void addLibrary(StringRef Name);
>
> private:
> - void readConfigs(llvm::opt::InputArgList &Args);
> + void readConfigs(const char *Argv0, llvm::opt::InputArgList &Args);
> void createFiles(llvm::opt::InputArgList &Args);
> void inferMachineType();
> template <class ELFT> void link(llvm::opt::InputArgList &Args);
> Index: ELF/Driver.cpp
> ===================================================================
> --- ELF/Driver.cpp
> +++ ELF/Driver.cpp
> @@ -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"
> @@ -248,18 +249,11 @@
> // 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.
> @@ -367,8 +361,8 @@
> }
> }
>
> - readConfigs(Args);
> - initLLVM(Args);
> + readConfigs(ArgsArr[0], Args);
> + initLLVM();
> createFiles(Args);
> inferMachineType();
> setConfigs();
> @@ -590,7 +584,7 @@
> }
>
> // Initializes Config members by the command line options.
> -void LinkerDriver::readConfigs(opt::InputArgList &Args) {
> +void LinkerDriver::readConfigs(const char *Argv0, opt::InputArgList &Args) {
> Config->AllowMultipleDefinition =
> Args.hasArg(OPT_allow_multiple_definition) || hasZOption(Args, "muldefs");
> Config->AuxiliaryList = args::getStrings(Args, OPT_auxiliary);
> @@ -685,6 +679,7 @@
> Config->ZWxneeded = hasZOption(Args, "wxneeded");
>
> // Parse LTO plugin-related options for compatibility with gold.
> + std::vector<const char *> LTOOptions({Argv0});
> for (auto *Arg : Args.filtered(OPT_plugin_opt)) {
> StringRef S = Arg->getValue();
> if (S == "disable-verify")
> @@ -698,11 +693,15 @@
> else if (S.startswith("jobs="))
> 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("-pass-through="))
> + // Ignore options that might be passed by GCC and collect
> + // LTO options for futher proccessing.
> + 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));
More information about the llvm-commits
mailing list