aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-04-23 16:06:07 -0700
committerFangrui Song <maskray@google.com>2020-04-27 09:43:51 -0700
commit3c9c9c1768fdca3fb06c96cc982d9fd240689a1b (patch)
treee55338516adcdedff51ac8ff113cf465ebd11177 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent5c03beefa720bddb3e3f53c595a76bce7ad50f37 (diff)
downloadllvm-3c9c9c1768fdca3fb06c96cc982d9fd240689a1b.zip
llvm-3c9c9c1768fdca3fb06c96cc982d9fd240689a1b.tar.gz
llvm-3c9c9c1768fdca3fb06c96cc982d9fd240689a1b.tar.bz2
[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 <data1> ``` 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
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp21
1 files changed, 15 insertions, 6 deletions
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<uint64_t> 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.