summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-09 14:49:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-09 14:49:08 +0000
commitf6cfc15705140cc958b784a1bc98f7f0f09be6be (patch)
tree9481eebb2dc98f8adf2c67e452fd1ac8815e0513 /tools
parent32a3e78304a94ea214aee5fe82b10dd110e8863a (diff)
downloadllvm-f6cfc15705140cc958b784a1bc98f7f0f09be6be.tar.gz
llvm-f6cfc15705140cc958b784a1bc98f7f0f09be6be.tar.bz2
llvm-f6cfc15705140cc958b784a1bc98f7f0f09be6be.tar.xz
Convert MachOObjectFile to a template.
For now it is templated only on being 64 or 32 bits. I will add little/big endian next. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179097 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-objdump/MachODump.cpp8
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp4
-rw-r--r--tools/llvm-readobj/MachODumper.cpp28
-rw-r--r--tools/llvm-symbolizer/LLVMSymbolize.cpp2
4 files changed, 22 insertions, 20 deletions
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index 7c6565832e..b0a1aca26f 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -52,7 +52,7 @@ static cl::opt<bool>
static cl::opt<std::string>
DSYMFile("dsym", cl::desc("Use .dSYM file for debug info"));
-static const Target *GetTarget(const MachOObjectFile *MachOObj) {
+static const Target *GetTarget(const MachOObjectFileBase *MachOObj) {
// Figure out the target triple.
if (TripleName.empty()) {
llvm::Triple TT("unknown-unknown-unknown");
@@ -108,7 +108,7 @@ struct SymbolSorter {
// Print additional information about an address, if available.
static void DumpAddress(uint64_t Address, ArrayRef<SectionRef> Sections,
- const MachOObjectFile *MachOObj, raw_ostream &OS) {
+ const MachOObjectFileBase *MachOObj, raw_ostream &OS) {
for (unsigned i = 0; i != Sections.size(); ++i) {
uint64_t SectAddr = 0, SectSize = 0;
Sections[i].getAddress(SectAddr);
@@ -200,7 +200,7 @@ static void emitDOTFile(const char *FileName, const MCFunction &f,
}
static void getSectionsAndSymbols(const MachOFormat::Header *Header,
- MachOObjectFile *MachOObj,
+ MachOObjectFileBase *MachOObj,
std::vector<SectionRef> &Sections,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns) {
@@ -238,7 +238,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) {
return;
}
- OwningPtr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile*>(
+ OwningPtr<MachOObjectFileBase> MachOOF(static_cast<MachOObjectFileBase*>(
ObjectFile::createMachOObjectFile(Buff.take())));
const Target *TheTarget = GetTarget(MachOOF.get());
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 9a36e8253d..4790d7a5fe 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -255,7 +255,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
StringRef SegmentName = "";
- if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
+ if (const MachOObjectFileBase *MachO = dyn_cast<const MachOObjectFileBase>(Obj)) {
DataRefImpl DR = i->getRawDataRefImpl();
SegmentName = MachO->getSectionFinalSegmentName(DR);
}
@@ -591,7 +591,7 @@ static void PrintSymbolTable(const ObjectFile *o) {
else if (Section == o->end_sections())
outs() << "*UND*";
else {
- if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(o)) {
+ if (const MachOObjectFileBase *MachO = dyn_cast<const MachOObjectFileBase>(o)) {
DataRefImpl DR = Section->getRawDataRefImpl();
StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ",";
diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp
index 89402808bf..3dad4d6e54 100644
--- a/tools/llvm-readobj/MachODumper.cpp
+++ b/tools/llvm-readobj/MachODumper.cpp
@@ -27,7 +27,7 @@ namespace {
class MachODumper : public ObjDumper {
public:
- MachODumper(const llvm::object::MachOObjectFile *Obj, StreamWriter& Writer)
+ MachODumper(const llvm::object::MachOObjectFileBase *Obj, StreamWriter& Writer)
: ObjDumper(Writer)
, Obj(Obj) { }
@@ -43,7 +43,7 @@ private:
void printRelocation(section_iterator SecI, relocation_iterator RelI);
- const llvm::object::MachOObjectFile *Obj;
+ const llvm::object::MachOObjectFileBase *Obj;
};
} // namespace
@@ -54,7 +54,7 @@ namespace llvm {
error_code createMachODumper(const object::ObjectFile *Obj,
StreamWriter& Writer,
OwningPtr<ObjDumper> &Result) {
- const MachOObjectFile *MachOObj = dyn_cast<MachOObjectFile>(Obj);
+ const MachOObjectFileBase *MachOObj = dyn_cast<MachOObjectFileBase>(Obj);
if (!MachOObj)
return readobj_error::unsupported_obj_file_format;
@@ -157,11 +157,11 @@ namespace {
};
}
-static void getSection(const MachOObjectFile *Obj,
+static void getSection(const MachOObjectFileBase *Obj,
DataRefImpl DRI,
MachOSection &Section) {
- if (Obj->is64Bit()) {
- const MachOFormat::Section<true> *Sect = Obj->getSection64(DRI);
+ if (const MachOObjectFile<true> *O = dyn_cast<MachOObjectFile<true> >(Obj)) {
+ const MachOObjectFile<true>::Section *Sect = O->getSection(DRI);
Section.Address = Sect->Address;
Section.Size = Sect->Size;
@@ -173,7 +173,8 @@ static void getSection(const MachOObjectFile *Obj,
Section.Reserved1 = Sect->Reserved1;
Section.Reserved2 = Sect->Reserved2;
} else {
- const MachOFormat::Section<false> *Sect = Obj->getSection(DRI);
+ const MachOObjectFile<false> *O2 = cast<MachOObjectFile<false> >(Obj);
+ const MachOObjectFile<false>::Section *Sect = O2->getSection(DRI);
Section.Address = Sect->Address;
Section.Size = Sect->Size;
@@ -187,20 +188,21 @@ static void getSection(const MachOObjectFile *Obj,
}
}
-static void getSymbol(const MachOObjectFile *Obj,
+static void getSymbol(const MachOObjectFileBase *Obj,
DataRefImpl DRI,
MachOSymbol &Symbol) {
- if (Obj->is64Bit()) {
- const MachOFormat::SymbolTableEntry<true> *Entry =
- Obj->getSymbol64TableEntry(DRI);
+ if (const MachOObjectFile<true> *O = dyn_cast<MachOObjectFile<true> >(Obj)) {
+ const MachOObjectFile<true>::SymbolTableEntry *Entry =
+ O->getSymbolTableEntry(DRI);
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;
Symbol.Flags = Entry->Flags;
Symbol.Value = Entry->Value;
} else {
- const MachOFormat::SymbolTableEntry<false> *Entry =
- Obj->getSymbolTableEntry(DRI);
+ const MachOObjectFile<false> *O2 = cast<MachOObjectFile<false> >(Obj);
+ const MachOObjectFile<false>::SymbolTableEntry *Entry =
+ O2->getSymbolTableEntry(DRI);
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;
diff --git a/tools/llvm-symbolizer/LLVMSymbolize.cpp b/tools/llvm-symbolizer/LLVMSymbolize.cpp
index 29d91a0e92..ffe8712a65 100644
--- a/tools/llvm-symbolizer/LLVMSymbolize.cpp
+++ b/tools/llvm-symbolizer/LLVMSymbolize.cpp
@@ -233,7 +233,7 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
// On Darwin we may find DWARF in separate object file in
// resource directory.
ObjectFile *DbgObj = Obj;
- if (isa<MachOObjectFile>(Obj)) {
+ if (isa<MachOObjectFileBase>(Obj)) {
const std::string &ResourceName =
getDarwinDWARFResourceForModule(ModuleName);
ObjectFile *ResourceObj = getObjectFile(ResourceName);