2015-03-15 09:30:58 +08:00
|
|
|
//===- llvm-cxxdump.cpp - Dump C++ data in an Object File -------*- C++ -*-===//
|
2014-07-25 07:14:40 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2015-03-15 09:30:58 +08:00
|
|
|
// Dumps C++ data resident in object files and archives.
|
2014-07-25 07:14:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-15 09:30:58 +08:00
|
|
|
#include "llvm-cxxdump.h"
|
2014-07-25 07:14:40 +08:00
|
|
|
#include "Error.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2015-06-23 10:20:37 +08:00
|
|
|
#include "llvm/Object/SymbolSize.h"
|
2014-07-25 07:14:40 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2015-03-24 02:07:13 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-07-25 07:14:40 +08:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
using namespace llvm::support;
|
|
|
|
|
|
|
|
namespace opts {
|
|
|
|
cl::list<std::string> InputFilenames(cl::Positional,
|
|
|
|
cl::desc("<input object files>"),
|
|
|
|
cl::ZeroOrMore);
|
|
|
|
} // namespace opts
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-07-17 14:18:36 +08:00
|
|
|
static void error(std::error_code EC) {
|
2014-07-25 07:14:40 +08:00
|
|
|
if (!EC)
|
2015-07-17 14:18:36 +08:00
|
|
|
return;
|
2014-07-25 07:14:40 +08:00
|
|
|
outs() << "\nError reading file: " << EC.message() << ".\n";
|
|
|
|
outs().flush();
|
2015-07-17 14:18:36 +08:00
|
|
|
exit(1);
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
static void reportError(StringRef Input, StringRef Message) {
|
|
|
|
if (Input == "-")
|
|
|
|
Input = "<stdin>";
|
|
|
|
errs() << Input << ": " << Message << "\n";
|
|
|
|
errs().flush();
|
2015-07-17 14:18:36 +08:00
|
|
|
exit(1);
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reportError(StringRef Input, std::error_code EC) {
|
|
|
|
reportError(Input, EC.message());
|
|
|
|
}
|
|
|
|
|
2015-08-14 02:31:43 +08:00
|
|
|
static std::map<SectionRef, SmallVector<SectionRef, 1>> SectionRelocMap;
|
2014-11-03 15:23:25 +08:00
|
|
|
|
2015-07-17 14:18:36 +08:00
|
|
|
static void collectRelocatedSymbols(const ObjectFile *Obj,
|
2014-11-03 15:23:25 +08:00
|
|
|
const SectionRef &Sec, uint64_t SecAddress,
|
|
|
|
uint64_t SymAddress, uint64_t SymSize,
|
|
|
|
StringRef *I, StringRef *E) {
|
|
|
|
uint64_t SymOffset = SymAddress - SecAddress;
|
|
|
|
uint64_t SymEnd = SymOffset + SymSize;
|
2015-08-14 02:31:43 +08:00
|
|
|
for (const SectionRef &SR : SectionRelocMap[Sec]) {
|
2014-11-03 15:23:25 +08:00
|
|
|
for (const object::RelocationRef &Reloc : SR.relocations()) {
|
|
|
|
if (I == E)
|
|
|
|
break;
|
|
|
|
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
|
|
|
|
if (RelocSymI == Obj->symbol_end())
|
|
|
|
continue;
|
2016-04-21 05:24:34 +08:00
|
|
|
Expected<StringRef> RelocSymName = RelocSymI->getName();
|
|
|
|
error(errorToErrorCode(RelocSymName.takeError()));
|
2015-06-30 07:29:12 +08:00
|
|
|
uint64_t Offset = Reloc.getOffset();
|
2014-11-03 15:23:25 +08:00
|
|
|
if (Offset >= SymOffset && Offset < SymEnd) {
|
2015-07-03 04:55:21 +08:00
|
|
|
*I = *RelocSymName;
|
2014-11-03 15:23:25 +08:00
|
|
|
++I;
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 12:21:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 14:18:36 +08:00
|
|
|
static void collectRelocationOffsets(
|
2014-11-03 15:23:25 +08:00
|
|
|
const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress,
|
|
|
|
uint64_t SymAddress, uint64_t SymSize, StringRef SymName,
|
2014-09-26 12:21:51 +08:00
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) {
|
2014-11-03 15:23:25 +08:00
|
|
|
uint64_t SymOffset = SymAddress - SecAddress;
|
|
|
|
uint64_t SymEnd = SymOffset + SymSize;
|
2015-08-14 02:31:43 +08:00
|
|
|
for (const SectionRef &SR : SectionRelocMap[Sec]) {
|
2014-11-03 15:23:25 +08:00
|
|
|
for (const object::RelocationRef &Reloc : SR.relocations()) {
|
|
|
|
const object::symbol_iterator RelocSymI = Reloc.getSymbol();
|
|
|
|
if (RelocSymI == Obj->symbol_end())
|
|
|
|
continue;
|
2016-04-21 05:24:34 +08:00
|
|
|
Expected<StringRef> RelocSymName = RelocSymI->getName();
|
|
|
|
error(errorToErrorCode(RelocSymName.takeError()));
|
2015-06-30 07:29:12 +08:00
|
|
|
uint64_t Offset = Reloc.getOffset();
|
2014-11-03 15:23:25 +08:00
|
|
|
if (Offset >= SymOffset && Offset < SymEnd)
|
2015-07-03 04:55:21 +08:00
|
|
|
Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName;
|
2014-11-03 15:23:25 +08:00
|
|
|
}
|
2014-09-26 12:21:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-15 09:30:58 +08:00
|
|
|
static void dumpCXXData(const ObjectFile *Obj) {
|
2014-09-26 12:21:51 +08:00
|
|
|
struct CompleteObjectLocator {
|
|
|
|
StringRef Symbols[2];
|
2014-09-26 16:01:23 +08:00
|
|
|
ArrayRef<little32_t> Data;
|
2014-09-26 12:21:51 +08:00
|
|
|
};
|
|
|
|
struct ClassHierarchyDescriptor {
|
|
|
|
StringRef Symbols[1];
|
2014-09-26 16:01:23 +08:00
|
|
|
ArrayRef<little32_t> Data;
|
2014-09-26 12:21:51 +08:00
|
|
|
};
|
|
|
|
struct BaseClassDescriptor {
|
|
|
|
StringRef Symbols[2];
|
2014-09-26 16:01:23 +08:00
|
|
|
ArrayRef<little32_t> Data;
|
2014-09-26 12:21:51 +08:00
|
|
|
};
|
|
|
|
struct TypeDescriptor {
|
|
|
|
StringRef Symbols[1];
|
2014-09-26 16:01:23 +08:00
|
|
|
uint64_t AlwaysZero;
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef MangledName;
|
|
|
|
};
|
2015-02-27 08:43:58 +08:00
|
|
|
struct ThrowInfo {
|
|
|
|
uint32_t Flags;
|
|
|
|
};
|
|
|
|
struct CatchableTypeArray {
|
|
|
|
uint32_t NumEntries;
|
|
|
|
};
|
|
|
|
struct CatchableType {
|
|
|
|
uint32_t Flags;
|
|
|
|
uint32_t NonVirtualBaseAdjustmentOffset;
|
|
|
|
int32_t VirtualBasePointerOffset;
|
|
|
|
uint32_t VirtualBaseAdjustmentOffset;
|
2015-02-28 06:35:25 +08:00
|
|
|
uint32_t Size;
|
2015-02-27 08:43:58 +08:00
|
|
|
StringRef Symbols[2];
|
|
|
|
};
|
2014-07-25 07:14:40 +08:00
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> VFTableEntries;
|
2015-02-27 08:43:58 +08:00
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> TIEntries;
|
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> CTAEntries;
|
2014-09-26 16:01:23 +08:00
|
|
|
std::map<StringRef, ArrayRef<little32_t>> VBTables;
|
2014-09-26 12:21:51 +08:00
|
|
|
std::map<StringRef, CompleteObjectLocator> COLs;
|
|
|
|
std::map<StringRef, ClassHierarchyDescriptor> CHDs;
|
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> BCAEntries;
|
|
|
|
std::map<StringRef, BaseClassDescriptor> BCDs;
|
|
|
|
std::map<StringRef, TypeDescriptor> TDs;
|
2015-02-27 08:43:58 +08:00
|
|
|
std::map<StringRef, ThrowInfo> TIs;
|
|
|
|
std::map<StringRef, CatchableTypeArray> CTAs;
|
|
|
|
std::map<StringRef, CatchableType> CTs;
|
2014-11-03 15:23:25 +08:00
|
|
|
|
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> VTableSymEntries;
|
|
|
|
std::map<std::pair<StringRef, uint64_t>, int64_t> VTableDataEntries;
|
|
|
|
std::map<std::pair<StringRef, uint64_t>, StringRef> VTTEntries;
|
|
|
|
std::map<StringRef, StringRef> TINames;
|
|
|
|
|
2015-08-14 02:31:43 +08:00
|
|
|
SectionRelocMap.clear();
|
|
|
|
for (const SectionRef &Section : Obj->sections()) {
|
|
|
|
section_iterator Sec2 = Section.getRelocatedSection();
|
|
|
|
if (Sec2 != Obj->section_end())
|
|
|
|
SectionRelocMap[*Sec2].push_back(Section);
|
|
|
|
}
|
|
|
|
|
2014-11-03 15:23:25 +08:00
|
|
|
uint8_t BytesInAddress = Obj->getBytesInAddress();
|
|
|
|
|
2015-06-25 03:57:32 +08:00
|
|
|
std::vector<std::pair<SymbolRef, uint64_t>> SymAddr =
|
2015-06-23 10:20:37 +08:00
|
|
|
object::computeSymbolSizes(*Obj);
|
|
|
|
|
2015-06-25 03:57:32 +08:00
|
|
|
for (auto &P : SymAddr) {
|
2015-06-23 10:20:37 +08:00
|
|
|
object::SymbolRef Sym = P.first;
|
|
|
|
uint64_t SymSize = P.second;
|
2016-04-21 05:24:34 +08:00
|
|
|
Expected<StringRef> SymNameOrErr = Sym.getName();
|
|
|
|
error(errorToErrorCode(SymNameOrErr.takeError()));
|
2015-07-03 04:55:21 +08:00
|
|
|
StringRef SymName = *SymNameOrErr;
|
2015-08-08 07:27:14 +08:00
|
|
|
ErrorOr<object::section_iterator> SecIOrErr = Sym.getSection();
|
|
|
|
error(SecIOrErr.getError());
|
|
|
|
object::section_iterator SecI = *SecIOrErr;
|
2014-09-27 06:32:19 +08:00
|
|
|
// Skip external symbols.
|
|
|
|
if (SecI == Obj->section_end())
|
|
|
|
continue;
|
2014-11-03 15:23:25 +08:00
|
|
|
const SectionRef &Sec = *SecI;
|
2014-09-27 06:32:19 +08:00
|
|
|
// Skip virtual or BSS sections.
|
2014-11-03 15:23:25 +08:00
|
|
|
if (Sec.isBSS() || Sec.isVirtual())
|
2014-09-27 06:32:19 +08:00
|
|
|
continue;
|
|
|
|
StringRef SecContents;
|
2015-07-17 14:18:36 +08:00
|
|
|
error(Sec.getContents(SecContents));
|
2015-07-04 02:19:00 +08:00
|
|
|
ErrorOr<uint64_t> SymAddressOrErr = Sym.getAddress();
|
2015-07-17 14:18:36 +08:00
|
|
|
error(SymAddressOrErr.getError());
|
2015-07-04 02:19:00 +08:00
|
|
|
uint64_t SymAddress = *SymAddressOrErr;
|
2014-11-03 15:23:25 +08:00
|
|
|
uint64_t SecAddress = Sec.getAddress();
|
|
|
|
uint64_t SecSize = Sec.getSize();
|
|
|
|
uint64_t SymOffset = SymAddress - SecAddress;
|
|
|
|
StringRef SymContents = SecContents.substr(SymOffset, SymSize);
|
|
|
|
|
2014-07-25 07:14:40 +08:00
|
|
|
// VFTables in the MS-ABI start with '??_7' and are contained within their
|
|
|
|
// own COMDAT section. We then determine the contents of the VFTable by
|
|
|
|
// looking at each relocation in the section.
|
|
|
|
if (SymName.startswith("??_7")) {
|
|
|
|
// Each relocation either names a virtual method or a thunk. We note the
|
|
|
|
// offset into the section and the symbol used for the relocation.
|
2014-11-03 15:23:25 +08:00
|
|
|
collectRelocationOffsets(Obj, Sec, SecAddress, SecAddress, SecSize,
|
|
|
|
SymName, VFTableEntries);
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
// VBTables in the MS-ABI start with '??_8' and are filled with 32-bit
|
|
|
|
// offsets of virtual bases.
|
|
|
|
else if (SymName.startswith("??_8")) {
|
2014-09-26 16:01:23 +08:00
|
|
|
ArrayRef<little32_t> VBTableData(
|
2014-11-03 15:23:25 +08:00
|
|
|
reinterpret_cast<const little32_t *>(SymContents.data()),
|
|
|
|
SymContents.size() / sizeof(little32_t));
|
2014-07-25 07:14:40 +08:00
|
|
|
VBTables[SymName] = VBTableData;
|
|
|
|
}
|
2014-09-26 12:21:51 +08:00
|
|
|
// Complete object locators in the MS-ABI start with '??_R4'
|
|
|
|
else if (SymName.startswith("??_R4")) {
|
|
|
|
CompleteObjectLocator COL;
|
2015-09-21 13:32:41 +08:00
|
|
|
COL.Data = makeArrayRef(
|
2014-11-03 15:23:25 +08:00
|
|
|
reinterpret_cast<const little32_t *>(SymContents.data()), 3);
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols);
|
2015-07-17 14:18:36 +08:00
|
|
|
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
|
2014-09-26 12:21:51 +08:00
|
|
|
COLs[SymName] = COL;
|
|
|
|
}
|
|
|
|
// Class hierarchy descriptors in the MS-ABI start with '??_R3'
|
|
|
|
else if (SymName.startswith("??_R3")) {
|
|
|
|
ClassHierarchyDescriptor CHD;
|
2015-09-21 13:32:41 +08:00
|
|
|
CHD.Data = makeArrayRef(
|
2014-11-03 15:23:25 +08:00
|
|
|
reinterpret_cast<const little32_t *>(SymContents.data()), 3);
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols);
|
2015-07-17 14:18:36 +08:00
|
|
|
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
|
2014-09-26 12:21:51 +08:00
|
|
|
CHDs[SymName] = CHD;
|
|
|
|
}
|
|
|
|
// Class hierarchy descriptors in the MS-ABI start with '??_R2'
|
|
|
|
else if (SymName.startswith("??_R2")) {
|
|
|
|
// Each relocation names a base class descriptor. We note the offset into
|
|
|
|
// the section and the symbol used for the relocation.
|
2014-11-03 15:23:25 +08:00
|
|
|
collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize,
|
|
|
|
SymName, BCAEntries);
|
2014-09-26 12:21:51 +08:00
|
|
|
}
|
|
|
|
// Base class descriptors in the MS-ABI start with '??_R1'
|
|
|
|
else if (SymName.startswith("??_R1")) {
|
|
|
|
BaseClassDescriptor BCD;
|
2015-09-21 13:32:41 +08:00
|
|
|
BCD.Data = makeArrayRef(
|
2014-11-03 15:23:25 +08:00
|
|
|
reinterpret_cast<const little32_t *>(SymContents.data()) + 1, 5);
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols);
|
2015-07-17 14:18:36 +08:00
|
|
|
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
|
2014-09-26 12:21:51 +08:00
|
|
|
BCDs[SymName] = BCD;
|
|
|
|
}
|
|
|
|
// Type descriptors in the MS-ABI start with '??_R0'
|
|
|
|
else if (SymName.startswith("??_R0")) {
|
2014-11-03 15:23:25 +08:00
|
|
|
const char *DataPtr = SymContents.drop_front(BytesInAddress).data();
|
2014-09-26 12:21:51 +08:00
|
|
|
TypeDescriptor TD;
|
2014-09-26 16:01:23 +08:00
|
|
|
if (BytesInAddress == 8)
|
|
|
|
TD.AlwaysZero = *reinterpret_cast<const little64_t *>(DataPtr);
|
|
|
|
else
|
|
|
|
TD.AlwaysZero = *reinterpret_cast<const little32_t *>(DataPtr);
|
2014-11-03 15:23:25 +08:00
|
|
|
TD.MangledName = SymContents.drop_front(BytesInAddress * 2);
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols);
|
2015-07-17 14:18:36 +08:00
|
|
|
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
|
2014-09-26 12:21:51 +08:00
|
|
|
TDs[SymName] = TD;
|
|
|
|
}
|
2015-02-27 08:43:58 +08:00
|
|
|
// Throw descriptors in the MS-ABI start with '_TI'
|
|
|
|
else if (SymName.startswith("_TI") || SymName.startswith("__TI")) {
|
|
|
|
ThrowInfo TI;
|
|
|
|
TI.Flags = *reinterpret_cast<const little32_t *>(SymContents.data());
|
|
|
|
collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize,
|
|
|
|
SymName, TIEntries);
|
|
|
|
TIs[SymName] = TI;
|
|
|
|
}
|
|
|
|
// Catchable type arrays in the MS-ABI start with _CTA or __CTA.
|
|
|
|
else if (SymName.startswith("_CTA") || SymName.startswith("__CTA")) {
|
|
|
|
CatchableTypeArray CTA;
|
|
|
|
CTA.NumEntries =
|
|
|
|
*reinterpret_cast<const little32_t *>(SymContents.data());
|
|
|
|
collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize,
|
|
|
|
SymName, CTAEntries);
|
|
|
|
CTAs[SymName] = CTA;
|
|
|
|
}
|
|
|
|
// Catchable types in the MS-ABI start with _CT or __CT.
|
|
|
|
else if (SymName.startswith("_CT") || SymName.startswith("__CT")) {
|
|
|
|
const little32_t *DataPtr =
|
|
|
|
reinterpret_cast<const little32_t *>(SymContents.data());
|
|
|
|
CatchableType CT;
|
|
|
|
CT.Flags = DataPtr[0];
|
|
|
|
CT.NonVirtualBaseAdjustmentOffset = DataPtr[2];
|
|
|
|
CT.VirtualBasePointerOffset = DataPtr[3];
|
|
|
|
CT.VirtualBaseAdjustmentOffset = DataPtr[4];
|
2015-02-28 06:35:25 +08:00
|
|
|
CT.Size = DataPtr[5];
|
2015-02-27 08:43:58 +08:00
|
|
|
StringRef *I = std::begin(CT.Symbols), *E = std::end(CT.Symbols);
|
2015-07-17 14:18:36 +08:00
|
|
|
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
|
2015-02-27 08:43:58 +08:00
|
|
|
CTs[SymName] = CT;
|
|
|
|
}
|
2014-11-03 15:23:25 +08:00
|
|
|
// Construction vtables in the Itanium ABI start with '_ZTT' or '__ZTT'.
|
|
|
|
else if (SymName.startswith("_ZTT") || SymName.startswith("__ZTT")) {
|
|
|
|
collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize,
|
|
|
|
SymName, VTTEntries);
|
|
|
|
}
|
|
|
|
// Typeinfo names in the Itanium ABI start with '_ZTS' or '__ZTS'.
|
|
|
|
else if (SymName.startswith("_ZTS") || SymName.startswith("__ZTS")) {
|
|
|
|
TINames[SymName] = SymContents.slice(0, SymContents.find('\0'));
|
|
|
|
}
|
|
|
|
// Vtables in the Itanium ABI start with '_ZTV' or '__ZTV'.
|
|
|
|
else if (SymName.startswith("_ZTV") || SymName.startswith("__ZTV")) {
|
|
|
|
collectRelocationOffsets(Obj, Sec, SecAddress, SymAddress, SymSize,
|
|
|
|
SymName, VTableSymEntries);
|
|
|
|
for (uint64_t SymOffI = 0; SymOffI < SymSize; SymOffI += BytesInAddress) {
|
|
|
|
auto Key = std::make_pair(SymName, SymOffI);
|
|
|
|
if (VTableSymEntries.count(Key))
|
|
|
|
continue;
|
2015-03-15 09:30:58 +08:00
|
|
|
const char *DataPtr =
|
|
|
|
SymContents.substr(SymOffI, BytesInAddress).data();
|
2014-11-03 15:23:25 +08:00
|
|
|
int64_t VData;
|
|
|
|
if (BytesInAddress == 8)
|
|
|
|
VData = *reinterpret_cast<const little64_t *>(DataPtr);
|
|
|
|
else
|
|
|
|
VData = *reinterpret_cast<const little32_t *>(DataPtr);
|
|
|
|
VTableDataEntries[Key] = VData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Typeinfo structures in the Itanium ABI start with '_ZTI' or '__ZTI'.
|
|
|
|
else if (SymName.startswith("_ZTI") || SymName.startswith("__ZTI")) {
|
|
|
|
// FIXME: Do something with these!
|
|
|
|
}
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
2015-03-15 09:30:58 +08:00
|
|
|
for (const auto &VFTableEntry : VFTableEntries) {
|
2014-07-25 07:14:40 +08:00
|
|
|
StringRef VFTableName = VFTableEntry.first.first;
|
|
|
|
uint64_t Offset = VFTableEntry.first.second;
|
|
|
|
StringRef SymName = VFTableEntry.second;
|
|
|
|
outs() << VFTableName << '[' << Offset << "]: " << SymName << '\n';
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &VBTable : VBTables) {
|
2014-07-25 12:30:11 +08:00
|
|
|
StringRef VBTableName = VBTable.first;
|
2014-07-25 07:14:40 +08:00
|
|
|
uint32_t Idx = 0;
|
2014-09-26 16:01:23 +08:00
|
|
|
for (little32_t Offset : VBTable.second) {
|
2014-07-25 07:14:40 +08:00
|
|
|
outs() << VBTableName << '[' << Idx << "]: " << Offset << '\n';
|
2014-07-25 12:30:11 +08:00
|
|
|
Idx += sizeof(Offset);
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &COLPair : COLs) {
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef COLName = COLPair.first;
|
|
|
|
const CompleteObjectLocator &COL = COLPair.second;
|
|
|
|
outs() << COLName << "[IsImageRelative]: " << COL.Data[0] << '\n';
|
|
|
|
outs() << COLName << "[OffsetToTop]: " << COL.Data[1] << '\n';
|
|
|
|
outs() << COLName << "[VFPtrOffset]: " << COL.Data[2] << '\n';
|
|
|
|
outs() << COLName << "[TypeDescriptor]: " << COL.Symbols[0] << '\n';
|
2015-03-15 09:30:58 +08:00
|
|
|
outs() << COLName << "[ClassHierarchyDescriptor]: " << COL.Symbols[1]
|
|
|
|
<< '\n';
|
2014-09-26 12:21:51 +08:00
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &CHDPair : CHDs) {
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef CHDName = CHDPair.first;
|
|
|
|
const ClassHierarchyDescriptor &CHD = CHDPair.second;
|
|
|
|
outs() << CHDName << "[AlwaysZero]: " << CHD.Data[0] << '\n';
|
|
|
|
outs() << CHDName << "[Flags]: " << CHD.Data[1] << '\n';
|
|
|
|
outs() << CHDName << "[NumClasses]: " << CHD.Data[2] << '\n';
|
|
|
|
outs() << CHDName << "[BaseClassArray]: " << CHD.Symbols[0] << '\n';
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &BCAEntry : BCAEntries) {
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef BCAName = BCAEntry.first.first;
|
|
|
|
uint64_t Offset = BCAEntry.first.second;
|
|
|
|
StringRef SymName = BCAEntry.second;
|
|
|
|
outs() << BCAName << '[' << Offset << "]: " << SymName << '\n';
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &BCDPair : BCDs) {
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef BCDName = BCDPair.first;
|
|
|
|
const BaseClassDescriptor &BCD = BCDPair.second;
|
|
|
|
outs() << BCDName << "[TypeDescriptor]: " << BCD.Symbols[0] << '\n';
|
|
|
|
outs() << BCDName << "[NumBases]: " << BCD.Data[0] << '\n';
|
|
|
|
outs() << BCDName << "[OffsetInVBase]: " << BCD.Data[1] << '\n';
|
|
|
|
outs() << BCDName << "[VBPtrOffset]: " << BCD.Data[2] << '\n';
|
|
|
|
outs() << BCDName << "[OffsetInVBTable]: " << BCD.Data[3] << '\n';
|
|
|
|
outs() << BCDName << "[Flags]: " << BCD.Data[4] << '\n';
|
2015-03-15 09:30:58 +08:00
|
|
|
outs() << BCDName << "[ClassHierarchyDescriptor]: " << BCD.Symbols[1]
|
|
|
|
<< '\n';
|
2014-09-26 12:21:51 +08:00
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &TDPair : TDs) {
|
2014-09-26 12:21:51 +08:00
|
|
|
StringRef TDName = TDPair.first;
|
|
|
|
const TypeDescriptor &TD = TDPair.second;
|
|
|
|
outs() << TDName << "[VFPtr]: " << TD.Symbols[0] << '\n';
|
2014-09-26 16:01:23 +08:00
|
|
|
outs() << TDName << "[AlwaysZero]: " << TD.AlwaysZero << '\n';
|
2014-09-26 12:21:51 +08:00
|
|
|
outs() << TDName << "[MangledName]: ";
|
2014-09-26 13:50:45 +08:00
|
|
|
outs().write_escaped(TD.MangledName.rtrim(StringRef("\0", 1)),
|
|
|
|
/*UseHexEscapes=*/true)
|
|
|
|
<< '\n';
|
2014-09-26 12:21:51 +08:00
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &TIPair : TIs) {
|
2015-02-27 08:43:58 +08:00
|
|
|
StringRef TIName = TIPair.first;
|
|
|
|
const ThrowInfo &TI = TIPair.second;
|
|
|
|
auto dumpThrowInfoFlag = [&](const char *Name, uint32_t Flag) {
|
|
|
|
outs() << TIName << "[Flags." << Name
|
|
|
|
<< "]: " << (TI.Flags & Flag ? "true" : "false") << '\n';
|
|
|
|
};
|
|
|
|
auto dumpThrowInfoSymbol = [&](const char *Name, int Offset) {
|
|
|
|
outs() << TIName << '[' << Name << "]: ";
|
|
|
|
auto Entry = TIEntries.find(std::make_pair(TIName, Offset));
|
|
|
|
outs() << (Entry == TIEntries.end() ? "null" : Entry->second) << '\n';
|
|
|
|
};
|
|
|
|
outs() << TIName << "[Flags]: " << TI.Flags << '\n';
|
|
|
|
dumpThrowInfoFlag("Const", 1);
|
|
|
|
dumpThrowInfoFlag("Volatile", 2);
|
|
|
|
dumpThrowInfoSymbol("CleanupFn", 4);
|
|
|
|
dumpThrowInfoSymbol("ForwardCompat", 8);
|
|
|
|
dumpThrowInfoSymbol("CatchableTypeArray", 12);
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &CTAPair : CTAs) {
|
2015-02-27 08:43:58 +08:00
|
|
|
StringRef CTAName = CTAPair.first;
|
|
|
|
const CatchableTypeArray &CTA = CTAPair.second;
|
|
|
|
|
|
|
|
outs() << CTAName << "[NumEntries]: " << CTA.NumEntries << '\n';
|
|
|
|
|
|
|
|
unsigned Idx = 0;
|
|
|
|
for (auto I = CTAEntries.lower_bound(std::make_pair(CTAName, 0)),
|
|
|
|
E = CTAEntries.upper_bound(std::make_pair(CTAName, UINT64_MAX));
|
|
|
|
I != E; ++I)
|
|
|
|
outs() << CTAName << '[' << Idx++ << "]: " << I->second << '\n';
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &CTPair : CTs) {
|
2015-02-27 08:43:58 +08:00
|
|
|
StringRef CTName = CTPair.first;
|
|
|
|
const CatchableType &CT = CTPair.second;
|
|
|
|
auto dumpCatchableTypeFlag = [&](const char *Name, uint32_t Flag) {
|
|
|
|
outs() << CTName << "[Flags." << Name
|
|
|
|
<< "]: " << (CT.Flags & Flag ? "true" : "false") << '\n';
|
|
|
|
};
|
|
|
|
outs() << CTName << "[Flags]: " << CT.Flags << '\n';
|
|
|
|
dumpCatchableTypeFlag("ScalarType", 1);
|
|
|
|
dumpCatchableTypeFlag("VirtualInheritance", 4);
|
|
|
|
outs() << CTName << "[TypeDescriptor]: " << CT.Symbols[0] << '\n';
|
|
|
|
outs() << CTName << "[NonVirtualBaseAdjustmentOffset]: "
|
|
|
|
<< CT.NonVirtualBaseAdjustmentOffset << '\n';
|
|
|
|
outs() << CTName
|
|
|
|
<< "[VirtualBasePointerOffset]: " << CT.VirtualBasePointerOffset
|
|
|
|
<< '\n';
|
|
|
|
outs() << CTName << "[VirtualBaseAdjustmentOffset]: "
|
|
|
|
<< CT.VirtualBaseAdjustmentOffset << '\n';
|
2015-02-28 06:35:25 +08:00
|
|
|
outs() << CTName << "[Size]: " << CT.Size << '\n';
|
2015-02-27 08:43:58 +08:00
|
|
|
outs() << CTName
|
|
|
|
<< "[CopyCtor]: " << (CT.Symbols[1].empty() ? "null" : CT.Symbols[1])
|
|
|
|
<< '\n';
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &VTTPair : VTTEntries) {
|
2014-11-03 15:23:25 +08:00
|
|
|
StringRef VTTName = VTTPair.first.first;
|
|
|
|
uint64_t VTTOffset = VTTPair.first.second;
|
|
|
|
StringRef VTTEntry = VTTPair.second;
|
|
|
|
outs() << VTTName << '[' << VTTOffset << "]: " << VTTEntry << '\n';
|
|
|
|
}
|
2015-04-15 11:17:49 +08:00
|
|
|
for (const auto &TIPair : TINames) {
|
2014-11-03 15:23:25 +08:00
|
|
|
StringRef TIName = TIPair.first;
|
|
|
|
outs() << TIName << ": " << TIPair.second << '\n';
|
|
|
|
}
|
|
|
|
auto VTableSymI = VTableSymEntries.begin();
|
|
|
|
auto VTableSymE = VTableSymEntries.end();
|
|
|
|
auto VTableDataI = VTableDataEntries.begin();
|
|
|
|
auto VTableDataE = VTableDataEntries.end();
|
|
|
|
for (;;) {
|
|
|
|
bool SymDone = VTableSymI == VTableSymE;
|
|
|
|
bool DataDone = VTableDataI == VTableDataE;
|
|
|
|
if (SymDone && DataDone)
|
|
|
|
break;
|
|
|
|
if (!SymDone && (DataDone || VTableSymI->first < VTableDataI->first)) {
|
|
|
|
StringRef VTableName = VTableSymI->first.first;
|
|
|
|
uint64_t Offset = VTableSymI->first.second;
|
|
|
|
StringRef VTableEntry = VTableSymI->second;
|
|
|
|
outs() << VTableName << '[' << Offset << "]: ";
|
|
|
|
outs() << VTableEntry;
|
|
|
|
outs() << '\n';
|
|
|
|
++VTableSymI;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!DataDone && (SymDone || VTableDataI->first < VTableSymI->first)) {
|
|
|
|
StringRef VTableName = VTableDataI->first.first;
|
|
|
|
uint64_t Offset = VTableDataI->first.second;
|
|
|
|
int64_t VTableEntry = VTableDataI->second;
|
|
|
|
outs() << VTableName << '[' << Offset << "]: ";
|
|
|
|
outs() << VTableEntry;
|
|
|
|
outs() << '\n';
|
|
|
|
++VTableDataI;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpArchive(const Archive *Arc) {
|
2015-11-06 03:24:56 +08:00
|
|
|
for (auto &ErrorOrChild : Arc->children()) {
|
|
|
|
error(ErrorOrChild.getError());
|
|
|
|
const Archive::Child &ArcC = *ErrorOrChild;
|
2014-09-26 06:56:54 +08:00
|
|
|
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary();
|
2014-07-25 07:14:40 +08:00
|
|
|
if (std::error_code EC = ChildOrErr.getError()) {
|
|
|
|
// Ignore non-object files.
|
|
|
|
if (EC != object_error::invalid_file_type)
|
|
|
|
reportError(Arc->getFileName(), EC.message());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
|
2015-03-15 09:30:58 +08:00
|
|
|
dumpCXXData(Obj);
|
2014-07-25 07:14:40 +08:00
|
|
|
else
|
2015-03-15 09:30:58 +08:00
|
|
|
reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format);
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpInput(StringRef File) {
|
|
|
|
// Attempt to open the binary.
|
2016-04-07 06:14:09 +08:00
|
|
|
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
|
|
|
|
if (!BinaryOrErr) {
|
|
|
|
auto EC = errorToErrorCode(BinaryOrErr.takeError());
|
2014-07-25 07:14:40 +08:00
|
|
|
reportError(File, EC);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-20 02:44:46 +08:00
|
|
|
Binary &Binary = *BinaryOrErr.get().getBinary();
|
2014-07-25 07:14:40 +08:00
|
|
|
|
2014-08-01 22:31:55 +08:00
|
|
|
if (Archive *Arc = dyn_cast<Archive>(&Binary))
|
2014-07-25 07:14:40 +08:00
|
|
|
dumpArchive(Arc);
|
2014-08-01 22:31:55 +08:00
|
|
|
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(&Binary))
|
2015-03-15 09:30:58 +08:00
|
|
|
dumpCXXData(Obj);
|
2014-07-25 07:14:40 +08:00
|
|
|
else
|
2015-03-15 09:30:58 +08:00
|
|
|
reportError(File, cxxdump_error::unrecognized_file_format);
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[]) {
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
llvm_shutdown_obj Y;
|
|
|
|
|
|
|
|
// Initialize targets.
|
|
|
|
llvm::InitializeAllTargetInfos();
|
|
|
|
|
|
|
|
// Register the target printer for --version.
|
|
|
|
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
|
|
|
|
|
2015-03-15 09:30:58 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv, "LLVM C++ ABI Data Dumper\n");
|
2014-07-25 07:14:40 +08:00
|
|
|
|
|
|
|
// Default to stdin if no filename is specified.
|
|
|
|
if (opts::InputFilenames.size() == 0)
|
|
|
|
opts::InputFilenames.push_back("-");
|
|
|
|
|
|
|
|
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
|
|
|
|
dumpInput);
|
|
|
|
|
2015-07-17 14:18:36 +08:00
|
|
|
return EXIT_SUCCESS;
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|