From e510860656bb81bd90ae3cf8bb5ef4dc8cd33c18 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 5 May 2021 00:20:41 -0700 Subject: [llvm-objdump] Add -M {att,intel} & deprecate --x86-asm-syntax={att,intel} The internal `cl::opt` option --x86-asm-syntax sets the AsmParser and AsmWriter dialect. The option is used by llc and llvm-mc tests to set the AsmWriter dialect. This patch adds -M {att,intel} as GNU objdump compatible aliases (PR43413). Note: the dialect is initialized when the MCAsmInfo is constructed. `MCInstPrinter::applyTargetSpecificCLOption` is called too late and its MCAsmInfo reference is const, so changing the `cl::opt` in `MCInstPrinter::applyTargetSpecificCLOption` is not an option, at least without large amount of refactoring. Reviewed By: hoy, jhenderson, thakis Differential Revision: https://reviews.llvm.org/D101695 --- llvm/tools/llvm-objdump/llvm-objdump.cpp | 44 +++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp') diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index e466364..8dbd88f 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2419,8 +2419,6 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) { DisassembleSymbols = commaSeparatedValues(InputArgs, OBJDUMP_disassemble_symbols_EQ); DisassembleZeroes = InputArgs.hasArg(OBJDUMP_disassemble_zeroes); - DisassemblerOptions = - commaSeparatedValues(InputArgs, OBJDUMP_disassembler_options_EQ); if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_dwarf_EQ)) { DwarfDumpType = StringSwitch(A->getValue()).Case("frames", DIDT_DebugFrame); @@ -2466,24 +2464,40 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) { parseMachOOptions(InputArgs); - // Handle options that get forwarded to cl::opt<>s in libraries. - // FIXME: Depending on https://reviews.llvm.org/D84191#inline-946075 , - // hopefully remove this again. - std::vector LLVMArgs; - LLVMArgs.push_back("llvm-objdump (LLVM option parsing)"); - if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_x86_asm_syntax_att, - OBJDUMP_x86_asm_syntax_intel)) { + // Parse -M (--disassembler-options) and deprecated + // --x86-asm-syntax={att,intel}. + // + // Note, for x86, the asm dialect (AssemblerDialect) is initialized when the + // MCAsmInfo is constructed. MCInstPrinter::applyTargetSpecificCLOption is + // called too late. For now we have to use the internal cl::opt option. + const char *AsmSyntax = nullptr; + for (const auto *A : InputArgs.filtered(OBJDUMP_disassembler_options_EQ, + OBJDUMP_x86_asm_syntax_att, + OBJDUMP_x86_asm_syntax_intel)) { switch (A->getOption().getID()) { case OBJDUMP_x86_asm_syntax_att: - LLVMArgs.push_back("--x86-asm-syntax=att"); - break; + AsmSyntax = "--x86-asm-syntax=att"; + continue; case OBJDUMP_x86_asm_syntax_intel: - LLVMArgs.push_back("--x86-asm-syntax=intel"); - break; + AsmSyntax = "--x86-asm-syntax=intel"; + continue; } + + SmallVector Values; + llvm::SplitString(A->getValue(), Values, ","); + for (StringRef V : Values) { + if (V == "att") + AsmSyntax = "--x86-asm-syntax=att"; + else if (V == "intel") + AsmSyntax = "--x86-asm-syntax=intel"; + else + DisassemblerOptions.push_back(V.str()); + } + } + if (AsmSyntax) { + const char *Argv[] = {"llvm-objdump", AsmSyntax}; + llvm::cl::ParseCommandLineOptions(2, Argv); } - LLVMArgs.push_back(nullptr); - llvm::cl::ParseCommandLineOptions(LLVMArgs.size() - 1, LLVMArgs.data()); // objdump defaults to a.out if no filenames specified. if (InputFilenames.empty()) -- cgit v1.1