From 3c9c9c1768fdca3fb06c96cc982d9fd240689a1b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 23 Apr 2020 16:06:07 -0700 Subject: [llvm-objdump] Print target address with evaluateMemoryOperandAddress() D63847 added `MCInstrAnalysis::evaluateMemoryOperandAddress()`. This patch leverages the feature to print the target addresses for evaluable instructions. ``` -400a: movl 4080(%rip), %eax +400a: movl 4080(%rip), %eax # 5000 ``` This patch also deletes `MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || MIA->isConditionalBranch(Inst)` which is used to guard `MCInstrAnalysis::evaluateBranch()` Reviewed By: jhenderson, skan Differential Revision: https://reviews.llvm.org/D78776 --- llvm/tools/llvm-objdump/llvm-objdump.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp') diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index a68a8c5..5cb3a54 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1513,13 +1513,22 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, Comments.clear(); // If disassembly has failed, avoid analysing invalid/incomplete - // instruction information. Otherwise, try to resolve the target of a - // call, tail call, etc. to a specific symbol. - if (Disassembled && MIA && - (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst) || - MIA->isConditionalBranch(Inst))) { + // instruction information. Otherwise, try to resolve the target address + // (jump target or memory operand address) and print it on the right of + // the instruction. + if (Disassembled && MIA) { uint64_t Target; - if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) { + bool PrintTarget = + MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target); + if (!PrintTarget) + if (Optional MaybeTarget = + MIA->evaluateMemoryOperandAddress(Inst, SectionAddr + Index, + Size)) { + Target = *MaybeTarget; + PrintTarget = true; + outs() << " # " << Twine::utohexstr(Target); + } + if (PrintTarget) { // In a relocatable object, the target's section must reside in // the same section as the call instruction or it is accessed // through a relocation. -- cgit v1.1