summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-07-07 22:06:59 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-07-07 22:06:59 +0000
commit81afca6bf7032eb61ba43b32f1380fd9e760c594 (patch)
treea1046cd0af2e5b9b0a4b19c6fed2cbf887f422db /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent683c4943e6e17534865909cadc90214cadfff86d (diff)
downloadbcm5719-llvm-81afca6bf7032eb61ba43b32f1380fd9e760c594.tar.gz
bcm5719-llvm-81afca6bf7032eb61ba43b32f1380fd9e760c594.zip
[llvm-objdump] Print the call target next to the instruction
GNU binutils provides this behavior. objdump -r doesn't really help when you aren't dealing with relocation object files. llvm-svn: 241631
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 0cb4fc24aa4..c0965d8843d 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -808,6 +808,27 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
SectionRelocMap[*Sec2].push_back(Section);
}
+ // Create a mapping from virtual address to symbol name. This is used to
+ // pretty print the target of a call.
+ std::vector<std::pair<uint64_t, StringRef>> AllSymbols;
+ if (MIA) {
+ for (const SymbolRef &Symbol : Obj->symbols()) {
+ ErrorOr<uint64_t> AddressOrErr = Symbol.getAddress();
+ if (error(AddressOrErr.getError()))
+ break;
+ uint64_t Address = *AddressOrErr;
+
+ ErrorOr<StringRef> Name = Symbol.getName();
+ if (error(Name.getError()))
+ break;
+ if (Name->empty())
+ continue;
+ AllSymbols.push_back(std::make_pair(Address, *Name));
+ }
+
+ array_pod_sort(AllSymbols.begin(), AllSymbols.end());
+ }
+
for (const SectionRef &Section : Obj->sections()) {
if (!Section.isText() || Section.isVirtual())
continue;
@@ -912,6 +933,21 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
SectionAddr + Index, outs(), "", *STI);
outs() << CommentStream.str();
Comments.clear();
+ if (MIA && (MIA->isCall(Inst) || MIA->isUnconditionalBranch(Inst))) {
+ uint64_t Target;
+ if (MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) {
+ const auto &TargetSym =
+ std::lower_bound(AllSymbols.begin(), AllSymbols.end(),
+ std::make_pair(Target, StringRef()));
+ if (TargetSym != AllSymbols.end()) {
+ outs() << " <" << TargetSym->second;
+ uint64_t Disp = TargetSym->first - Target;
+ if (Disp)
+ outs() << '-' << Disp;
+ outs() << '>';
+ }
+ }
+ }
outs() << "\n";
} else {
errs() << ToolName << ": warning: invalid instruction encoding\n";
OpenPOWER on IntegriCloud