diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst --- a/llvm/docs/CommandGuide/llvm-objdump.rst +++ b/llvm/docs/CommandGuide/llvm-objdump.rst @@ -146,8 +146,14 @@ .. option:: -M, --disassembler-options= - Pass target-specific disassembler options. Currently supported for ARM targets - only. Available options are ``reg-names-std`` and ``reg-names-raw``. + Pass target-specific disassembler options. Available options: + + * ``reg-names-std``: ARM only (default). Print in ARM 's instruction set documentation, with r13/r14/r15 replaced by sp/lr/pc. + * ``reg-names-raw``: ARM only. Use r followed by the register number. + * ``no-aliases``: RISC-V only. Print raw instruction mnemonic instead of pesudo instruction mnemonic. + * ``numeric``: RISC-V only. Print raw register names instead of ABI mnemonic. (e.g. print x1 instead of ra) + * ``att``: x86 only (default). Print in the AT&T syntax. + * ``intel``: x86 only. Print in the intel syntax. .. option:: --mcpu= diff --git a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml --- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml +++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml @@ -1,7 +1,7 @@ # RUN: yaml2obj %s -o %t -# RUN: llvm-objdump %t -d --symbolize-operands --x86-asm-syntax=intel --no-show-raw-insn --no-leading-addr | \ +# RUN: llvm-objdump %t -d --symbolize-operands -M intel --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: llvm-objdump %t -d --symbolize-operands -M att --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. diff --git a/llvm/test/tools/llvm-objdump/X86/syntax-mode.s b/llvm/test/tools/llvm-objdump/X86/syntax-mode.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/X86/syntax-mode.s @@ -0,0 +1,21 @@ +## Test att and intel syntax modes. +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t +# RUN: llvm-objdump -d --no-show-raw-insn -M att %t | FileCheck %s --check-prefix=ATT +# RUN: llvm-objdump -d --no-show-raw-insn -M intel %t | FileCheck %s --check-prefix=INTEL +# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=ATT + +## Test discouraged internal cl::opt options. +# RUN: llvm-objdump -d --no-show-raw-insn --x86-asm-syntax=att %t | FileCheck %s --check-prefix=ATT +# RUN: llvm-objdump -d --no-show-raw-insn --x86-asm-syntax=intel %t | FileCheck %s --check-prefix=INTEL + +# ATT: movw $1, %ax +# ATT: imull %esi, %edi +# ATT: leaq 5(%rsi,%rdi,4), %rax + +# INTEL: mov ax, 1 +# INTEL: imul edi, esi +# INTEL: lea rax, [rsi + 4*rdi + 5] + + movw $1, %ax + imull %esi, %edi + leaq 5(%rsi,%rdi,4), %rax diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2476,6 +2476,17 @@ // hopefully remove this again. std::vector LLVMArgs; LLVMArgs.push_back("llvm-objdump (LLVM option parsing)"); + llvm::erase_if(DisassemblerOptions, [&](StringRef V) { + if (V == "att") { + LLVMArgs.push_back("--x86-asm-syntax=att"); + return true; + } + if (V == "intel") { + LLVMArgs.push_back("--x86-asm-syntax=intel"); + return true; + } + return false; + }); if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_x86_asm_syntax_att, OBJDUMP_x86_asm_syntax_intel)) { switch (A->getOption().getID()) {