[PATCH] D101695: [llvm-objdump] Add -M {att,intel} as aliases for --x86-asm-syntax={att,intel}

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 1 12:27:38 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: hoy, jhenderson.
Herald added subscribers: pengfei, s.egerton, rupprecht, simoncook.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.
`MCInstPrinterapplyTargetSpecificCLOption` is called too late and its MCAsmInfo
reference is const, so changing the `cl::opt` in
`MCInstPrinterapplyTargetSpecificCLOption` is not an option, at least without
large amount of refactoring.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101695

Files:
  llvm/docs/CommandGuide/llvm-objdump.rst
  llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbololize-operands.yaml
  llvm/test/tools/llvm-objdump/X86/syntax-mode.s
  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
@@ -2476,6 +2476,17 @@
   // hopefully remove this again.
   std::vector<const char *> 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()) {
Index: llvm/test/tools/llvm-objdump/X86/syntax-mode.s
===================================================================
--- /dev/null
+++ 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
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,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.
Index: llvm/docs/CommandGuide/llvm-objdump.rst
===================================================================
--- llvm/docs/CommandGuide/llvm-objdump.rst
+++ llvm/docs/CommandGuide/llvm-objdump.rst
@@ -146,8 +146,14 @@
 
 .. option:: -M, --disassembler-options=<opt1[,opt2,...]>
 
-  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=<cpu-name>
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101695.342169.patch
Type: text/x-patch
Size: 3919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210501/a7e7a62d/attachment.bin>


More information about the llvm-commits mailing list