From 3ab0ce0cde91cade8e6d0c04d439dbe3988aa204 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 4 Mar 2014 04:00:55 +0000 Subject: 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 --- tools/llvm-objdump/COFFDump.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'tools') 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 &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(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 &Rels) { outs() << "Function Table:\n"; outs() << " Start Address: "; printCOFFSymbolAddress(outs(), Rels, @@ -516,10 +538,17 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { return; ArrayRef 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); } } -- cgit v1.2.3