[PATCH] D101761: [llvm-objdump] support "-M att" and "-M intel" flags
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 3 08:35:04 PDT 2021
thakis updated this revision to Diff 342405.
thakis added a comment.
clang-format
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101761/new/
https://reviews.llvm.org/D101761
Files:
llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2424,8 +2424,47 @@
DisassembleSymbols =
commaSeparatedValues(InputArgs, OBJDUMP_disassemble_symbols_EQ);
DisassembleZeroes = InputArgs.hasArg(OBJDUMP_disassemble_zeroes);
- DisassemblerOptions =
- commaSeparatedValues(InputArgs, OBJDUMP_disassembler_options_EQ);
+
+ // DisassemblerOptions are passed to
+ // MCInstPrinter::applyTargetSpecificCLOption, but handling "att" and "intel"
+ // in that hook is too late: createX86MCInstPrinter() returns a different
+ // MCInstPrinter subclass depending on the assembler dialect. So we have
+ // to handle `-M att` and `-M intel` specially: They don't go into
+ // DisassemblerOptions like the other `-M` flags.
+ // llvm-objdump hasn't supported `-M att` and `-M intel` for a long time, so
+ // keep supporting the old `--x86-asm-syntax=att/intel` spelling that people
+ // used to use with it before too, even though that's not how GNU objdump
+ // spells it.
+ 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:
+ AsmSyntax = "--x86-asm-syntax=att";
+ continue;
+ case OBJDUMP_x86_asm_syntax_intel:
+ AsmSyntax = "--x86-asm-syntax=intel";
+ continue;
+ }
+
+ assert(A->getOption().getID() == OBJDUMP_disassembler_options_EQ);
+ for (StringRef Value : A->getValues()) {
+ if (Value.equals_lower("att")) {
+ AsmSyntax = "--x86-asm-syntax=att";
+ continue;
+ }
+ if (Value.equals_lower("intel")) {
+ AsmSyntax = "--x86-asm-syntax=intel";
+ continue;
+ }
+ llvm::SmallVector<StringRef, 2> SplitValues;
+ llvm::SplitString(Value, SplitValues, ",");
+ for (StringRef SplitValue : SplitValues)
+ DisassemblerOptions.push_back(SplitValue.str());
+ }
+ }
+
if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_dwarf_EQ)) {
DwarfDumpType =
StringSwitch<DIDumpType>(A->getValue()).Case("frames", DIDT_DebugFrame);
@@ -2472,21 +2511,10 @@
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<const char *> 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)) {
- switch (A->getOption().getID()) {
- case OBJDUMP_x86_asm_syntax_att:
- LLVMArgs.push_back("--x86-asm-syntax=att");
- break;
- case OBJDUMP_x86_asm_syntax_intel:
- LLVMArgs.push_back("--x86-asm-syntax=intel");
- break;
- }
- }
+ if (AsmSyntax)
+ LLVMArgs.push_back(AsmSyntax);
if (InputArgs.hasArg(OBJDUMP_mhvx))
LLVMArgs.push_back("--mhvx");
if (InputArgs.hasArg(OBJDUMP_mhvx_v66))
Index: llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
===================================================================
--- llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
+++ llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
@@ -1,8 +1,12 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objdump %t -d --symbolize-operands --x86-asm-syntax=intel --no-show-raw-insn --no-leading-addr | \
# RUN: FileCheck %s --match-full-lines --check-prefix=INTEL
+# RUN: llvm-objdump %t -dM Intel --symbolize-operands --no-show-raw-insn --no-leading-addr | \
+# RUN: FileCheck %s --match-full-lines --check-prefix=INTEL
# RUN: llvm-objdump %t -d --symbolize-operands --x86-asm-syntax=att --no-show-raw-insn --no-leading-addr | \
# RUN: FileCheck %s --match-full-lines --check-prefix=ATT
+# RUN: llvm-objdump %t -dMatt --symbolize-operands --no-show-raw-insn --no-leading-addr | \
+# RUN: FileCheck %s --match-full-lines --check-prefix=ATT
## Expect to find the branch labels and global variable name.
# ATT: <_start>:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101761.342405.patch
Type: text/x-patch
Size: 4418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210503/4ad8b4e7/attachment.bin>
More information about the llvm-commits
mailing list