summaryrefslogtreecommitdiff
path: root/tools/llvm-objdump
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-03-04 04:00:55 +0000
committerRui Ueyama <ruiu@google.com>2014-03-04 04:00:55 +0000
commit3ab0ce0cde91cade8e6d0c04d439dbe3988aa204 (patch)
tree1180ab60c3db4c629b0fa58c3bca76caf4418d82 /tools/llvm-objdump
parent7ef591d612837b5cdf2b9ed7f7eea2fc799117af (diff)
downloadllvm-3ab0ce0cde91cade8e6d0c04d439dbe3988aa204.tar.gz
llvm-3ab0ce0cde91cade8e6d0c04d439dbe3988aa204.tar.bz2
llvm-3ab0ce0cde91cade8e6d0c04d439dbe3988aa204.tar.xz
llvm-objdump: Print x64 unwind info in executable.
The original code does not work correctly on executable files because the code is written in such a way that only object files are assumed to be given to llvm-objdump. Contents of RuntimeFunction are different between executables and objects. In executables, fields in RuntimeFunction have actual addresses to unwind info structures. On the other hand, in object files, the fields have zero value, but instead there are relocations pointing to the fields, so that Linker will fill them at link-time. So, when we are reading an object file, we need to use relocation info to find the location of unwind info. When executable, we should just look at the values in RuntimeFunction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202785 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-objdump')
-rw-r--r--tools/llvm-objdump/COFFDump.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp
index ba5de46b9f..53cedbbdbd 100644
--- a/tools/llvm-objdump/COFFDump.cpp
+++ b/tools/llvm-objdump/COFFDump.cpp
@@ -453,10 +453,32 @@ static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo *UI) {
outs().flush();
}
+/// Prints out the given RuntumeFunction struct for x64, assuming that Obj is
+/// pointing to an executable file.
static void printRuntimeFunction(const COFFObjectFile *Obj,
- const RuntimeFunction &RF,
- uint64_t SectionOffset,
- const std::vector<RelocationRef> &Rels) {
+ const RuntimeFunction &RF) {
+ if (!RF.StartAddress)
+ return;
+ outs() << "Function Table:\n"
+ << format(" Start Address: 0x%04x\n", RF.StartAddress)
+ << format(" End Address: 0x%04x\n", RF.EndAddress)
+ << format(" Unwind Info Address: : 0x%04x\n\n", RF.UnwindInfoOffset);
+ uintptr_t addr;
+ if (Obj->getRvaPtr(RF.UnwindInfoOffset, addr))
+ return;
+ printWin64EHUnwindInfo(reinterpret_cast<const Win64EH::UnwindInfo *>(addr));
+}
+
+/// Prints out the given RuntumeFunction struct for x64, assuming that Obj is
+/// pointing to an object file. Unlike executable, fields in RuntumeFunction
+/// struct are filled with zeros, but instead there are relocations pointing to
+/// them so that the linker will fill targets' RVAs to the fields at link
+/// time. This function interprets the relocations to find the data to be used
+/// in the resulting executable.
+static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
+ const RuntimeFunction &RF,
+ uint64_t SectionOffset,
+ const std::vector<RelocationRef> &Rels) {
outs() << "Function Table:\n";
outs() << " Start Address: ";
printCOFFSymbolAddress(outs(), Rels,
@@ -516,10 +538,17 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
return;
ArrayRef<RuntimeFunction> RFs(RFStart, NumRFs);
+ bool IsExecutable = Rels.empty();
+ if (IsExecutable) {
+ for (const RuntimeFunction &RF : RFs)
+ printRuntimeFunction(Obj, RF);
+ return;
+ }
+
for (const RuntimeFunction &RF : RFs) {
uint64_t SectionOffset =
std::distance(RFs.begin(), &RF) * sizeof(RuntimeFunction);
- printRuntimeFunction(Obj, RF, SectionOffset, Rels);
+ printRuntimeFunctionRels(Obj, RF, SectionOffset, Rels);
}
}