[llvm] [llvm-objdump] Support --mcpu=help/--mattr=help without -d (PR #165661)

Ruoyu Qiu via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 06:06:28 PST 2025


https://github.com/cabbaken updated https://github.com/llvm/llvm-project/pull/165661

>From 9f37b38971c60fb2ab0f0f9b8005555f44007c9f Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Thu, 30 Oct 2025 06:47:58 +0000
Subject: [PATCH 01/27] Add triple support to mcpu=help

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../tools/llvm-objdump/mattr-mcpu-help.test     |  6 ++++++
 llvm/tools/llvm-objdump/llvm-objdump.cpp        | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 65c426008fd6a..3475f0396d9b2 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -14,3 +14,9 @@ FileHeader:
   Data:            ELFDATA2LSB
   Type:            ET_EXEC
   Machine:         EM_X86_64
+
+# RUN: llvm-objdump --triple=x86_64 --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-WITHOUT-DISASSEMBLING
+
+# CHECK-WITHOUT-DISASSEMBLING: Available CPUs for this target:
+# CHECK-WITHOUT-DISASSEMBLING: Available features for this target:
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 3ec644a472bfc..5fe4420eb4f2d 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3533,6 +3533,19 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
   return Values;
 }
 
+static int MCPUHelp() {
+  if (!TripleName.empty()) {
+    std::string Error;
+    const Target *DummyTarget = TargetRegistry::lookupTarget(TripleName, Error);
+    if (!DummyTarget) {
+      outs() << Error << '\n';
+      return 2;
+    }
+    DummyTarget->createMCSubtargetInfo(TripleName, MCPU, "");
+  }
+  return 0;
+}
+
 static void parseOtoolOptions(const llvm::opt::InputArgList &InputArgs) {
   MachOOpt = true;
   FullLeadingAddr = true;
@@ -3826,6 +3839,10 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
       !DisassembleSymbols.empty())
     Disassemble = true;
 
+  if (!Disassemble && MCPU == "help") {
+    return MCPUHelp();
+  }
+
   if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
       !DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
       !Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&

>From 1ddbf3c1c523807a7f322d166b5a7cf0388f6253 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Thu, 30 Oct 2025 09:42:42 +0000
Subject: [PATCH 02/27] Fix deprecated function call

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 5fe4420eb4f2d..5e8d012a08450 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3536,12 +3536,14 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
 static int MCPUHelp() {
   if (!TripleName.empty()) {
     std::string Error;
-    const Target *DummyTarget = TargetRegistry::lookupTarget(TripleName, Error);
+    Triple DummyTriple(TripleName);
+    const Target *DummyTarget =
+        TargetRegistry::lookupTarget(DummyTriple, Error);
     if (!DummyTarget) {
       outs() << Error << '\n';
       return 2;
     }
-    DummyTarget->createMCSubtargetInfo(TripleName, MCPU, "");
+    DummyTarget->createMCSubtargetInfo(DummyTriple, MCPU, "");
   }
   return 0;
 }

>From 43c26ca43dc3bca130a8d6c42b5cb10033c5b647 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 31 Oct 2025 10:27:46 +0000
Subject: [PATCH 03/27] Do some fix

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 llvm/test/tools/llvm-objdump/mattr-mcpu-help.test |  2 ++
 llvm/tools/llvm-objdump/llvm-objdump.cpp          | 13 +++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 3475f0396d9b2..63aab94203b1f 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -20,3 +20,5 @@ FileHeader:
 
 # CHECK-WITHOUT-DISASSEMBLING: Available CPUs for this target:
 # CHECK-WITHOUT-DISASSEMBLING: Available features for this target:
+
+; XFAIL: *
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 5e8d012a08450..31205e07511da 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3533,16 +3533,17 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
   return Values;
 }
 
-static int MCPUHelp() {
+static int mcpuHelp() {
   if (!TripleName.empty()) {
     std::string Error;
     Triple DummyTriple(TripleName);
     const Target *DummyTarget =
         TargetRegistry::lookupTarget(DummyTriple, Error);
     if (!DummyTarget) {
-      outs() << Error << '\n';
+      reportCmdLineError(Error);
       return 2;
     }
+    // We need to access the Help() through the corresponding MCSubtargetInfo
     DummyTarget->createMCSubtargetInfo(DummyTriple, MCPU, "");
   }
   return 0;
@@ -3841,14 +3842,11 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
       !DisassembleSymbols.empty())
     Disassemble = true;
 
-  if (!Disassemble && MCPU == "help") {
-    return MCPUHelp();
-  }
-
   if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
       !DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
       !Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&
       !DynamicSymbolTable && !UnwindInfo && !FaultMapSection && !Offloading &&
+      MCPU != "help" &&
       !(MachOOpt &&
         (Bind || DataInCode || ChainedFixups || DyldInfo || DylibId ||
          DylibsUsed || ExportsTrie || FirstPrivateHeader ||
@@ -3859,6 +3857,9 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
     return 2;
   }
 
+  if (!Disassemble && MCPU == "help")
+    mcpuHelp();
+
   DisasmSymbolSet.insert_range(DisassembleSymbols);
 
   llvm::for_each(InputFilenames, dumpInput);

>From b8a508972189c0b4212fb305cb3b162e44b81b7f Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 14 Nov 2025 09:59:17 +0000
Subject: [PATCH 04/27] Fix mcpuHelp

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 31205e07511da..0e083faba5bb5 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3533,20 +3533,17 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
   return Values;
 }
 
-static int mcpuHelp() {
+static void mcpuHelp() {
   if (!TripleName.empty()) {
     std::string Error;
     Triple DummyTriple(TripleName);
     const Target *DummyTarget =
         TargetRegistry::lookupTarget(DummyTriple, Error);
-    if (!DummyTarget) {
+    if (!DummyTarget)
       reportCmdLineError(Error);
-      return 2;
-    }
-    // We need to access the Help() through the corresponding MCSubtargetInfo
-    DummyTarget->createMCSubtargetInfo(DummyTriple, MCPU, "");
+    // createMCSubtargetInfo prints the mcpu help text when called with "help"
+    DummyTarget->createMCSubtargetInfo(DummyTriple, "help", "");
   }
-  return 0;
 }
 
 static void parseOtoolOptions(const llvm::opt::InputArgList &InputArgs) {

>From b3071681defdbe525c08b9e5bd4b972a5cf958c1 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 21 Nov 2025 07:36:22 +0000
Subject: [PATCH 05/27] Correct behavior of mcpu=help

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../tools/llvm-objdump/mattr-mcpu-help.test   | 25 ++++++++++++--
 llvm/tools/llvm-objdump/llvm-objdump.cpp      | 33 +++++++++++++------
 2 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 63aab94203b1f..9dffa8e4b2ba7 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -15,10 +15,29 @@ FileHeader:
   Type:            ET_EXEC
   Machine:         EM_X86_64
 
-# RUN: llvm-objdump --triple=x86_64 --mcpu=help 2>&1 \
+# RUN: cp %t a.out
+# RUN: llvm-objdump -d --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-DEFAULT-FILE
+# RUN: rm a.out
+
+# CHECK-DEFAULT-FILE: Available CPUs for this target:
+# CHECK-DEFAULT-FILE: Available features for this target:
+
+# RUN: llvm-objdump --triple=arm --mcpu=help %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-TRIPLE-PRIORITY
+
+# CHECK-TRIPLE-PRIORITY: Available CPUs for this target:
+# CHECK-TRIPLE-PRIORITY: Available features for this target:
+# CHECK-TRIPLE-PRIORITY: arm
+
+# RUN: not llvm-objdump --triple=x86_64 --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-WITHOUT-FILE
+
+# CHECK-WITHOUT-FILE: Available CPUs for this target:
+# CHECK-WITHOUT-FILE: Available features for this target:
+
+# RUN: llvm-objdump --mcpu=help %t 2>&1 \
 # RUN:   | FileCheck %s --check-prefix=CHECK-WITHOUT-DISASSEMBLING
 
 # CHECK-WITHOUT-DISASSEMBLING: Available CPUs for this target:
 # CHECK-WITHOUT-DISASSEMBLING: Available features for this target:
-
-; XFAIL: *
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 0e083faba5bb5..8122937af471a 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3534,16 +3534,29 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
 }
 
 static void mcpuHelp() {
-  if (!TripleName.empty()) {
-    std::string Error;
-    Triple DummyTriple(TripleName);
-    const Target *DummyTarget =
-        TargetRegistry::lookupTarget(DummyTriple, Error);
-    if (!DummyTarget)
-      reportCmdLineError(Error);
-    // createMCSubtargetInfo prints the mcpu help text when called with "help"
-    DummyTarget->createMCSubtargetInfo(DummyTriple, "help", "");
+  std::string Error;
+  Triple DummyTriple;
+
+  if (!TripleName.empty())
+    DummyTriple.setTriple(TripleName);
+  else {
+    // If the target triple is derived from the files, we display help message
+    // when disassembling them.
+    if (Disassemble)
+      return;
+    for (std::string Filename : InputFilenames) {
+      OwningBinary<Binary> OBinary =
+          unwrapOrError(createBinary(Filename), Filename);
+      Binary *Obj = OBinary.getBinary();
+      DummyTriple = dyn_cast<ObjectFile>(Obj)->makeTriple();
+    }
   }
+
+  const Target *DummyTarget = TargetRegistry::lookupTarget(DummyTriple, Error);
+  if (!DummyTarget)
+    reportCmdLineError(Error);
+  // We need to access the Help() through the corresponding MCSubtargetInfo.
+  DummyTarget->createMCSubtargetInfo(DummyTriple, "help", "");
 }
 
 static void parseOtoolOptions(const llvm::opt::InputArgList &InputArgs) {
@@ -3854,7 +3867,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
     return 2;
   }
 
-  if (!Disassemble && MCPU == "help")
+  if (MCPU == "help")
     mcpuHelp();
 
   DisasmSymbolSet.insert_range(DisassembleSymbols);

>From 04cf6596741bb99915912cbd9295f705976807ca Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 21 Nov 2025 08:20:45 +0000
Subject: [PATCH 06/27] Add type check

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 8122937af471a..93fbf3d3113e7 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3547,8 +3547,11 @@ static void mcpuHelp() {
     for (std::string Filename : InputFilenames) {
       OwningBinary<Binary> OBinary =
           unwrapOrError(createBinary(Filename), Filename);
-      Binary *Obj = OBinary.getBinary();
-      DummyTriple = dyn_cast<ObjectFile>(Obj)->makeTriple();
+      Binary *Bin = OBinary.getBinary();
+      if (ObjectFile* Obj = dyn_cast<ObjectFile>(Bin)) {
+        DummyTriple = Obj->makeTriple();
+        break;
+      }
     }
   }
 

>From c246c1c2fc1f51b6e15fc43d461e80038caa08c0 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 21 Nov 2025 08:23:54 +0000
Subject: [PATCH 07/27] fix format

---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 93fbf3d3113e7..c8bc9ab1c7d6c 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3548,7 +3548,7 @@ static void mcpuHelp() {
       OwningBinary<Binary> OBinary =
           unwrapOrError(createBinary(Filename), Filename);
       Binary *Bin = OBinary.getBinary();
-      if (ObjectFile* Obj = dyn_cast<ObjectFile>(Bin)) {
+      if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin)) {
         DummyTriple = Obj->makeTriple();
         break;
       }

>From a8b26bd6eb8e1a783956205f807633f5f50b9d09 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 21 Nov 2025 10:43:34 +0000
Subject: [PATCH 08/27] Add release notes

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 llvm/docs/ReleaseNotes.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 49158fb4217b6..aae2f48529279 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -179,6 +179,8 @@ Changes to the LLVM tools
 * `llvm-readelf` now dumps all hex format values in lower-case mode.
 * Some code paths for supporting Python 2.7 in `llvm-lit` have been removed.
 * Support for `%T` in lit has been removed.
+* `llvm-objdump` now supports using `--mcpu=help` with the `--triple` option
+  without requiring an input file or the `-d` (disassemble) flag.
 
 Changes to LLDB
 ---------------------------------

>From 4c6e630bc7358c1d136a767554fd60b23571178f Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 26 Nov 2025 11:03:08 +0000
Subject: [PATCH 09/27] Structure test cases and fix variable name

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../tools/llvm-objdump/mattr-mcpu-help.test   | 27 ----------
 .../llvm-objdump/mattr-mcpu-triple-help.test  | 49 +++++++++++++++++++
 llvm/tools/llvm-objdump/llvm-objdump.cpp      | 15 +++---
 3 files changed, 57 insertions(+), 34 deletions(-)
 create mode 100644 llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 9dffa8e4b2ba7..65c426008fd6a 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -14,30 +14,3 @@ FileHeader:
   Data:            ELFDATA2LSB
   Type:            ET_EXEC
   Machine:         EM_X86_64
-
-# RUN: cp %t a.out
-# RUN: llvm-objdump -d --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-DEFAULT-FILE
-# RUN: rm a.out
-
-# CHECK-DEFAULT-FILE: Available CPUs for this target:
-# CHECK-DEFAULT-FILE: Available features for this target:
-
-# RUN: llvm-objdump --triple=arm --mcpu=help %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-TRIPLE-PRIORITY
-
-# CHECK-TRIPLE-PRIORITY: Available CPUs for this target:
-# CHECK-TRIPLE-PRIORITY: Available features for this target:
-# CHECK-TRIPLE-PRIORITY: arm
-
-# RUN: not llvm-objdump --triple=x86_64 --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-WITHOUT-FILE
-
-# CHECK-WITHOUT-FILE: Available CPUs for this target:
-# CHECK-WITHOUT-FILE: Available features for this target:
-
-# RUN: llvm-objdump --mcpu=help %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-WITHOUT-DISASSEMBLING
-
-# CHECK-WITHOUT-DISASSEMBLING: Available CPUs for this target:
-# CHECK-WITHOUT-DISASSEMBLING: Available features for this target:
diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
new file mode 100644
index 0000000000000..e871314e63d90
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -0,0 +1,49 @@
+# RUN: yaml2obj %s -o %t
+# REQUIRES: arm-registered-target,x86-registered-target
+
+
+# CHECK-HELP: Available CPUs for this target:
+# CHECK-ARM: arm
+# CHECK-X86: i386
+# CHECK-HELP: Available features for this target:
+## To check we still disassemble the file:
+# CHECK-DISASM: file format elf32-littlearm
+# CHECK-FILE-ISSUE: 'a.out': No such file or directory
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_ARM
+
+## 2. -d + --mcpu=help + a.out
+## Check the error if there is an issue with the file.
+# RUN: not llvm-objdump -d --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-FILE-ISSUE
+
+## Check if we can handle the default filename.
+# RUN: cp %t a.out
+# RUN: llvm-objdump -d --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM
+# RUN: rm a.out
+
+## 3. -d + --mcpu=help + --triple
+## Check the error if there is an issue with the file.
+# RUN: not llvm-objdump -d --mcpu=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-FILE-ISSUE
+
+## Check triple priority
+# RUN: cp %t a.out
+# RUN: llvm-objdump -d --mcpu=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86
+# RUN: rm a.out
+
+## 4. --mcpu + file
+## Check if we can handle without -d
+# RUN: llvm-objdump --mcpu=help %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM
+
+## We should also check if we can handle without -d and file
+# RUN: not llvm-objdump --mcpu=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index c8bc9ab1c7d6c..9c1e505177369 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3535,11 +3535,11 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
 
 static void mcpuHelp() {
   std::string Error;
-  Triple DummyTriple;
+  Triple TheTriple;
 
-  if (!TripleName.empty())
-    DummyTriple.setTriple(TripleName);
-  else {
+  if (!TripleName.empty()) {
+    TheTriple.setTriple(TripleName);
+  } else {
     // If the target triple is derived from the files, we display help message
     // when disassembling them.
     if (Disassemble)
@@ -3549,17 +3549,18 @@ static void mcpuHelp() {
           unwrapOrError(createBinary(Filename), Filename);
       Binary *Bin = OBinary.getBinary();
       if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin)) {
-        DummyTriple = Obj->makeTriple();
+      if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin)) {
+        TheTriple = Obj->makeTriple();
         break;
       }
     }
   }
 
-  const Target *DummyTarget = TargetRegistry::lookupTarget(DummyTriple, Error);
+  const Target *DummyTarget = TargetRegistry::lookupTarget(TheTriple, Error);
   if (!DummyTarget)
     reportCmdLineError(Error);
   // We need to access the Help() through the corresponding MCSubtargetInfo.
-  DummyTarget->createMCSubtargetInfo(DummyTriple, "help", "");
+  DummyTarget->createMCSubtargetInfo(TheTriple, "help", "");
 }
 
 static void parseOtoolOptions(const llvm::opt::InputArgList &InputArgs) {

>From 2ddfcfed9fd3a1fc80329d997ffa3bd260fbbafe Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 26 Nov 2025 11:15:08 +0000
Subject: [PATCH 10/27] Add other option

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../tools/llvm-objdump/mattr-mcpu-triple-help.test | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index e871314e63d90..5d6fb98236243 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -8,6 +8,8 @@
 # CHECK-HELP: Available features for this target:
 ## To check we still disassemble the file:
 # CHECK-DISASM: file format elf32-littlearm
+# CHECK-SECTION-HEADER: Sections:
+# CHECK-SECTION-HEADER: Idx Name            Size     VMA      Type
 # CHECK-FILE-ISSUE: 'a.out': No such file or directory
 
 --- !ELF
@@ -24,8 +26,8 @@ FileHeader:
 
 ## Check if we can handle the default filename.
 # RUN: cp %t a.out
-# RUN: llvm-objdump -d --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM
+# RUN: llvm-objdump -d --mcpu=help --section-headers 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM,CHECK-SECTION-HEADER
 # RUN: rm a.out
 
 ## 3. -d + --mcpu=help + --triple
@@ -35,14 +37,14 @@ FileHeader:
 
 ## Check triple priority
 # RUN: cp %t a.out
-# RUN: llvm-objdump -d --mcpu=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86
+# RUN: llvm-objdump -d --mcpu=help --triple=x86_64 --section-headers 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86,CHECK-SECTION-HEADER
 # RUN: rm a.out
 
 ## 4. --mcpu + file
 ## Check if we can handle without -d
-# RUN: llvm-objdump --mcpu=help %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM
+# RUN: llvm-objdump --mcpu=help --section-headers %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-SECTION-HEADER
 
 ## We should also check if we can handle without -d and file
 # RUN: not llvm-objdump --mcpu=help --triple=x86_64 2>&1 \

>From d596a0302a404d83bc638964764658c0a67875fa Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Mon, 1 Dec 2025 06:40:46 +0000
Subject: [PATCH 11/27] Add mattr support

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../tools/llvm-objdump/mattr-mcpu-triple-help.test   | 12 ++++++++++++
 llvm/tools/llvm-objdump/llvm-objdump.cpp             |  8 ++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index 5d6fb98236243..9302c046ac23f 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -23,29 +23,41 @@ FileHeader:
 ## Check the error if there is an issue with the file.
 # RUN: not llvm-objdump -d --mcpu=help 2>&1 \
 # RUN:   | FileCheck %s --check-prefix=CHECK-FILE-ISSUE
+# RUN: not llvm-objdump -d --mattr=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-FILE-ISSUE
 
 ## Check if we can handle the default filename.
 # RUN: cp %t a.out
 # RUN: llvm-objdump -d --mcpu=help --section-headers 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM,CHECK-SECTION-HEADER
+# RUN: llvm-objdump -d --mattr=help --section-headers 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM,CHECK-SECTION-HEADER
 # RUN: rm a.out
 
 ## 3. -d + --mcpu=help + --triple
 ## Check the error if there is an issue with the file.
 # RUN: not llvm-objdump -d --mcpu=help --triple=x86_64 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-FILE-ISSUE
+# RUN: not llvm-objdump -d --mattr=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-FILE-ISSUE
 
 ## Check triple priority
 # RUN: cp %t a.out
 # RUN: llvm-objdump -d --mcpu=help --triple=x86_64 --section-headers 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86,CHECK-SECTION-HEADER
+# RUN: llvm-objdump -d --mattr=help --triple=x86_64 --section-headers 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86,CHECK-SECTION-HEADER
 # RUN: rm a.out
 
 ## 4. --mcpu + file
 ## Check if we can handle without -d
 # RUN: llvm-objdump --mcpu=help --section-headers %t 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-SECTION-HEADER
+# RUN: llvm-objdump --mattr=help --section-headers %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-SECTION-HEADER
 
 ## We should also check if we can handle without -d and file
 # RUN: not llvm-objdump --mcpu=help --triple=x86_64 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
+# RUN: not llvm-objdump --mattr=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 9c1e505177369..a4c8f7c594e52 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3856,11 +3856,15 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
       !DisassembleSymbols.empty())
     Disassemble = true;
 
+  const bool PrintCpuHelp =
+      MCPU == "help" ||
+      std::find(MAttrs.begin(), MAttrs.end(), "help") != MAttrs.end();
+
   if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
       !DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
       !Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&
       !DynamicSymbolTable && !UnwindInfo && !FaultMapSection && !Offloading &&
-      MCPU != "help" &&
+      !PrintCpuHelp &&
       !(MachOOpt &&
         (Bind || DataInCode || ChainedFixups || DyldInfo || DylibId ||
          DylibsUsed || ExportsTrie || FirstPrivateHeader ||
@@ -3871,7 +3875,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
     return 2;
   }
 
-  if (MCPU == "help")
+  if (PrintCpuHelp)
     mcpuHelp();
 
   DisasmSymbolSet.insert_range(DisassembleSymbols);

>From 1fd545365553c120fb6ae49f0af834cc01a880fc Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Mon, 1 Dec 2025 06:54:12 +0000
Subject: [PATCH 12/27] Use ADT instead of STL

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index a4c8f7c594e52..6fbcabf105d7f 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3856,9 +3856,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
       !DisassembleSymbols.empty())
     Disassemble = true;
 
-  const bool PrintCpuHelp =
-      MCPU == "help" ||
-      std::find(MAttrs.begin(), MAttrs.end(), "help") != MAttrs.end();
+  const bool PrintCpuHelp = (MCPU == "help" || is_contained(MAttrs, "help"));
 
   if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
       !DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&

>From d4a48c2f3d50b3d68edb50979e40ff833fc16ffd Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Mon, 1 Dec 2025 08:11:37 +0000
Subject: [PATCH 13/27] Fix error

---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 1e185f1c15e54..53b62af4e84db 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3548,7 +3548,6 @@ static void mcpuHelp() {
       OwningBinary<Binary> OBinary =
           unwrapOrError(createBinary(Filename), Filename);
       Binary *Bin = OBinary.getBinary();
-      if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin)) {
       if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin)) {
         TheTriple = Obj->makeTriple();
         break;

>From 07e00249dc408d8282f52fd522ef73a60389720d Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Mon, 1 Dec 2025 08:53:18 +0000
Subject: [PATCH 14/27] Fix OS-dependent test

---
 llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index 9302c046ac23f..3103711781980 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -10,7 +10,8 @@
 # CHECK-DISASM: file format elf32-littlearm
 # CHECK-SECTION-HEADER: Sections:
 # CHECK-SECTION-HEADER: Idx Name            Size     VMA      Type
-# CHECK-FILE-ISSUE: 'a.out': No such file or directory
+## Don't check the OS-dependent message "No such file or directory".
+# CHECK-FILE-ISSUE: error: 'a.out':
 
 --- !ELF
 FileHeader:

>From 778baf39ede7c23e9d39a960324829b7761af577 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Mon, 1 Dec 2025 13:06:10 +0000
Subject: [PATCH 15/27] Fix tests and file check

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../llvm-objdump/mattr-mcpu-triple-help.test  | 63 +++++--------------
 llvm/tools/llvm-objdump/llvm-objdump.cpp      | 18 +++---
 2 files changed, 25 insertions(+), 56 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index 3103711781980..f3cf208a5b278 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -1,17 +1,29 @@
 # RUN: yaml2obj %s -o %t
 # REQUIRES: arm-registered-target,x86-registered-target
 
+## Check if we can handle without -d
+# RUN: llvm-objdump --mcpu=help %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM
+
+## Check if we can handle without file
+# RUN: not llvm-objdump --mcpu=help --triple=arm 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM
+
+## Check triple priority
+# RUN: llvm-objdump --mcpu=help --triple=x86_64 -d %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86,CHECK-DISASM
 
+## Check if we can handle multiple files
+# RUN: llvm-objdump --mcpu=help %t %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-MULTI-FILE,CHECK-HELP,CHECK-ARM
+
+# CHECK-MULTI-FILE: When multiple files are specified, only the first file is used to retrieve the help message.
 # CHECK-HELP: Available CPUs for this target:
 # CHECK-ARM: arm
 # CHECK-X86: i386
 # CHECK-HELP: Available features for this target:
 ## To check we still disassemble the file:
 # CHECK-DISASM: file format elf32-littlearm
-# CHECK-SECTION-HEADER: Sections:
-# CHECK-SECTION-HEADER: Idx Name            Size     VMA      Type
-## Don't check the OS-dependent message "No such file or directory".
-# CHECK-FILE-ISSUE: error: 'a.out':
 
 --- !ELF
 FileHeader:
@@ -19,46 +31,3 @@ FileHeader:
   Data:            ELFDATA2LSB
   Type:            ET_EXEC
   Machine:         EM_ARM
-
-## 2. -d + --mcpu=help + a.out
-## Check the error if there is an issue with the file.
-# RUN: not llvm-objdump -d --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-FILE-ISSUE
-# RUN: not llvm-objdump -d --mattr=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-FILE-ISSUE
-
-## Check if we can handle the default filename.
-# RUN: cp %t a.out
-# RUN: llvm-objdump -d --mcpu=help --section-headers 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM,CHECK-SECTION-HEADER
-# RUN: llvm-objdump -d --mattr=help --section-headers 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-DISASM,CHECK-SECTION-HEADER
-# RUN: rm a.out
-
-## 3. -d + --mcpu=help + --triple
-## Check the error if there is an issue with the file.
-# RUN: not llvm-objdump -d --mcpu=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-FILE-ISSUE
-# RUN: not llvm-objdump -d --mattr=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-FILE-ISSUE
-
-## Check triple priority
-# RUN: cp %t a.out
-# RUN: llvm-objdump -d --mcpu=help --triple=x86_64 --section-headers 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86,CHECK-SECTION-HEADER
-# RUN: llvm-objdump -d --mattr=help --triple=x86_64 --section-headers 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-DISASM,CHECK-HELP,CHECK-X86,CHECK-SECTION-HEADER
-# RUN: rm a.out
-
-## 4. --mcpu + file
-## Check if we can handle without -d
-# RUN: llvm-objdump --mcpu=help --section-headers %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-SECTION-HEADER
-# RUN: llvm-objdump --mattr=help --section-headers %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM,CHECK-SECTION-HEADER
-
-## We should also check if we can handle without -d and file
-# RUN: not llvm-objdump --mcpu=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
-# RUN: not llvm-objdump --mattr=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 53b62af4e84db..426ba899e4c2a 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3544,15 +3544,15 @@ static void mcpuHelp() {
     // when disassembling them.
     if (Disassemble)
       return;
-    for (std::string Filename : InputFilenames) {
-      OwningBinary<Binary> OBinary =
-          unwrapOrError(createBinary(Filename), Filename);
-      Binary *Bin = OBinary.getBinary();
-      if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin)) {
-        TheTriple = Obj->makeTriple();
-        break;
-      }
-    }
+    if (InputFilenames.size() != 1)
+      reportWarning("When multiple files are specified, only the first file is "
+                    "used to retrieve the help message.",
+                    InputFilenames[0]);
+    OwningBinary<Binary> OBinary =
+        unwrapOrError(createBinary(InputFilenames[0]), InputFilenames[0]);
+    Binary *Bin = OBinary.getBinary();
+    if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin))
+      TheTriple = Obj->makeTriple();
   }
 
   const Target *DummyTarget = TargetRegistry::lookupTarget(TheTriple, Error);

>From eae0981c0c37fb56869baad187ee2325575d04fa Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 5 Dec 2025 11:03:25 +0000
Subject: [PATCH 16/27] Fix code and test cases.

Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
 .../tools/llvm-objdump/mattr-mcpu-help.test   | 32 ++++++++++--
 .../llvm-objdump/mattr-mcpu-triple-help.test  | 34 +++++--------
 llvm/tools/llvm-objdump/llvm-objdump.cpp      | 51 ++++++++++---------
 3 files changed, 70 insertions(+), 47 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 65c426008fd6a..6a1dd27d493c8 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -1,12 +1,38 @@
 # RUN: yaml2obj %s -o %t
-# RUN: llvm-objdump -d %t --mattr=help 2>&1 | FileCheck %s
-# RUN: llvm-objdump -d %t --mcpu=help 2>&1 | FileCheck %s
+# RUN: llvm-objdump -d %t --mattr=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-DISASSEMBLE
+# RUN: llvm-objdump -d %t --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-DISASSEMBLE
+
+## We should be able to retrieve help message without -d.
+# RUN: llvm-objdump --mattr=help %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK
+# RUN: llvm-objdump --mcpu=help %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK
+
+## We still handle other options.
+# RUN: llvm-objdump --mattr=help --section-headers %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-SECTION-HEADERS
+# RUN: llvm-objdump --mcpu=help --section-headers %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-SECTION-HEADERS
+
+## We report error when we can't infer triple.
+# RUN: not llvm-objdump --mattr=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: not llvm-objdump --mcpu=help 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+
 # REQUIRES: x86-registered-target
 
 # CHECK: Available CPUs for this target:
 # CHECK: Available features for this target:
 ## To check we still disassemble the file:
-# CHECK: file format elf64-x86-64
+# CHECK-DISASSEMBLE: file format elf64-x86-64
+
+# CHECK-SECTION-HEADERS: Sections:
+# CHECK-SECTION-HEADERS: Idx Name               Size     VMA              Type
+
+# CHECK-ERROR: A target triple was not specified and could not be inferred from the input file.
 
 --- !ELF
 FileHeader:
diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index f3cf208a5b278..57c40b79c6e97 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -1,33 +1,25 @@
 # RUN: yaml2obj %s -o %t
-# REQUIRES: arm-registered-target,x86-registered-target
+# REQUIRES: mips-registered-target,x86-registered-target
 
-## Check if we can handle without -d
-# RUN: llvm-objdump --mcpu=help %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM
+## We shoule be able to retrieve help message by triple.
+# RUN: llvm-objdump --mattr=help --triple=mips 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
+# RUN: llvm-objdump --mcpu=help --triple=mips 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
 
-## Check if we can handle without file
-# RUN: not llvm-objdump --mcpu=help --triple=arm 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-ARM
+## The help message will always depends on --triple.
+# RUN: llvm-objdump --mattr=help --triple=mips %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
+# RUN: llvm-objdump --mcpu=help --triple=mips %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
 
-## Check triple priority
-# RUN: llvm-objdump --mcpu=help --triple=x86_64 -d %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86,CHECK-DISASM
-
-## Check if we can handle multiple files
-# RUN: llvm-objdump --mcpu=help %t %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-MULTI-FILE,CHECK-HELP,CHECK-ARM
-
-# CHECK-MULTI-FILE: When multiple files are specified, only the first file is used to retrieve the help message.
 # CHECK-HELP: Available CPUs for this target:
-# CHECK-ARM: arm
-# CHECK-X86: i386
+# CHECK-MIPS: mips
 # CHECK-HELP: Available features for this target:
-## To check we still disassemble the file:
-# CHECK-DISASM: file format elf32-littlearm
 
 --- !ELF
 FileHeader:
   Class:           ELFCLASS32
   Data:            ELFDATA2LSB
   Type:            ET_EXEC
-  Machine:         EM_ARM
+  Machine:         EM_X86_64
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 426ba899e4c2a..4aadeb749f619 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3540,17 +3540,15 @@ static void mcpuHelp() {
   if (!TripleName.empty()) {
     TheTriple.setTriple(TripleName);
   } else {
-    // If the target triple is derived from the files, we display help message
-    // when disassembling them.
-    if (Disassemble)
-      return;
-    if (InputFilenames.size() != 1)
-      reportWarning("When multiple files are specified, only the first file is "
-                    "used to retrieve the help message.",
-                    InputFilenames[0]);
-    OwningBinary<Binary> OBinary =
-        unwrapOrError(createBinary(InputFilenames[0]), InputFilenames[0]);
-    Binary *Bin = OBinary.getBinary();
+    // We can guarantee that InputFilenames won't be empty.
+    Expected<OwningBinary<Binary>> OBinary = createBinary(InputFilenames[0]);
+    // OwningBinary<Binary> OBinary =
+    if (!OBinary)
+      reportError(InputFilenames[0],
+                  "A target triple was not specified and could "
+                  " not be inferred from the input file.");
+
+    Binary *Bin = OBinary->getBinary();
     if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin))
       TheTriple = Obj->makeTriple();
   }
@@ -3857,23 +3855,30 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
 
   const bool PrintCpuHelp = (MCPU == "help" || is_contained(MAttrs, "help"));
 
-  if (!ArchiveHeaders && !Disassemble && DwarfDumpType == DIDT_Null &&
-      !DynamicRelocations && !FileHeaders && !PrivateHeaders && !RawClangAST &&
-      !Relocations && !SectionHeaders && !SectionContents && !SymbolTable &&
-      !DynamicSymbolTable && !UnwindInfo && !FaultMapSection && !Offloading &&
-      !PrintCpuHelp &&
-      !(MachOOpt &&
-        (Bind || DataInCode || ChainedFixups || DyldInfo || DylibId ||
-         DylibsUsed || ExportsTrie || FirstPrivateHeader ||
-         FunctionStartsType != FunctionStartsMode::None || IndirectSymbols ||
-         InfoPlist || LazyBind || LinkOptHints || ObjcMetaData || Rebase ||
-         Rpaths || UniversalHeaders || WeakBind || !FilterSections.empty()))) {
+  bool ShouldDump =
+      ArchiveHeaders || Disassemble || DwarfDumpType != DIDT_Null ||
+      DynamicRelocations || FileHeaders || PrivateHeaders || RawClangAST ||
+      Relocations || SectionHeaders || SectionContents || SymbolTable ||
+      DynamicSymbolTable || UnwindInfo || FaultMapSection || Offloading ||
+      (MachOOpt &&
+       (Bind || DataInCode || ChainedFixups || DyldInfo || DylibId ||
+        DylibsUsed || ExportsTrie || FirstPrivateHeader ||
+        FunctionStartsType != FunctionStartsMode::None || IndirectSymbols ||
+        InfoPlist || LazyBind || LinkOptHints || ObjcMetaData || Rebase ||
+        Rpaths || UniversalHeaders || WeakBind || !FilterSections.empty()));
+
+  if (!ShouldDump && !PrintCpuHelp) {
     T->printHelp(ToolName);
     return 2;
   }
 
-  if (PrintCpuHelp)
+  // If the target triple is derived from the files, we display help message
+  // when disassembling them.
+  if (!Disassemble && PrintCpuHelp) {
     mcpuHelp();
+    if (!ShouldDump)
+      return EXIT_SUCCESS;
+  }
 
   DisasmSymbolSet.insert_range(DisassembleSymbols);
 

>From bf35795041ea6e93c30b76af945fbb603c3539c2 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Fri, 5 Dec 2025 11:17:30 +0000
Subject: [PATCH 17/27] Fix variable type and release note

---
 llvm/docs/ReleaseNotes.md                | 2 +-
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 9357da96fdf55..69643e478daa8 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -200,7 +200,7 @@ Changes to the LLVM tools
   emitted on stdout, to account for spaces or other special characters in path.
   (`#97305 <https://github.com/llvm/llvm-project/pull/97305>`_).
 
-* `llvm-objdump` now supports using `--mcpu=help` with the `--triple` option
+* `llvm-objdump` now supports using `--mcpu=help` and `--mattr=help` with the `--triple` option
   without requiring an input file or the `-d` (disassemble) flag.
 
 Changes to LLDB
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 4aadeb749f619..b6ebfe58a4aa5 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3855,7 +3855,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
 
   const bool PrintCpuHelp = (MCPU == "help" || is_contained(MAttrs, "help"));
 
-  bool ShouldDump =
+  const bool ShouldDump =
       ArchiveHeaders || Disassemble || DwarfDumpType != DIDT_Null ||
       DynamicRelocations || FileHeaders || PrivateHeaders || RawClangAST ||
       Relocations || SectionHeaders || SectionContents || SymbolTable ||

>From e7eb13164eff181148628ef6e0168f7fdb1204bb Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 10 Dec 2025 10:02:59 +0800
Subject: [PATCH 18/27] Apply suggestions from code review

Co-authored-by: James Henderson <James.Henderson at sony.com>
---
 llvm/test/tools/llvm-objdump/mattr-mcpu-help.test        | 4 ++--
 llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 6a1dd27d493c8..956daab84e969 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -4,7 +4,7 @@
 # RUN: llvm-objdump -d %t --mcpu=help 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-DISASSEMBLE
 
-## We should be able to retrieve help message without -d.
+## The help message can be printed without -d.
 # RUN: llvm-objdump --mattr=help %t 2>&1 \
 # RUN:   | FileCheck %s --check-prefix=CHECK
 # RUN: llvm-objdump --mcpu=help %t 2>&1 \
@@ -16,7 +16,7 @@
 # RUN: llvm-objdump --mcpu=help --section-headers %t 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-SECTION-HEADERS
 
-## We report error when we can't infer triple.
+## We report an error when we can't infer the triple because we don't have --triple or an input object (including a.out).
 # RUN: not llvm-objdump --mattr=help 2>&1 \
 # RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
 # RUN: not llvm-objdump --mcpu=help 2>&1 \
diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index 57c40b79c6e97..c769c583f2259 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -1,13 +1,13 @@
 # RUN: yaml2obj %s -o %t
-# REQUIRES: mips-registered-target,x86-registered-target
+# REQUIRES: mips-registered-target
 
-## We shoule be able to retrieve help message by triple.
+## When specifying --triple, the help message should be printed for the specified target.
 # RUN: llvm-objdump --mattr=help --triple=mips 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
 # RUN: llvm-objdump --mcpu=help --triple=mips 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
 
-## The help message will always depends on --triple.
+## The help message will depend on the target specified by --triple even if the input is for a different target.
 # RUN: llvm-objdump --mattr=help --triple=mips %t 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
 # RUN: llvm-objdump --mcpu=help --triple=mips %t 2>&1 \

>From 5c6ae582625c07f34f24ff03d565a73b4af2332a Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 10 Dec 2025 10:13:39 +0000
Subject: [PATCH 19/27] Optimize Error message and test file

---
 .../tools/llvm-objdump/mattr-mcpu-help.test   | 10 ++++-----
 .../llvm-objdump/mattr-mcpu-triple-help.test  | 22 +++++++++----------
 llvm/tools/llvm-objdump/llvm-objdump.cpp      | 17 +++++++-------
 3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 956daab84e969..7898afe1a2dd3 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -1,4 +1,6 @@
 # RUN: yaml2obj %s -o %t
+# REQUIRES: x86-registered-target
+
 # RUN: llvm-objdump -d %t --mattr=help 2>&1 \
 # RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-DISASSEMBLE
 # RUN: llvm-objdump -d %t --mcpu=help 2>&1 \
@@ -18,11 +20,9 @@
 
 ## We report an error when we can't infer the triple because we don't have --triple or an input object (including a.out).
 # RUN: not llvm-objdump --mattr=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error:
 # RUN: not llvm-objdump --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR
-
-# REQUIRES: x86-registered-target
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error:
 
 # CHECK: Available CPUs for this target:
 # CHECK: Available features for this target:
@@ -32,7 +32,7 @@
 # CHECK-SECTION-HEADERS: Sections:
 # CHECK-SECTION-HEADERS: Idx Name               Size     VMA              Type
 
-# CHECK-ERROR: A target triple was not specified and could not be inferred from the input file.
+# CHECK-ERROR: llvm-objdump: error: 'a.out': triple was not specified and could not be inferred from the input file: No such file or directory
 
 --- !ELF
 FileHeader:
diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index c769c583f2259..6a14abfd2fafb 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -1,20 +1,20 @@
 # RUN: yaml2obj %s -o %t
-# REQUIRES: mips-registered-target
+# REQUIRES: x86-registered-target
 
 ## When specifying --triple, the help message should be printed for the specified target.
-# RUN: llvm-objdump --mattr=help --triple=mips 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
-# RUN: llvm-objdump --mcpu=help --triple=mips 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
+# RUN: llvm-objdump --mattr=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
+# RUN: llvm-objdump --mcpu=help --triple=x86_64 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
 
 ## The help message will depend on the target specified by --triple even if the input is for a different target.
-# RUN: llvm-objdump --mattr=help --triple=mips %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
-# RUN: llvm-objdump --mcpu=help --triple=mips %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-MIPS
+# RUN: llvm-objdump --mattr=help --triple=x86_64 %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
+# RUN: llvm-objdump --mcpu=help --triple=x86_64 %t 2>&1 \
+# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
 
 # CHECK-HELP: Available CPUs for this target:
-# CHECK-MIPS: mips
+# CHECK-X86: x86-64
 # CHECK-HELP: Available features for this target:
 
 --- !ELF
@@ -22,4 +22,4 @@ FileHeader:
   Class:           ELFCLASS32
   Data:            ELFDATA2LSB
   Type:            ET_EXEC
-  Machine:         EM_X86_64
+  Machine:         EM_MIPS
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index b6ebfe58a4aa5..5c1421cef5414 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3534,25 +3534,25 @@ commaSeparatedValues(const llvm::opt::InputArgList &InputArgs, int ID) {
 }
 
 static void mcpuHelp() {
-  std::string Error;
   Triple TheTriple;
 
   if (!TripleName.empty()) {
     TheTriple.setTriple(TripleName);
   } else {
-    // We can guarantee that InputFilenames won't be empty.
+    assert(InputFilenames.size());
     Expected<OwningBinary<Binary>> OBinary = createBinary(InputFilenames[0]);
-    // OwningBinary<Binary> OBinary =
-    if (!OBinary)
-      reportError(InputFilenames[0],
-                  "A target triple was not specified and could "
-                  " not be inferred from the input file.");
+    if (auto E = OBinary.takeError()) {
+      reportError(InputFilenames[0], "triple was not specified and could not "
+                                     "be inferred from the input file: " +
+                                         toString(std::move(E)));
+    }
 
     Binary *Bin = OBinary->getBinary();
     if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin))
       TheTriple = Obj->makeTriple();
   }
 
+  std::string Error;
   const Target *DummyTarget = TargetRegistry::lookupTarget(TheTriple, Error);
   if (!DummyTarget)
     reportCmdLineError(Error);
@@ -3874,7 +3874,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
 
   // If the target triple is derived from the files, we display help message
   // when disassembling them.
-  if (!Disassemble && PrintCpuHelp) {
+  if (PrintCpuHelp) {
     mcpuHelp();
     if (!ShouldDump)
       return EXIT_SUCCESS;
@@ -3882,6 +3882,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
 
   DisasmSymbolSet.insert_range(DisassembleSymbols);
 
+
   llvm::for_each(InputFilenames, dumpInput);
 
   warnOnNoMatchForSections();

>From 99b9e0800f50380c5fb04d88532ac71894f23d86 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 10 Dec 2025 10:18:56 +0000
Subject: [PATCH 20/27] Fix code format issue

---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 5c1421cef5414..7af21ff70ccd6 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3882,7 +3882,6 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
 
   DisasmSymbolSet.insert_range(DisassembleSymbols);
 
-
   llvm::for_each(InputFilenames, dumpInput);
 
   warnOnNoMatchForSections();

>From ca8370605582a01123a1559631aa0b070457d04d Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 10 Dec 2025 14:08:09 +0000
Subject: [PATCH 21/27] Make test case compatible with the Windows.

---
 llvm/test/tools/llvm-objdump/mattr-mcpu-help.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 7898afe1a2dd3..b90e2de35b8da 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -32,7 +32,7 @@
 # CHECK-SECTION-HEADERS: Sections:
 # CHECK-SECTION-HEADERS: Idx Name               Size     VMA              Type
 
-# CHECK-ERROR: llvm-objdump: error: 'a.out': triple was not specified and could not be inferred from the input file: No such file or directory
+# CHECK-ERROR: llvm-objdump{{.*}}: error: 'a.out': triple was not specified and could not be inferred from the input file: No such file or directory
 
 --- !ELF
 FileHeader:

>From 3c7f3f46a6dae9daffb164d0a1f9f0b405f904da Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 10 Dec 2025 15:42:38 +0000
Subject: [PATCH 22/27] Try to make test case compatible with the Windows.

---
 llvm/test/tools/llvm-objdump/mattr-mcpu-help.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index b90e2de35b8da..8765be41f1073 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -32,7 +32,7 @@
 # CHECK-SECTION-HEADERS: Sections:
 # CHECK-SECTION-HEADERS: Idx Name               Size     VMA              Type
 
-# CHECK-ERROR: llvm-objdump{{.*}}: error: 'a.out': triple was not specified and could not be inferred from the input file: No such file or directory
+# CHECK-ERROR: llvm-objdump{{(\.exe)?}}: error: 'a.out': triple was not specified and could not be inferred from the input file: No such file or directory
 
 --- !ELF
 FileHeader:

>From ef6e70ced9cc90d3aff816d6f38199a719f4a22f Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Wed, 10 Dec 2025 16:24:28 +0000
Subject: [PATCH 23/27] Add error report to unrecognized file type.

---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 7af21ff70ccd6..2354a3cf5ad5f 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3550,6 +3550,8 @@ static void mcpuHelp() {
     Binary *Bin = OBinary->getBinary();
     if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin))
       TheTriple = Obj->makeTriple();
+    else
+      reportError(InputFilenames[0], "file format not recognized");
   }
 
   std::string Error;

>From 2c8f99ea5627918cfc15e2037039dce91e610de1 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Thu, 11 Dec 2025 04:21:12 +0000
Subject: [PATCH 24/27] Fix test

---
 llvm/test/tools/llvm-objdump/mattr-mcpu-help.test | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 8765be41f1073..1b0c7de4f1ff2 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -20,9 +20,9 @@
 
 ## We report an error when we can't infer the triple because we don't have --triple or an input object (including a.out).
 # RUN: not llvm-objdump --mattr=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error:
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
 # RUN: not llvm-objdump --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error:
+# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
 
 # CHECK: Available CPUs for this target:
 # CHECK: Available features for this target:
@@ -32,7 +32,7 @@
 # CHECK-SECTION-HEADERS: Sections:
 # CHECK-SECTION-HEADERS: Idx Name               Size     VMA              Type
 
-# CHECK-ERROR: llvm-objdump{{(\.exe)?}}: error: 'a.out': triple was not specified and could not be inferred from the input file: No such file or directory
+# CHECK-ERROR: llvm-objdump{{.*}}: error: 'a.out': triple was not specified and could not be inferred from the input file: [[MSG]]
 
 --- !ELF
 FileHeader:

>From 7d1efcd69bcd48c473fb27eab28cb52b4fd47efa Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Thu, 11 Dec 2025 10:42:03 +0000
Subject: [PATCH 25/27] Do some fix

---
 .../tools/llvm-objdump/mattr-mcpu-help.test   | 21 ++++++++++++++-----
 .../llvm-objdump/mattr-mcpu-triple-help.test  | 18 +++++++---------
 llvm/tools/llvm-objdump/llvm-objdump.cpp      | 12 +++++------
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index 1b0c7de4f1ff2..ff415a28b68d0 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -8,9 +8,9 @@
 
 ## The help message can be printed without -d.
 # RUN: llvm-objdump --mattr=help %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK
+# RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-NO-DISASSEMBLE
 # RUN: llvm-objdump --mcpu=help %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK
+# RUN:   | FileCheck %s --check-prefixes=CHECK,CHECK-NO-DISASSEMBLE
 
 ## We still handle other options.
 # RUN: llvm-objdump --mattr=help --section-headers %t 2>&1 \
@@ -20,19 +20,30 @@
 
 ## We report an error when we can't infer the triple because we don't have --triple or an input object (including a.out).
 # RUN: not llvm-objdump --mattr=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
+# RUN:   | FileCheck %s --check-prefix=CHECK-MISSING-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
 # RUN: not llvm-objdump --mcpu=help 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=CHECK-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
+# RUN:   | FileCheck %s --check-prefix=CHECK-MISSING-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
+
+## This is a minidump file, which cannot be converted to ObjectFile in llvm.
+# RUN: printf "\x4D\x44\x4D\x50\x93\xA7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" > %t.minidump
+## We report an error when the binary file cannot be convert to a recognized object.
+# RUN: not llvm-objdump --mattr=help %t.minidump 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-UNSUPPORTED-ERROR --implicit-check-not=error: -DFILE=%t.minidump
+# RUN: not llvm-objdump --mcpu=help %t.minidump 2>&1 \
+# RUN:   | FileCheck %s --check-prefix=CHECK-UNSUPPORTED-ERROR --implicit-check-not=error: -DFILE=%t.minidump
 
 # CHECK: Available CPUs for this target:
 # CHECK: Available features for this target:
 ## To check we still disassemble the file:
 # CHECK-DISASSEMBLE: file format elf64-x86-64
+# CHECK-NO-DISASSEMBLE-NOT: file format elf64-x86-64
 
 # CHECK-SECTION-HEADERS: Sections:
 # CHECK-SECTION-HEADERS: Idx Name               Size     VMA              Type
 
-# CHECK-ERROR: llvm-objdump{{.*}}: error: 'a.out': triple was not specified and could not be inferred from the input file: [[MSG]]
+# CHECK-MISSING-ERROR: llvm-objdump{{.*}}: error: 'a.out': triple was not specified and could not be inferred from the input file: [[MSG]]
+
+# CHECK-UNSUPPORTED-ERROR: llvm-objdump{{.*}}: error: '[[FILE]]': input file is not an object file
 
 --- !ELF
 FileHeader:
diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
index 6a14abfd2fafb..1212773afc35a 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-triple-help.test
@@ -2,20 +2,16 @@
 # REQUIRES: x86-registered-target
 
 ## When specifying --triple, the help message should be printed for the specified target.
-# RUN: llvm-objdump --mattr=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
-# RUN: llvm-objdump --mcpu=help --triple=x86_64 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
+# RUN: llvm-objdump --mattr=help --triple=x86_64 2>&1 | FileCheck %s
+# RUN: llvm-objdump --mcpu=help --triple=x86_64 2>&1 | FileCheck %s
 
 ## The help message will depend on the target specified by --triple even if the input is for a different target.
-# RUN: llvm-objdump --mattr=help --triple=x86_64 %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
-# RUN: llvm-objdump --mcpu=help --triple=x86_64 %t 2>&1 \
-# RUN:   | FileCheck %s --check-prefixes=CHECK-HELP,CHECK-X86
+# RUN: llvm-objdump --mattr=help --triple=x86_64 %t 2>&1 | FileCheck %s
+# RUN: llvm-objdump --mcpu=help --triple=x86_64 %t 2>&1 | FileCheck %s
 
-# CHECK-HELP: Available CPUs for this target:
-# CHECK-X86: x86-64
-# CHECK-HELP: Available features for this target:
+# CHECK: Available CPUs for this target:
+# CHECK: x86-64
+# CHECK: Available features for this target:
 
 --- !ELF
 FileHeader:
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 2354a3cf5ad5f..43b44466d1a3c 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3539,9 +3539,9 @@ static void mcpuHelp() {
   if (!TripleName.empty()) {
     TheTriple.setTriple(TripleName);
   } else {
-    assert(InputFilenames.size());
+    assert(!InputFilenames.empty());
     Expected<OwningBinary<Binary>> OBinary = createBinary(InputFilenames[0]);
-    if (auto E = OBinary.takeError()) {
+    if (Error E = OBinary.takeError()) {
       reportError(InputFilenames[0], "triple was not specified and could not "
                                      "be inferred from the input file: " +
                                          toString(std::move(E)));
@@ -3551,13 +3551,13 @@ static void mcpuHelp() {
     if (ObjectFile *Obj = dyn_cast<ObjectFile>(Bin))
       TheTriple = Obj->makeTriple();
     else
-      reportError(InputFilenames[0], "file format not recognized");
+      reportError(InputFilenames[0], "input file is not an object file");
   }
 
-  std::string Error;
-  const Target *DummyTarget = TargetRegistry::lookupTarget(TheTriple, Error);
+  std::string ErrMessage;
+  const Target *DummyTarget = TargetRegistry::lookupTarget(TheTriple, ErrMessage);
   if (!DummyTarget)
-    reportCmdLineError(Error);
+    reportCmdLineError(ErrMessage);
   // We need to access the Help() through the corresponding MCSubtargetInfo.
   DummyTarget->createMCSubtargetInfo(TheTriple, "help", "");
 }

>From 4d0bcc80768ee07b5c97fe56f12c67997fa971a1 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Thu, 11 Dec 2025 11:02:09 +0000
Subject: [PATCH 26/27] Fix code format

---
 llvm/tools/llvm-objdump/llvm-objdump.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 43b44466d1a3c..a0223a205164c 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3555,7 +3555,8 @@ static void mcpuHelp() {
   }
 
   std::string ErrMessage;
-  const Target *DummyTarget = TargetRegistry::lookupTarget(TheTriple, ErrMessage);
+  const Target *DummyTarget =
+      TargetRegistry::lookupTarget(TheTriple, ErrMessage);
   if (!DummyTarget)
     reportCmdLineError(ErrMessage);
   // We need to access the Help() through the corresponding MCSubtargetInfo.

>From 5bb7e4e15739c45e9dfc069badbcf5bf93cb9c1f Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Thu, 11 Dec 2025 14:04:58 +0000
Subject: [PATCH 27/27] Add yaml to generate minidump.

---
 llvm/test/tools/llvm-objdump/mattr-mcpu-help.test | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
index ff415a28b68d0..abf8dc57053dc 100644
--- a/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
+++ b/llvm/test/tools/llvm-objdump/mattr-mcpu-help.test
@@ -24,8 +24,7 @@
 # RUN: not llvm-objdump --mcpu=help 2>&1 \
 # RUN:   | FileCheck %s --check-prefix=CHECK-MISSING-ERROR --implicit-check-not=error: -DMSG=%errc_ENOENT
 
-## This is a minidump file, which cannot be converted to ObjectFile in llvm.
-# RUN: printf "\x4D\x44\x4D\x50\x93\xA7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" > %t.minidump
+# RUN: yaml2obj --docnum=2 %s -o %t.minidump
 ## We report an error when the binary file cannot be convert to a recognized object.
 # RUN: not llvm-objdump --mattr=help %t.minidump 2>&1 \
 # RUN:   | FileCheck %s --check-prefix=CHECK-UNSUPPORTED-ERROR --implicit-check-not=error: -DFILE=%t.minidump
@@ -51,3 +50,9 @@ FileHeader:
   Data:            ELFDATA2LSB
   Type:            ET_EXEC
   Machine:         EM_X86_64
+
+--- !minidump
+Streams:
+  - Type:            SystemInfo
+    Processor Arch:  PPC
+    Platform ID:     Linux



More information about the llvm-commits mailing list