[llvm] 275862c - [llvm-objdump] Default to --mattr=+all for AArch64

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 30 11:18:00 PDT 2022


Author: Fangrui Song
Date: 2022-06-30T11:17:56-07:00
New Revision: 275862c75d9f203903b8bda2c41bd2d1e1efe885

URL: https://github.com/llvm/llvm-project/commit/275862c75d9f203903b8bda2c41bd2d1e1efe885
DIFF: https://github.com/llvm/llvm-project/commit/275862c75d9f203903b8bda2c41bd2d1e1efe885.diff

LOG: [llvm-objdump] Default to --mattr=+all for AArch64

GNU objdump disassembles all unknown instructions by default. Match this user
friendly behavior with the target feature "all" (D128029) designed for disassemblers.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D128030

Added: 
    llvm/test/tools/llvm-objdump/ELF/AArch64/mattr.s

Modified: 
    llvm/docs/CommandGuide/llvm-objdump.rst
    llvm/tools/llvm-objdump/llvm-objdump.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst
index bab83c09ffe49..7d2bae706eb3e 100644
--- a/llvm/docs/CommandGuide/llvm-objdump.rst
+++ b/llvm/docs/CommandGuide/llvm-objdump.rst
@@ -27,7 +27,11 @@ combined with other commands:
 
 .. option:: -d, --disassemble
 
-  Disassemble all executable sections found in the input files.
+  Disassemble all executable sections found in the input files. On some
+  architectures (AArch64, x86), all known instructions are disassembled by
+  default. On the others, :option:`--mcpu` or :option:`--mattr` is needed to
+  enable some instruction sets. Disabled instructions are displayed as
+  ``<unknown>``.
 
 .. option:: -D, --disassemble-all
 

diff  --git a/llvm/test/tools/llvm-objdump/ELF/AArch64/mattr.s b/llvm/test/tools/llvm-objdump/ELF/AArch64/mattr.s
new file mode 100644
index 0000000000000..e236660770648
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/ELF/AArch64/mattr.s
@@ -0,0 +1,21 @@
+## When --mattr and --mcpu are both empty, disassemble all known instructions.
+# RUN: llvm-mc -filetype=obj -triple=aarch64 -mattr=+all %s -o %t
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefixes=CHECK,ALL
+
+## If --mattr or --mcpu is specified, don't default to --mattr=+all.
+# RUN: llvm-objdump -d --no-show-raw-insn --mattr=+v8a %t | FileCheck %s --check-prefixes=CHECK,UNKNOWN
+# RUN: llvm-objdump -d --no-show-raw-insn --mcpu=generic %t | FileCheck %s --check-prefixes=CHECK,UNKNOWN
+
+# CHECK-LABEL: <_start>:
+# ALL-NEXT:      bc.eq 0x4
+# ALL-NEXT:      irg x0, x1
+# ALL-NEXT:      mrs x0, RNDR
+# UNKNOWN-COUNT-2: <unknown>
+# UNKNOWN:       mrs x0, S3_3_C2_C4_0
+# CHECK-EMPTY:
+
+.globl _start
+_start:
+  bc.eq #4      // armv8.8-a hbc
+  irg x0, x1    // armv8.5-a mte
+  mrs x0, RNDR  // armv8.5-a rand

diff  --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 8180665749600..132320a3cbc70 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1690,9 +1690,12 @@ static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
 
   // Package up features to be passed to target/subtarget
   SubtargetFeatures Features = Obj->getFeatures();
-  if (!MAttrs.empty())
+  if (!MAttrs.empty()) {
     for (unsigned I = 0; I != MAttrs.size(); ++I)
       Features.AddFeature(MAttrs[I]);
+  } else if (MCPU.empty() && Obj->getArch() == llvm::Triple::aarch64) {
+    Features.AddFeature("+all");
+  }
 
   std::unique_ptr<const MCRegisterInfo> MRI(
       TheTarget->createMCRegInfo(TripleName));


        


More information about the llvm-commits mailing list