Skip to content

Commit 3cd1e73

Browse files
authored
[llvm-objdump] Add -mllvm (#75892)
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
1 parent 1d57b9a commit 3cd1e73

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

llvm/docs/CommandGuide/llvm-objdump.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ OPTIONS
198198
Enable/disable target-specific attributes. Specify ``--mattr=help`` to display
199199
the available attributes.
200200

201+
.. option:: -mllvm <arg>
202+
203+
Specify an argument to forward to LLVM's CommandLine library.
204+
201205
.. option:: --no-leading-addr, --no-addresses
202206

203207
When disassembling, do not print leading addresses for instructions or inline

llvm/test/tools/llvm-objdump/mllvm.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# REQUIRES: x86-registered-target
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t
3+
# RUN: llvm-objdump --no-print-imm-hex -d -mllvm --x86-asm-syntax=intel %t | FileCheck %s
4+
# RUN: llvm-objdump --no-print-imm-hex -d -mllvm=--x86-asm-syntax=intel %t | FileCheck %s
5+
6+
# CHECK: lea rax, [rsi + 4*rdi + 5]
7+
8+
leaq 5(%rsi,%rdi,4), %rax

llvm/tools/llvm-objdump/ObjdumpOpts.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def mattr_EQ : Joined<["--"], "mattr=">,
137137
MetaVarName<"a1,+a2,-a3,...">,
138138
HelpText<"Target specific attributes (--mattr=help for details)">;
139139

140+
def mllvm : Separate<["-"], "mllvm">, HelpText<"Specify an argument to forward to LLVM's CommandLine library">, MetaVarName<"<arg>">;
141+
def : Joined<["-"], "mllvm=">, Alias<mllvm>;
142+
140143
def no_show_raw_insn : Flag<["--"], "no-show-raw-insn">,
141144
HelpText<"When disassembling instructions, "
142145
"do not print the instruction bytes.">;

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,10 +3320,13 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
33203320
DisassemblerOptions.push_back(V.str());
33213321
}
33223322
}
3323-
if (AsmSyntax) {
3324-
const char *Argv[] = {"llvm-objdump", AsmSyntax};
3325-
llvm::cl::ParseCommandLineOptions(2, Argv);
3326-
}
3323+
SmallVector<const char *> Args = {"llvm-objdump"};
3324+
for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_mllvm))
3325+
Args.push_back(A->getValue());
3326+
if (AsmSyntax)
3327+
Args.push_back(AsmSyntax);
3328+
if (Args.size() > 1)
3329+
llvm::cl::ParseCommandLineOptions(Args.size(), Args.data());
33273330

33283331
// Look up any provided build IDs, then append them to the input filenames.
33293332
for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_build_id)) {

0 commit comments

Comments
 (0)