summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump/COFFDump.cpp
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
commit9c674e68519af463541058bcb44550f827f0958d (patch)
tree8883fdb879bb93f8a574f6dd2a7dda3f1577b24c /llvm/tools/llvm-objdump/COFFDump.cpp
parentaf02c1c0038600d41030cdc0d52dbfd05c76653e (diff)
downloadbcm5719-llvm-9c674e68519af463541058bcb44550f827f0958d.tar.gz
bcm5719-llvm-9c674e68519af463541058bcb44550f827f0958d.zip
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. llvm-svn: 202785
Diffstat (limited to 'llvm/tools/llvm-objdump/COFFDump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/COFFDump.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index ba5de46b9f6..53cedbbdbd4 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/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);
}
}
OpenPOWER on IntegriCloud