diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst index b156b212e461f..959452a74b23e 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 + + 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 0000000000000..7fb14ff085fa9 --- /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 100a95d3d9254..c1dec5ced89d3 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<"">; +def : Joined<["-"], "mllvm=">, Alias; + 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 1cdd84b20970f..463d73e73ef82 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 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)) {