From 7fa27ce4a07f19b07799a767fc29416f3b625afb Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 26 Jul 2023 21:03:47 +0200 Subject: Vendor import of llvm-project main llvmorg-17-init-19304-gd0b54bb50e51, the last commit before the upstream release/17.x branch was created. --- llvm/tools/llvm-dwp/Opts.td | 13 ++++++ llvm/tools/llvm-dwp/llvm-dwp.cpp | 86 ++++++++++++++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 llvm/tools/llvm-dwp/Opts.td (limited to 'llvm/tools/llvm-dwp') diff --git a/llvm/tools/llvm-dwp/Opts.td b/llvm/tools/llvm-dwp/Opts.td new file mode 100644 index 000000000000..c01fa4a12cba --- /dev/null +++ b/llvm/tools/llvm-dwp/Opts.td @@ -0,0 +1,13 @@ +include "llvm/Option/OptParser.td" + +class F : Flag<["-", "--"], name>, HelpText; +class S : Separate<["-", "--"], name>, HelpText; + +def help : F<"help", "Display this help">; +def : F<"h", "Alias for --help">, Alias; +def version : F<"version", "Display the version of this program">; + +def execFileNames : S<"e", "Specify the executable/library files to get the list of *.dwo from.">, MetaVarName<"">; +def outputFileName : S<"o", "Specify the output file.">, MetaVarName<"">; +def continueOnCuIndexOverflow: F<"continue-on-cu-index-overflow", "This turns an error when offset for .debug_*.dwo sections " + "overfolws into a warning.">, MetaVarName<"">; diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 0a2c1c1ccc02..350a37345e2c 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -23,6 +23,8 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/Option.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/InitLLVM.h" @@ -36,20 +38,46 @@ using namespace llvm::object; static mc::RegisterMCTargetOptionsFlags MCTargetOptionsFlags; -cl::OptionCategory DwpCategory("Specific Options"); -static cl::list - InputFiles(cl::Positional, cl::desc(""), cl::cat(DwpCategory)); +// Command-line option boilerplate. +namespace { +enum ID { + OPT_INVALID = 0, // This is not an option ID. +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + OPT_##ID, +#include "Opts.inc" +#undef OPTION +}; -static cl::list ExecFilenames( - "e", - cl::desc( - "Specify the executable/library files to get the list of *.dwo from"), - cl::value_desc("filename"), cl::cat(DwpCategory)); +#define PREFIX(NAME, VALUE) \ + static constexpr StringLiteral NAME##_init[] = VALUE; \ + static constexpr ArrayRef NAME(NAME##_init, \ + std::size(NAME##_init) - 1); +#include "Opts.inc" +#undef PREFIX -static cl::opt OutputFilename(cl::Required, "o", - cl::desc("Specify the output file."), - cl::value_desc("filename"), - cl::cat(DwpCategory)); +static constexpr opt::OptTable::Info InfoTable[] = { +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + { \ + PREFIX, NAME, HELPTEXT, \ + METAVAR, OPT_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, OPT_##GROUP, \ + OPT_##ALIAS, ALIASARGS, VALUES}, +#include "Opts.inc" +#undef OPTION +}; + +class DwpOptTable : public opt::GenericOptTable { +public: + DwpOptTable() : GenericOptTable(InfoTable) {} +}; +} // end anonymous namespace + +// Options +static std::vector ExecFilenames; +static std::string OutputFilename; +static bool ContinueOnCuIndexOverflow; static Expected> getDWOFilenames(StringRef ExecFilename) { @@ -100,15 +128,41 @@ static Expected readTargetTriple(StringRef FileName) { int main(int argc, char **argv) { InitLLVM X(argc, argv); - cl::HideUnrelatedOptions({&DwpCategory, &getColorCategory()}); - cl::ParseCommandLineOptions(argc, argv, "merge split dwarf (.dwo) files\n"); + DwpOptTable Tbl; + llvm::BumpPtrAllocator A; + llvm::StringSaver Saver{A}; + opt::InputArgList Args = + Tbl.parseArgs(argc, argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) { + llvm::errs() << Msg << '\n'; + std::exit(1); + }); + + if (Args.hasArg(OPT_help)) { + Tbl.printHelp(llvm::outs(), "llvm-dwp [options] ", + "merge split dwarf (.dwo) files"); + std::exit(0); + } + + if (Args.hasArg(OPT_version)) { + llvm::cl::PrintVersionMessage(); + std::exit(0); + } + + OutputFilename = Args.getLastArgValue(OPT_outputFileName, ""); + ContinueOnCuIndexOverflow = Args.hasArg(OPT_continueOnCuIndexOverflow); + + for (const llvm::opt::Arg *A : Args.filtered(OPT_execFileNames)) + ExecFilenames.emplace_back(A->getValue()); + + std::vector DWOFilenames; + for (const llvm::opt::Arg *A : Args.filtered(OPT_INPUT)) + DWOFilenames.emplace_back(A->getValue()); llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetMCs(); llvm::InitializeAllTargets(); llvm::InitializeAllAsmPrinters(); - std::vector DWOFilenames = InputFiles; for (const auto &ExecFilename : ExecFilenames) { auto DWOs = getDWOFilenames(ExecFilename); if (!DWOs) { @@ -207,7 +261,7 @@ int main(int argc, char **argv) { if (!MS) return error("no object streamer for target " + TripleName, Context); - if (auto Err = write(*MS, DWOFilenames)) { + if (auto Err = write(*MS, DWOFilenames, ContinueOnCuIndexOverflow)) { logAllUnhandledErrors(std::move(Err), WithColor::error()); return 1; } -- cgit v1.2.3