mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-14 15:25:25 +00:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user