Skip to content

[llvm-objdump] Add -mllvm #75892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2023
Merged

[llvm-objdump] Add -mllvm #75892

merged 1 commit into from
Dec 19, 2023

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Dec 19, 2023

When llvm-objdump switched from cl:: to OptTable
(https://reviews.llvm.org/D100433), we dropped support for LLVM cl::
options. Some LLVM_DEBUG in llvm/lib/Target/$target/MCDisassembler/
files might be useful. Add -mllvm to allow dumping the information.

# -debug is available in an LLVM_ENABLE_ASSERTIONS=on build
llvm-objdump -d -mllvm -debug a.o > /dev/null

Link: https://discourse.llvm.org/t/how-to-enable-debug-logs-in-llvm-objdump/75758

When llvm-objdump switched from cl:: to OptTable
(https://reviews.llvm.org/D100433), we dropped support for LLVM cl::
options. Some LLVM_DEBUG in `llvm/lib/Target/$target/MCDisassembler/`
files might be useful. Add -mllvm to allow dumping the information.

```
llvm-objdump -d -mllvm -debug a.o > /dev/null
```

Link: https://discourse.llvm.org/t/how-to-enable-debug-logs-in-llvm-objdump/75758
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2023

@llvm/pr-subscribers-llvm-binary-utilities

Author: Fangrui Song (MaskRay)

Changes

When llvm-objdump switched from cl:: to OptTable
(https://reviews.llvm.org/D100433), we dropped support for LLVM cl::
options. Some LLVM_DEBUG in llvm/lib/Target/$target/MCDisassembler/
files might be useful. Add -mllvm to allow dumping the information.

llvm-objdump -d -mllvm -debug a.o > /dev/null

Link: https://discourse.llvm.org/t/how-to-enable-debug-logs-in-llvm-objdump/75758


Full diff: https://github.com/llvm/llvm-project/pull/75892.diff

4 Files Affected:

  • (modified) llvm/docs/CommandGuide/llvm-objdump.rst (+4)
  • (added) llvm/test/tools/llvm-objdump/mllvm.s (+8)
  • (modified) llvm/tools/llvm-objdump/ObjdumpOpts.td (+3)
  • (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+7-4)
diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst
index b156b212e461f2..959452a74b23ea 100644
--- a/llvm/docs/CommandGuide/llvm-objdump.rst
+++ b/llvm/docs/CommandGuide/llvm-objdump.rst
@@ -198,6 +198,10 @@ OPTIONS
   Enable/disable target-specific attributes. Specify ``--mattr=help`` to display
   the available attributes.
 
+.. option:: -mllvm <arg>
+
+   Specify an argument to forward to LLVM's CommandLine library.
+
 .. option:: --no-leading-addr, --no-addresses
 
   When disassembling, do not print leading addresses for instructions or inline
diff --git a/llvm/test/tools/llvm-objdump/mllvm.s b/llvm/test/tools/llvm-objdump/mllvm.s
new file mode 100644
index 00000000000000..7fb14ff085fa94
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/mllvm.s
@@ -0,0 +1,8 @@
+# REQUIRES: x86-registered-target
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t
+# RUN: llvm-objdump --no-print-imm-hex -d -mllvm --x86-asm-syntax=intel %t | FileCheck %s
+# RUN: llvm-objdump --no-print-imm-hex -d -mllvm=--x86-asm-syntax=intel %t | FileCheck %s
+
+# CHECK: lea rax, [rsi + 4*rdi + 5]
+
+  leaq 5(%rsi,%rdi,4), %rax
diff --git a/llvm/tools/llvm-objdump/ObjdumpOpts.td b/llvm/tools/llvm-objdump/ObjdumpOpts.td
index 100a95d3d92542..c1dec5ced89d31 100644
--- a/llvm/tools/llvm-objdump/ObjdumpOpts.td
+++ b/llvm/tools/llvm-objdump/ObjdumpOpts.td
@@ -137,6 +137,9 @@ def mattr_EQ : Joined<["--"], "mattr=">,
   MetaVarName<"a1,+a2,-a3,...">,
   HelpText<"Target specific attributes (--mattr=help for details)">;
 
+def mllvm : Separate<["-"], "mllvm">, HelpText<"Specify an argument to forward to LLVM's CommandLine library">, MetaVarName<"<arg>">;
+def : Joined<["-"], "mllvm=">, Alias<mllvm>;
+
 def no_show_raw_insn : Flag<["--"], "no-show-raw-insn">,
   HelpText<"When disassembling instructions, "
            "do not print the instruction bytes.">;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 1cdd84b20970fe..463d73e73ef82a 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3320,10 +3320,13 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
         DisassemblerOptions.push_back(V.str());
     }
   }
-  if (AsmSyntax) {
-    const char *Argv[] = {"llvm-objdump", AsmSyntax};
-    llvm::cl::ParseCommandLineOptions(2, Argv);
-  }
+  SmallVector<const char *> Args = {"llvm-objdump"};
+  for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_mllvm))
+    Args.push_back(A->getValue());
+  if (AsmSyntax)
+    Args.push_back(AsmSyntax);
+  if (Args.size() > 1)
+    llvm::cl::ParseCommandLineOptions(Args.size(), Args.data());
 
   // Look up any provided build IDs, then append them to the input filenames.
   for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_build_id)) {

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too.

@MaskRay MaskRay merged commit 3cd1e73 into llvm:main Dec 19, 2023
@MaskRay MaskRay deleted the objdump-mllvm branch December 19, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants