2012-12-05 20:12:35 +00:00
|
|
|
//===-- COFFDump.cpp - COFF-specific dumper ---------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-12-05 20:12:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 15:54:18 +00:00
|
|
|
/// This file implements the COFF-specific dumper for llvm-objdump.
|
2012-12-05 20:12:35 +00:00
|
|
|
/// It outputs the Win64 EH data structures as plain text.
|
2014-01-24 17:20:08 +00:00
|
|
|
/// The encoding of the unwind codes is described in MSDN:
|
2012-12-05 20:12:35 +00:00
|
|
|
/// http://msdn.microsoft.com/en-us/library/ck9asaa9.aspx
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-objdump.h"
|
2018-08-20 22:18:21 +00:00
|
|
|
#include "llvm/Demangle/Demangle.h"
|
2012-12-05 20:12:35 +00:00
|
|
|
#include "llvm/Object/COFF.h"
|
2016-08-18 16:39:19 +00:00
|
|
|
#include "llvm/Object/COFFImportFile.h"
|
2012-12-05 20:12:35 +00:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2013-01-02 10:26:28 +00:00
|
|
|
#include "llvm/Support/Win64EH.h"
|
2018-11-11 22:12:04 +00:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2012-12-05 20:12:35 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
using namespace llvm::object;
|
2012-12-05 20:12:35 +00:00
|
|
|
using namespace llvm::Win64EH;
|
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
namespace llvm {
|
2012-12-05 20:12:35 +00:00
|
|
|
// Returns the name of the unwind code.
|
|
|
|
static StringRef getUnwindCodeTypeName(uint8_t Code) {
|
|
|
|
switch(Code) {
|
|
|
|
default: llvm_unreachable("Invalid unwind code");
|
|
|
|
case UOP_PushNonVol: return "UOP_PushNonVol";
|
|
|
|
case UOP_AllocLarge: return "UOP_AllocLarge";
|
|
|
|
case UOP_AllocSmall: return "UOP_AllocSmall";
|
|
|
|
case UOP_SetFPReg: return "UOP_SetFPReg";
|
|
|
|
case UOP_SaveNonVol: return "UOP_SaveNonVol";
|
|
|
|
case UOP_SaveNonVolBig: return "UOP_SaveNonVolBig";
|
|
|
|
case UOP_SaveXMM128: return "UOP_SaveXMM128";
|
|
|
|
case UOP_SaveXMM128Big: return "UOP_SaveXMM128Big";
|
|
|
|
case UOP_PushMachFrame: return "UOP_PushMachFrame";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the name of a referenced register.
|
|
|
|
static StringRef getUnwindRegisterName(uint8_t Reg) {
|
|
|
|
switch(Reg) {
|
|
|
|
default: llvm_unreachable("Invalid register");
|
|
|
|
case 0: return "RAX";
|
|
|
|
case 1: return "RCX";
|
|
|
|
case 2: return "RDX";
|
|
|
|
case 3: return "RBX";
|
|
|
|
case 4: return "RSP";
|
|
|
|
case 5: return "RBP";
|
|
|
|
case 6: return "RSI";
|
|
|
|
case 7: return "RDI";
|
|
|
|
case 8: return "R8";
|
|
|
|
case 9: return "R9";
|
|
|
|
case 10: return "R10";
|
|
|
|
case 11: return "R11";
|
|
|
|
case 12: return "R12";
|
|
|
|
case 13: return "R13";
|
|
|
|
case 14: return "R14";
|
|
|
|
case 15: return "R15";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculates the number of array slots required for the unwind code.
|
|
|
|
static unsigned getNumUsedSlots(const UnwindCode &UnwindCode) {
|
|
|
|
switch (UnwindCode.getUnwindOp()) {
|
|
|
|
default: llvm_unreachable("Invalid unwind code");
|
|
|
|
case UOP_PushNonVol:
|
|
|
|
case UOP_AllocSmall:
|
|
|
|
case UOP_SetFPReg:
|
|
|
|
case UOP_PushMachFrame:
|
|
|
|
return 1;
|
|
|
|
case UOP_SaveNonVol:
|
|
|
|
case UOP_SaveXMM128:
|
|
|
|
return 2;
|
|
|
|
case UOP_SaveNonVolBig:
|
|
|
|
case UOP_SaveXMM128Big:
|
|
|
|
return 3;
|
|
|
|
case UOP_AllocLarge:
|
|
|
|
return (UnwindCode.getOpInfo() == 0) ? 2 : 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints one unwind code. Because an unwind code can occupy up to 3 slots in
|
|
|
|
// the unwind codes array, this function requires that the correct number of
|
|
|
|
// slots is provided.
|
|
|
|
static void printUnwindCode(ArrayRef<UnwindCode> UCs) {
|
|
|
|
assert(UCs.size() >= getNumUsedSlots(UCs[0]));
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << format(" 0x%02x: ", unsigned(UCs[0].u.CodeOffset))
|
2012-12-05 20:12:35 +00:00
|
|
|
<< getUnwindCodeTypeName(UCs[0].getUnwindOp());
|
|
|
|
switch (UCs[0].getUnwindOp()) {
|
|
|
|
case UOP_PushNonVol:
|
|
|
|
outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo());
|
|
|
|
break;
|
|
|
|
case UOP_AllocLarge:
|
|
|
|
if (UCs[0].getOpInfo() == 0) {
|
|
|
|
outs() << " " << UCs[1].FrameOffset;
|
|
|
|
} else {
|
|
|
|
outs() << " " << UCs[1].FrameOffset
|
|
|
|
+ (static_cast<uint32_t>(UCs[2].FrameOffset) << 16);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UOP_AllocSmall:
|
|
|
|
outs() << " " << ((UCs[0].getOpInfo() + 1) * 8);
|
|
|
|
break;
|
|
|
|
case UOP_SetFPReg:
|
|
|
|
outs() << " ";
|
|
|
|
break;
|
|
|
|
case UOP_SaveNonVol:
|
|
|
|
outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo())
|
|
|
|
<< format(" [0x%04x]", 8 * UCs[1].FrameOffset);
|
|
|
|
break;
|
|
|
|
case UOP_SaveNonVolBig:
|
|
|
|
outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo())
|
|
|
|
<< format(" [0x%08x]", UCs[1].FrameOffset
|
|
|
|
+ (static_cast<uint32_t>(UCs[2].FrameOffset) << 16));
|
|
|
|
break;
|
|
|
|
case UOP_SaveXMM128:
|
|
|
|
outs() << " XMM" << static_cast<uint32_t>(UCs[0].getOpInfo())
|
|
|
|
<< format(" [0x%04x]", 16 * UCs[1].FrameOffset);
|
|
|
|
break;
|
|
|
|
case UOP_SaveXMM128Big:
|
|
|
|
outs() << " XMM" << UCs[0].getOpInfo()
|
|
|
|
<< format(" [0x%08x]", UCs[1].FrameOffset
|
|
|
|
+ (static_cast<uint32_t>(UCs[2].FrameOffset) << 16));
|
|
|
|
break;
|
|
|
|
case UOP_PushMachFrame:
|
|
|
|
outs() << " " << (UCs[0].getOpInfo() ? "w/o" : "w")
|
|
|
|
<< " error code";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
outs() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAllUnwindCodes(ArrayRef<UnwindCode> UCs) {
|
|
|
|
for (const UnwindCode *I = UCs.begin(), *E = UCs.end(); I < E; ) {
|
|
|
|
unsigned UsedSlots = getNumUsedSlots(*I);
|
|
|
|
if (UsedSlots > UCs.size()) {
|
|
|
|
outs() << "Unwind data corrupted: Encountered unwind op "
|
|
|
|
<< getUnwindCodeTypeName((*I).getUnwindOp())
|
|
|
|
<< " which requires " << UsedSlots
|
|
|
|
<< " slots, but only " << UCs.size()
|
|
|
|
<< " remaining in buffer";
|
|
|
|
return ;
|
|
|
|
}
|
2015-09-21 05:32:41 +00:00
|
|
|
printUnwindCode(makeArrayRef(I, E));
|
2012-12-05 20:12:35 +00:00
|
|
|
I += UsedSlots;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a symbol sym this functions returns the address and section of it.
|
2019-04-09 05:41:24 +00:00
|
|
|
static Error resolveSectionAndAddress(const COFFObjectFile *Obj,
|
|
|
|
const SymbolRef &Sym,
|
|
|
|
const coff_section *&ResolvedSection,
|
|
|
|
uint64_t &ResolvedAddr) {
|
2016-06-24 18:24:42 +00:00
|
|
|
Expected<uint64_t> ResolvedAddrOrErr = Sym.getAddress();
|
|
|
|
if (!ResolvedAddrOrErr)
|
2019-04-09 05:41:24 +00:00
|
|
|
return ResolvedAddrOrErr.takeError();
|
2015-07-03 18:19:00 +00:00
|
|
|
ResolvedAddr = *ResolvedAddrOrErr;
|
2016-05-02 20:28:12 +00:00
|
|
|
Expected<section_iterator> Iter = Sym.getSection();
|
|
|
|
if (!Iter)
|
2019-04-09 05:41:24 +00:00
|
|
|
return Iter.takeError();
|
2015-08-07 23:27:14 +00:00
|
|
|
ResolvedSection = Obj->getCOFFSection(**Iter);
|
2019-04-09 05:41:24 +00:00
|
|
|
return Error::success();
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Given a vector of relocations for a section and an offset into this section
|
|
|
|
// the function returns the symbol used for the relocation at the offset.
|
2019-04-09 05:41:24 +00:00
|
|
|
static Error resolveSymbol(const std::vector<RelocationRef> &Rels,
|
2014-06-13 03:07:50 +00:00
|
|
|
uint64_t Offset, SymbolRef &Sym) {
|
2016-09-30 23:22:42 +00:00
|
|
|
for (auto &R : Rels) {
|
|
|
|
uint64_t Ofs = R.getOffset();
|
2012-12-05 20:12:35 +00:00
|
|
|
if (Ofs == Offset) {
|
2016-09-30 23:22:42 +00:00
|
|
|
Sym = *R.getSymbol();
|
2019-04-09 05:41:24 +00:00
|
|
|
return Error::success();
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-09 05:41:24 +00:00
|
|
|
return make_error<BinaryError>();
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Given a vector of relocations for a section and an offset into this section
|
|
|
|
// the function resolves the symbol used for the relocation at the offset and
|
|
|
|
// returns the section content and the address inside the content pointed to
|
|
|
|
// by the symbol.
|
2019-04-09 05:41:24 +00:00
|
|
|
static Error
|
2014-06-13 03:07:50 +00:00
|
|
|
getSectionContents(const COFFObjectFile *Obj,
|
|
|
|
const std::vector<RelocationRef> &Rels, uint64_t Offset,
|
|
|
|
ArrayRef<uint8_t> &Contents, uint64_t &Addr) {
|
2012-12-05 20:12:35 +00:00
|
|
|
SymbolRef Sym;
|
2019-04-09 05:41:24 +00:00
|
|
|
if (Error E = resolveSymbol(Rels, Offset, Sym))
|
|
|
|
return E;
|
2012-12-05 20:12:35 +00:00
|
|
|
const coff_section *Section;
|
2019-04-09 05:41:24 +00:00
|
|
|
if (Error E = resolveSectionAndAddress(Obj, Sym, Section, Addr))
|
|
|
|
return E;
|
2019-05-14 04:22:51 +00:00
|
|
|
return Obj->getSectionContents(Section, Contents);
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Given a vector of relocations for a section and an offset into this section
|
|
|
|
// the function returns the name of the symbol used for the relocation at the
|
|
|
|
// offset.
|
2019-04-09 05:41:24 +00:00
|
|
|
static Error resolveSymbolName(const std::vector<RelocationRef> &Rels,
|
|
|
|
uint64_t Offset, StringRef &Name) {
|
2012-12-05 20:12:35 +00:00
|
|
|
SymbolRef Sym;
|
2019-04-09 05:41:24 +00:00
|
|
|
if (Error EC = resolveSymbol(Rels, Offset, Sym))
|
2014-01-16 20:57:55 +00:00
|
|
|
return EC;
|
2016-04-20 21:24:34 +00:00
|
|
|
Expected<StringRef> NameOrErr = Sym.getName();
|
|
|
|
if (!NameOrErr)
|
2019-04-09 05:41:24 +00:00
|
|
|
return NameOrErr.takeError();
|
2015-07-02 20:55:21 +00:00
|
|
|
Name = *NameOrErr;
|
2019-04-09 05:41:24 +00:00
|
|
|
return Error::success();
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
static void printCOFFSymbolAddress(raw_ostream &Out,
|
2012-12-05 20:12:35 +00:00
|
|
|
const std::vector<RelocationRef> &Rels,
|
|
|
|
uint64_t Offset, uint32_t Disp) {
|
|
|
|
StringRef Sym;
|
2014-02-28 05:21:29 +00:00
|
|
|
if (!resolveSymbolName(Rels, Offset, Sym)) {
|
|
|
|
Out << Sym;
|
|
|
|
if (Disp > 0)
|
|
|
|
Out << format(" + 0x%04x", Disp);
|
|
|
|
} else {
|
|
|
|
Out << format("0x%04x", Disp);
|
|
|
|
}
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 06:51:07 +00:00
|
|
|
static void
|
|
|
|
printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) {
|
|
|
|
if (Count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uintptr_t IntPtr = 0;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (std::error_code EC = Obj->getVaPtr(TableVA, IntPtr))
|
|
|
|
reportError(errorCodeToError(EC), Obj->getFileName());
|
|
|
|
|
2014-02-20 06:51:07 +00:00
|
|
|
const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
|
|
|
|
outs() << "SEH Table:";
|
|
|
|
for (int I = 0; I < Count; ++I)
|
2019-08-21 11:07:31 +00:00
|
|
|
outs() << format(" 0x%x", P[I] + Obj->getPE32Header()->ImageBase);
|
2014-02-20 06:51:07 +00:00
|
|
|
outs() << "\n\n";
|
|
|
|
}
|
|
|
|
|
2016-03-15 06:14:01 +00:00
|
|
|
template <typename T>
|
|
|
|
static void printTLSDirectoryT(const coff_tls_directory<T> *TLSDir) {
|
|
|
|
size_t FormatWidth = sizeof(T) * 2;
|
|
|
|
outs() << "TLS directory:"
|
|
|
|
<< "\n StartAddressOfRawData: "
|
|
|
|
<< format_hex(TLSDir->StartAddressOfRawData, FormatWidth)
|
|
|
|
<< "\n EndAddressOfRawData: "
|
|
|
|
<< format_hex(TLSDir->EndAddressOfRawData, FormatWidth)
|
|
|
|
<< "\n AddressOfIndex: "
|
|
|
|
<< format_hex(TLSDir->AddressOfIndex, FormatWidth)
|
|
|
|
<< "\n AddressOfCallBacks: "
|
|
|
|
<< format_hex(TLSDir->AddressOfCallBacks, FormatWidth)
|
|
|
|
<< "\n SizeOfZeroFill: "
|
|
|
|
<< TLSDir->SizeOfZeroFill
|
|
|
|
<< "\n Characteristics: "
|
|
|
|
<< TLSDir->Characteristics
|
|
|
|
<< "\n Alignment: "
|
|
|
|
<< TLSDir->getAlignment()
|
|
|
|
<< "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printTLSDirectory(const COFFObjectFile *Obj) {
|
2019-08-19 14:32:23 +00:00
|
|
|
const pe32_header *PE32Header = Obj->getPE32Header();
|
|
|
|
const pe32plus_header *PE32PlusHeader = Obj->getPE32PlusHeader();
|
2016-03-15 06:14:01 +00:00
|
|
|
|
|
|
|
// Skip if it's not executable.
|
|
|
|
if (!PE32Header && !PE32PlusHeader)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const data_directory *DataDir;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (std::error_code EC = Obj->getDataDirectory(COFF::TLS_TABLE, DataDir))
|
|
|
|
reportError(errorCodeToError(EC), Obj->getFileName());
|
|
|
|
|
2016-03-15 06:14:01 +00:00
|
|
|
if (DataDir->RelativeVirtualAddress == 0)
|
|
|
|
return;
|
2019-08-21 11:07:31 +00:00
|
|
|
|
|
|
|
uintptr_t IntPtr = 0;
|
|
|
|
if (std::error_code EC =
|
|
|
|
Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
|
|
|
|
reportError(errorCodeToError(EC), Obj->getFileName());
|
2016-03-15 06:14:01 +00:00
|
|
|
|
|
|
|
if (PE32Header) {
|
|
|
|
auto *TLSDir = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
|
|
|
|
printTLSDirectoryT(TLSDir);
|
|
|
|
} else {
|
|
|
|
auto *TLSDir = reinterpret_cast<const coff_tls_directory64 *>(IntPtr);
|
|
|
|
printTLSDirectoryT(TLSDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
outs() << "\n";
|
|
|
|
}
|
|
|
|
|
2014-02-19 03:53:11 +00:00
|
|
|
static void printLoadConfiguration(const COFFObjectFile *Obj) {
|
2019-08-19 14:35:08 +00:00
|
|
|
// Skip if it's not executable.
|
2019-08-19 14:32:23 +00:00
|
|
|
if (!Obj->getPE32Header())
|
2014-02-21 20:27:15 +00:00
|
|
|
return;
|
|
|
|
|
2014-02-19 03:53:11 +00:00
|
|
|
// Currently only x86 is supported
|
2014-09-10 12:51:52 +00:00
|
|
|
if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_I386)
|
2014-02-19 03:53:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const data_directory *DataDir;
|
2019-08-21 11:07:31 +00:00
|
|
|
|
|
|
|
if (std::error_code EC =
|
|
|
|
Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir))
|
|
|
|
reportError(errorCodeToError(EC), Obj->getFileName());
|
|
|
|
|
2014-02-19 03:53:11 +00:00
|
|
|
uintptr_t IntPtr = 0;
|
|
|
|
if (DataDir->RelativeVirtualAddress == 0)
|
|
|
|
return;
|
2019-08-21 11:07:31 +00:00
|
|
|
|
|
|
|
if (std::error_code EC =
|
|
|
|
Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
|
|
|
|
reportError(errorCodeToError(EC), Obj->getFileName());
|
2014-02-20 06:51:07 +00:00
|
|
|
|
2014-03-04 04:15:59 +00:00
|
|
|
auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
|
2014-02-19 03:53:11 +00:00
|
|
|
outs() << "Load configuration:"
|
|
|
|
<< "\n Timestamp: " << LoadConf->TimeDateStamp
|
|
|
|
<< "\n Major Version: " << LoadConf->MajorVersion
|
|
|
|
<< "\n Minor Version: " << LoadConf->MinorVersion
|
|
|
|
<< "\n GlobalFlags Clear: " << LoadConf->GlobalFlagsClear
|
|
|
|
<< "\n GlobalFlags Set: " << LoadConf->GlobalFlagsSet
|
|
|
|
<< "\n Critical Section Default Timeout: " << LoadConf->CriticalSectionDefaultTimeout
|
|
|
|
<< "\n Decommit Free Block Threshold: " << LoadConf->DeCommitFreeBlockThreshold
|
|
|
|
<< "\n Decommit Total Free Threshold: " << LoadConf->DeCommitTotalFreeThreshold
|
|
|
|
<< "\n Lock Prefix Table: " << LoadConf->LockPrefixTable
|
|
|
|
<< "\n Maximum Allocation Size: " << LoadConf->MaximumAllocationSize
|
|
|
|
<< "\n Virtual Memory Threshold: " << LoadConf->VirtualMemoryThreshold
|
|
|
|
<< "\n Process Affinity Mask: " << LoadConf->ProcessAffinityMask
|
|
|
|
<< "\n Process Heap Flags: " << LoadConf->ProcessHeapFlags
|
|
|
|
<< "\n CSD Version: " << LoadConf->CSDVersion
|
|
|
|
<< "\n Security Cookie: " << LoadConf->SecurityCookie
|
|
|
|
<< "\n SEH Table: " << LoadConf->SEHandlerTable
|
|
|
|
<< "\n SEH Count: " << LoadConf->SEHandlerCount
|
|
|
|
<< "\n\n";
|
2014-02-20 06:51:07 +00:00
|
|
|
printSEHTable(Obj, LoadConf->SEHandlerTable, LoadConf->SEHandlerCount);
|
|
|
|
outs() << "\n";
|
2014-02-19 03:53:11 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 21:04:00 +00:00
|
|
|
// Prints import tables. The import table is a table containing the list of
|
|
|
|
// DLL name and symbol names which will be linked by the loader.
|
|
|
|
static void printImportTables(const COFFObjectFile *Obj) {
|
2014-01-16 20:57:55 +00:00
|
|
|
import_directory_iterator I = Obj->import_directory_begin();
|
|
|
|
import_directory_iterator E = Obj->import_directory_end();
|
|
|
|
if (I == E)
|
2014-01-15 23:46:18 +00:00
|
|
|
return;
|
2013-09-27 21:04:00 +00:00
|
|
|
outs() << "The Import Tables:\n";
|
2016-06-26 04:36:32 +00:00
|
|
|
for (const ImportDirectoryEntryRef &DirRef : Obj->import_directories()) {
|
2016-07-31 19:25:21 +00:00
|
|
|
const coff_import_directory_table_entry *Dir;
|
2013-09-27 21:04:00 +00:00
|
|
|
StringRef Name;
|
2016-06-26 04:36:32 +00:00
|
|
|
if (DirRef.getImportTableEntry(Dir)) return;
|
|
|
|
if (DirRef.getName(Name)) return;
|
2013-09-27 21:04:00 +00:00
|
|
|
|
|
|
|
outs() << format(" lookup %08x time %08x fwd %08x name %08x addr %08x\n\n",
|
|
|
|
static_cast<uint32_t>(Dir->ImportLookupTableRVA),
|
|
|
|
static_cast<uint32_t>(Dir->TimeDateStamp),
|
|
|
|
static_cast<uint32_t>(Dir->ForwarderChain),
|
|
|
|
static_cast<uint32_t>(Dir->NameRVA),
|
|
|
|
static_cast<uint32_t>(Dir->ImportAddressTableRVA));
|
|
|
|
outs() << " DLL Name: " << Name << "\n";
|
|
|
|
outs() << " Hint/Ord Name\n";
|
2016-06-26 04:36:32 +00:00
|
|
|
for (const ImportedSymbolRef &Entry : DirRef.imported_symbols()) {
|
|
|
|
bool IsOrdinal;
|
|
|
|
if (Entry.isOrdinal(IsOrdinal))
|
|
|
|
return;
|
|
|
|
if (IsOrdinal) {
|
|
|
|
uint16_t Ordinal;
|
|
|
|
if (Entry.getOrdinal(Ordinal))
|
|
|
|
return;
|
|
|
|
outs() << format(" % 6d\n", Ordinal);
|
2013-09-27 21:04:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-26 04:36:32 +00:00
|
|
|
uint32_t HintNameRVA;
|
|
|
|
if (Entry.getHintNameRVA(HintNameRVA))
|
|
|
|
return;
|
2013-09-27 21:04:00 +00:00
|
|
|
uint16_t Hint;
|
|
|
|
StringRef Name;
|
2016-06-26 04:36:32 +00:00
|
|
|
if (Obj->getHintName(HintNameRVA, Hint, Name))
|
2013-09-27 21:04:00 +00:00
|
|
|
return;
|
|
|
|
outs() << format(" % 6d ", Hint) << Name << "\n";
|
|
|
|
}
|
|
|
|
outs() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-16 07:05:49 +00:00
|
|
|
// Prints export tables. The export table is a table containing the list of
|
|
|
|
// exported symbol from the DLL.
|
|
|
|
static void printExportTable(const COFFObjectFile *Obj) {
|
|
|
|
outs() << "Export Table:\n";
|
|
|
|
export_directory_iterator I = Obj->export_directory_begin();
|
|
|
|
export_directory_iterator E = Obj->export_directory_end();
|
|
|
|
if (I == E)
|
|
|
|
return;
|
2014-01-16 20:50:34 +00:00
|
|
|
StringRef DllName;
|
2014-01-17 22:02:24 +00:00
|
|
|
uint32_t OrdinalBase;
|
2014-01-16 20:50:34 +00:00
|
|
|
if (I->getDllName(DllName))
|
|
|
|
return;
|
2014-01-17 22:02:24 +00:00
|
|
|
if (I->getOrdinalBase(OrdinalBase))
|
|
|
|
return;
|
2014-01-16 20:50:34 +00:00
|
|
|
outs() << " DLL name: " << DllName << "\n";
|
2014-01-17 22:02:24 +00:00
|
|
|
outs() << " Ordinal base: " << OrdinalBase << "\n";
|
2014-01-16 07:05:49 +00:00
|
|
|
outs() << " Ordinal RVA Name\n";
|
2014-01-30 02:49:50 +00:00
|
|
|
for (; I != E; I = ++I) {
|
2014-01-16 07:05:49 +00:00
|
|
|
uint32_t Ordinal;
|
|
|
|
if (I->getOrdinal(Ordinal))
|
|
|
|
return;
|
|
|
|
uint32_t RVA;
|
|
|
|
if (I->getExportRVA(RVA))
|
|
|
|
return;
|
2016-01-12 23:28:42 +00:00
|
|
|
bool IsForwarder;
|
|
|
|
if (I->isForwarder(IsForwarder))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (IsForwarder) {
|
|
|
|
// Export table entries can be used to re-export symbols that
|
|
|
|
// this COFF file is imported from some DLLs. This is rare.
|
|
|
|
// In most cases IsForwarder is false.
|
|
|
|
outs() << format(" % 4d ", Ordinal);
|
|
|
|
} else {
|
|
|
|
outs() << format(" % 4d %# 8x", Ordinal, RVA);
|
|
|
|
}
|
2014-01-16 07:05:49 +00:00
|
|
|
|
|
|
|
StringRef Name;
|
2014-01-16 20:50:34 +00:00
|
|
|
if (I->getSymbolName(Name))
|
2014-01-16 07:05:49 +00:00
|
|
|
continue;
|
|
|
|
if (!Name.empty())
|
|
|
|
outs() << " " << Name;
|
2016-01-12 23:28:42 +00:00
|
|
|
if (IsForwarder) {
|
|
|
|
StringRef S;
|
|
|
|
if (I->getForwardTo(S))
|
|
|
|
return;
|
|
|
|
outs() << " (forwarded to " << S << ")";
|
|
|
|
}
|
2014-01-16 07:05:49 +00:00
|
|
|
outs() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 00:31:48 +00:00
|
|
|
// Given the COFF object file, this function returns the relocations for .pdata
|
|
|
|
// and the pointer to "runtime function" structs.
|
|
|
|
static bool getPDataSection(const COFFObjectFile *Obj,
|
|
|
|
std::vector<RelocationRef> &Rels,
|
|
|
|
const RuntimeFunction *&RFStart, int &NumRFs) {
|
2014-03-18 06:53:02 +00:00
|
|
|
for (const SectionRef &Section : Obj->sections()) {
|
2019-08-14 11:10:11 +00:00
|
|
|
StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
|
2014-03-04 00:31:48 +00:00
|
|
|
if (Name != ".pdata")
|
|
|
|
continue;
|
2012-12-05 20:12:35 +00:00
|
|
|
|
2014-03-18 06:53:02 +00:00
|
|
|
const coff_section *Pdata = Obj->getCOFFSection(Section);
|
|
|
|
for (const RelocationRef &Reloc : Section.relocations())
|
2014-03-14 14:22:49 +00:00
|
|
|
Rels.push_back(Reloc);
|
2012-12-05 20:12:35 +00:00
|
|
|
|
|
|
|
// Sort relocations by address.
|
2019-01-15 09:19:18 +00:00
|
|
|
llvm::sort(Rels, isRelocAddressLess);
|
2012-12-05 20:12:35 +00:00
|
|
|
|
|
|
|
ArrayRef<uint8_t> Contents;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (Error E = Obj->getSectionContents(Pdata, Contents))
|
|
|
|
reportError(std::move(E), Obj->getFileName());
|
|
|
|
|
2014-03-04 00:31:48 +00:00
|
|
|
if (Contents.empty())
|
|
|
|
continue;
|
2012-12-05 20:12:35 +00:00
|
|
|
|
2014-03-04 00:31:48 +00:00
|
|
|
RFStart = reinterpret_cast<const RuntimeFunction *>(Contents.data());
|
|
|
|
NumRFs = Contents.size() / sizeof(RuntimeFunction);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-05 20:12:35 +00:00
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
Error getCOFFRelocationValueString(const COFFObjectFile *Obj,
|
2019-04-08 16:24:08 +00:00
|
|
|
const RelocationRef &Rel,
|
|
|
|
SmallVectorImpl<char> &Result) {
|
2019-01-18 11:33:26 +00:00
|
|
|
symbol_iterator SymI = Rel.getSymbol();
|
|
|
|
Expected<StringRef> SymNameOrErr = SymI->getName();
|
|
|
|
if (!SymNameOrErr)
|
2019-04-08 16:24:08 +00:00
|
|
|
return SymNameOrErr.takeError();
|
2019-01-18 11:33:26 +00:00
|
|
|
StringRef SymName = *SymNameOrErr;
|
|
|
|
Result.append(SymName.begin(), SymName.end());
|
2019-04-08 16:24:08 +00:00
|
|
|
return Error::success();
|
2019-01-18 11:33:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-04 03:08:45 +00:00
|
|
|
static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo *UI) {
|
|
|
|
// The casts to int are required in order to output the value as number.
|
|
|
|
// Without the casts the value would be interpreted as char data (which
|
|
|
|
// results in garbage output).
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << " Version: " << static_cast<int>(UI->getVersion()) << "\n";
|
|
|
|
outs() << " Flags: " << static_cast<int>(UI->getFlags());
|
2014-03-04 03:08:45 +00:00
|
|
|
if (UI->getFlags()) {
|
|
|
|
if (UI->getFlags() & UNW_ExceptionHandler)
|
|
|
|
outs() << " UNW_ExceptionHandler";
|
|
|
|
if (UI->getFlags() & UNW_TerminateHandler)
|
|
|
|
outs() << " UNW_TerminateHandler";
|
|
|
|
if (UI->getFlags() & UNW_ChainInfo)
|
|
|
|
outs() << " UNW_ChainInfo";
|
|
|
|
}
|
|
|
|
outs() << "\n";
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << " Size of prolog: " << static_cast<int>(UI->PrologSize) << "\n";
|
|
|
|
outs() << " Number of Codes: " << static_cast<int>(UI->NumCodes) << "\n";
|
2014-03-04 03:08:45 +00:00
|
|
|
// Maybe this should move to output of UOP_SetFPReg?
|
|
|
|
if (UI->getFrameRegister()) {
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << " Frame register: "
|
2014-03-04 03:08:45 +00:00
|
|
|
<< getUnwindRegisterName(UI->getFrameRegister()) << "\n";
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << " Frame offset: " << 16 * UI->getFrameOffset() << "\n";
|
2014-03-04 03:08:45 +00:00
|
|
|
} else {
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << " No frame pointer used\n";
|
2014-03-04 03:08:45 +00:00
|
|
|
}
|
|
|
|
if (UI->getFlags() & (UNW_ExceptionHandler | UNW_TerminateHandler)) {
|
|
|
|
// FIXME: Output exception handler data
|
|
|
|
} else if (UI->getFlags() & UNW_ChainInfo) {
|
|
|
|
// FIXME: Output chained unwind info
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UI->NumCodes)
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << " Unwind Codes:\n";
|
2014-03-04 03:08:45 +00:00
|
|
|
|
2015-09-21 05:32:41 +00:00
|
|
|
printAllUnwindCodes(makeArrayRef(&UI->UnwindCodes[0], UI->NumCodes));
|
2014-03-04 03:08:45 +00:00
|
|
|
|
2014-03-04 19:23:56 +00:00
|
|
|
outs() << "\n";
|
2014-03-04 03:08:45 +00:00
|
|
|
outs().flush();
|
|
|
|
}
|
|
|
|
|
2014-03-04 04:22:41 +00:00
|
|
|
/// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
|
2014-03-04 04:00:55 +00:00
|
|
|
/// pointing to an executable file.
|
2014-03-04 00:31:48 +00:00
|
|
|
static void printRuntimeFunction(const COFFObjectFile *Obj,
|
2014-03-04 04:00:55 +00:00
|
|
|
const RuntimeFunction &RF) {
|
|
|
|
if (!RF.StartAddress)
|
|
|
|
return;
|
|
|
|
outs() << "Function Table:\n"
|
2014-03-05 23:03:37 +00:00
|
|
|
<< format(" Start Address: 0x%04x\n",
|
|
|
|
static_cast<uint32_t>(RF.StartAddress))
|
|
|
|
<< format(" End Address: 0x%04x\n",
|
|
|
|
static_cast<uint32_t>(RF.EndAddress))
|
|
|
|
<< format(" Unwind Info Address: 0x%04x\n",
|
|
|
|
static_cast<uint32_t>(RF.UnwindInfoOffset));
|
2014-03-04 04:00:55 +00:00
|
|
|
uintptr_t addr;
|
|
|
|
if (Obj->getRvaPtr(RF.UnwindInfoOffset, addr))
|
|
|
|
return;
|
|
|
|
printWin64EHUnwindInfo(reinterpret_cast<const Win64EH::UnwindInfo *>(addr));
|
|
|
|
}
|
|
|
|
|
2014-03-04 04:22:41 +00:00
|
|
|
/// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
|
|
|
|
/// pointing to an object file. Unlike executable, fields in RuntimeFunction
|
2014-03-04 04:00:55 +00:00
|
|
|
/// 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) {
|
2014-03-04 00:31:48 +00:00
|
|
|
outs() << "Function Table:\n";
|
|
|
|
outs() << " Start Address: ";
|
|
|
|
printCOFFSymbolAddress(outs(), Rels,
|
|
|
|
SectionOffset +
|
|
|
|
/*offsetof(RuntimeFunction, StartAddress)*/ 0,
|
|
|
|
RF.StartAddress);
|
|
|
|
outs() << "\n";
|
2012-12-05 20:12:35 +00:00
|
|
|
|
2014-03-04 00:31:48 +00:00
|
|
|
outs() << " End Address: ";
|
|
|
|
printCOFFSymbolAddress(outs(), Rels,
|
|
|
|
SectionOffset +
|
|
|
|
/*offsetof(RuntimeFunction, EndAddress)*/ 4,
|
|
|
|
RF.EndAddress);
|
|
|
|
outs() << "\n";
|
2012-12-05 20:12:35 +00:00
|
|
|
|
2014-03-04 00:31:48 +00:00
|
|
|
outs() << " Unwind Info Address: ";
|
|
|
|
printCOFFSymbolAddress(outs(), Rels,
|
|
|
|
SectionOffset +
|
|
|
|
/*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
|
|
|
|
RF.UnwindInfoOffset);
|
|
|
|
outs() << "\n";
|
|
|
|
|
|
|
|
ArrayRef<uint8_t> XContents;
|
|
|
|
uint64_t UnwindInfoOffset = 0;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (Error E = getSectionContents(
|
|
|
|
Obj, Rels,
|
|
|
|
SectionOffset +
|
|
|
|
/*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
|
|
|
|
XContents, UnwindInfoOffset))
|
|
|
|
reportError(std::move(E), Obj->getFileName());
|
2014-03-04 00:31:48 +00:00
|
|
|
if (XContents.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UnwindInfoOffset += RF.UnwindInfoOffset;
|
|
|
|
if (UnwindInfoOffset > XContents.size())
|
|
|
|
return;
|
|
|
|
|
2014-03-04 04:15:59 +00:00
|
|
|
auto *UI = reinterpret_cast<const Win64EH::UnwindInfo *>(XContents.data() +
|
|
|
|
UnwindInfoOffset);
|
2014-03-04 03:08:45 +00:00
|
|
|
printWin64EHUnwindInfo(UI);
|
2014-03-04 00:31:48 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
void printCOFFUnwindInfo(const COFFObjectFile *Obj) {
|
2014-09-10 12:51:52 +00:00
|
|
|
if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) {
|
2018-11-11 22:12:04 +00:00
|
|
|
WithColor::error(errs(), "llvm-objdump")
|
|
|
|
<< "unsupported image machine type "
|
|
|
|
"(currently only AMD64 is supported).\n";
|
2014-03-04 00:31:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RelocationRef> Rels;
|
|
|
|
const RuntimeFunction *RFStart;
|
|
|
|
int NumRFs;
|
|
|
|
if (!getPDataSection(Obj, Rels, RFStart, NumRFs))
|
|
|
|
return;
|
|
|
|
ArrayRef<RuntimeFunction> RFs(RFStart, NumRFs);
|
|
|
|
|
2014-03-04 04:00:55 +00:00
|
|
|
bool IsExecutable = Rels.empty();
|
|
|
|
if (IsExecutable) {
|
|
|
|
for (const RuntimeFunction &RF : RFs)
|
|
|
|
printRuntimeFunction(Obj, RF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-04 00:31:48 +00:00
|
|
|
for (const RuntimeFunction &RF : RFs) {
|
|
|
|
uint64_t SectionOffset =
|
|
|
|
std::distance(RFs.begin(), &RF) * sizeof(RuntimeFunction);
|
2014-03-04 04:00:55 +00:00
|
|
|
printRuntimeFunctionRels(Obj, RF, SectionOffset, Rels);
|
2012-12-05 20:12:35 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-27 21:04:00 +00:00
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
void printCOFFFileHeader(const object::ObjectFile *Obj) {
|
2014-01-16 07:05:49 +00:00
|
|
|
const COFFObjectFile *file = dyn_cast<const COFFObjectFile>(Obj);
|
2016-03-15 06:14:01 +00:00
|
|
|
printTLSDirectory(file);
|
2014-02-19 03:53:11 +00:00
|
|
|
printLoadConfiguration(file);
|
2014-01-16 07:05:49 +00:00
|
|
|
printImportTables(file);
|
|
|
|
printExportTable(file);
|
2013-09-27 21:04:00 +00:00
|
|
|
}
|
2015-12-20 09:54:34 +00:00
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
void printCOFFSymbolTable(const object::COFFImportFile *i) {
|
2016-08-18 16:39:19 +00:00
|
|
|
unsigned Index = 0;
|
|
|
|
bool IsCode = i->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
|
|
|
|
|
|
|
|
for (const object::BasicSymbolRef &Sym : i->symbols()) {
|
|
|
|
std::string Name;
|
|
|
|
raw_string_ostream NS(Name);
|
|
|
|
|
2019-05-10 09:59:04 +00:00
|
|
|
cantFail(Sym.printName(NS));
|
2016-08-18 16:39:19 +00:00
|
|
|
NS.flush();
|
|
|
|
|
|
|
|
outs() << "[" << format("%2d", Index) << "]"
|
|
|
|
<< "(sec " << format("%2d", 0) << ")"
|
|
|
|
<< "(fl 0x00)" // Flag bits, which COFF doesn't have.
|
|
|
|
<< "(ty " << format("%3x", (IsCode && Index) ? 32 : 0) << ")"
|
|
|
|
<< "(scl " << format("%3x", 0) << ") "
|
|
|
|
<< "(nx " << 0 << ") "
|
|
|
|
<< "0x" << format("%08x", 0) << " " << Name << '\n';
|
|
|
|
|
|
|
|
++Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:31:42 +00:00
|
|
|
void printCOFFSymbolTable(const COFFObjectFile *coff) {
|
2015-12-20 09:54:34 +00:00
|
|
|
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
|
2017-10-11 17:23:15 +00:00
|
|
|
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
|
2019-08-21 11:07:31 +00:00
|
|
|
if (!Symbol)
|
|
|
|
reportError(Symbol.takeError(), coff->getFileName());
|
|
|
|
|
2015-12-20 09:54:34 +00:00
|
|
|
StringRef Name;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (std::error_code EC = coff->getSymbolName(*Symbol, Name))
|
|
|
|
reportError(errorCodeToError(EC), coff->getFileName());
|
2015-12-20 09:54:34 +00:00
|
|
|
|
|
|
|
outs() << "[" << format("%2d", SI) << "]"
|
|
|
|
<< "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
|
|
|
|
<< "(fl 0x00)" // Flag bits, which COFF doesn't have.
|
|
|
|
<< "(ty " << format("%3x", unsigned(Symbol->getType())) << ")"
|
2018-08-20 22:18:21 +00:00
|
|
|
<< "(scl " << format("%3x", unsigned(Symbol->getStorageClass()))
|
|
|
|
<< ") "
|
2015-12-20 09:54:34 +00:00
|
|
|
<< "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") "
|
|
|
|
<< "0x" << format("%08x", unsigned(Symbol->getValue())) << " "
|
2018-08-20 22:18:21 +00:00
|
|
|
<< Name;
|
|
|
|
if (Demangle && Name.startswith("?")) {
|
|
|
|
char *DemangledSymbol = nullptr;
|
|
|
|
size_t Size = 0;
|
|
|
|
int Status = -1;
|
|
|
|
DemangledSymbol =
|
|
|
|
microsoftDemangle(Name.data(), DemangledSymbol, &Size, &Status);
|
|
|
|
|
|
|
|
if (Status == 0 && DemangledSymbol) {
|
|
|
|
outs() << " (" << StringRef(DemangledSymbol) << ")";
|
|
|
|
std::free(DemangledSymbol);
|
2018-08-21 21:23:29 +00:00
|
|
|
} else {
|
|
|
|
outs() << " (invalid mangled name)";
|
2018-08-20 22:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
outs() << "\n";
|
2015-12-20 09:54:34 +00:00
|
|
|
|
|
|
|
for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
|
|
|
|
if (Symbol->isSectionDefinition()) {
|
|
|
|
const coff_aux_section_definition *asd;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (std::error_code EC =
|
|
|
|
coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd))
|
|
|
|
reportError(errorCodeToError(EC), coff->getFileName());
|
2015-12-20 09:54:34 +00:00
|
|
|
|
|
|
|
int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
|
|
|
|
|
|
|
|
outs() << "AUX "
|
|
|
|
<< format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
|
|
|
|
, unsigned(asd->Length)
|
|
|
|
, unsigned(asd->NumberOfRelocations)
|
|
|
|
, unsigned(asd->NumberOfLinenumbers)
|
|
|
|
, unsigned(asd->CheckSum))
|
|
|
|
<< format("assoc %d comdat %d\n"
|
|
|
|
, unsigned(AuxNumber)
|
|
|
|
, unsigned(asd->Selection));
|
|
|
|
} else if (Symbol->isFileRecord()) {
|
|
|
|
const char *FileName;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (std::error_code EC = coff->getAuxSymbol<char>(SI + 1, FileName))
|
|
|
|
reportError(errorCodeToError(EC), coff->getFileName());
|
2015-12-20 09:54:34 +00:00
|
|
|
|
|
|
|
StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
|
|
|
|
coff->getSymbolTableEntrySize());
|
|
|
|
outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n';
|
|
|
|
|
|
|
|
SI = SI + Symbol->getNumberOfAuxSymbols();
|
|
|
|
break;
|
2016-05-26 01:45:12 +00:00
|
|
|
} else if (Symbol->isWeakExternal()) {
|
|
|
|
const coff_aux_weak_external *awe;
|
2019-08-21 11:07:31 +00:00
|
|
|
if (std::error_code EC =
|
|
|
|
coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe))
|
|
|
|
reportError(errorCodeToError(EC), coff->getFileName());
|
2016-05-26 01:45:12 +00:00
|
|
|
|
|
|
|
outs() << "AUX " << format("indx %d srch %d\n",
|
|
|
|
static_cast<uint32_t>(awe->TagIndex),
|
|
|
|
static_cast<uint32_t>(awe->Characteristics));
|
2015-12-20 09:54:34 +00:00
|
|
|
} else {
|
|
|
|
outs() << "AUX Unknown\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 15:31:42 +00:00
|
|
|
} // namespace llvm
|