[llvm] [llvm-objdump] Support --mcpu=help/--mattr=help without -d (PR #165661)
Ruoyu Qiu via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 10 02:15:54 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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/19] 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();
More information about the llvm-commits
mailing list