aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-objdump
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-18 18:08:55 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-18 18:08:55 +0000
commitfd7aa38e304a09fa0ef51b85b773b649b7e58c5e (patch)
treeb60cff57cb597e0d649f4d382bd8274cf7a90bd8 /tools/llvm-objdump
parent77327fd652e184c413744eabec8d9fdd605d09c1 (diff)
downloadexternal_llvm-fd7aa38e304a09fa0ef51b85b773b649b7e58c5e.zip
external_llvm-fd7aa38e304a09fa0ef51b85b773b649b7e58c5e.tar.gz
external_llvm-fd7aa38e304a09fa0ef51b85b773b649b7e58c5e.tar.bz2
At Jim Grosbach's request detemplate Object/MachO.h.
We are still able to handle mixed endian objects by swapping one struct at a time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-objdump')
-rw-r--r--tools/llvm-objdump/MachODump.cpp43
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp20
2 files changed, 23 insertions, 40 deletions
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index 4b6cb5f..e4d9ce2 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -53,7 +53,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 MachOObjectFileBase *MachOObj) {
+static const Target *GetTarget(const MachOObjectFile *MachOObj) {
// Figure out the target triple.
if (TripleName.empty()) {
llvm::Triple TT("unknown-unknown-unknown");
@@ -93,7 +93,7 @@ struct SymbolSorter {
// Print additional information about an address, if available.
static void DumpAddress(uint64_t Address, ArrayRef<SectionRef> Sections,
- const MachOObjectFileBase *MachOObj, raw_ostream &OS) {
+ const MachOObjectFile *MachOObj, raw_ostream &OS) {
for (unsigned i = 0; i != Sections.size(); ++i) {
uint64_t SectAddr = 0, SectSize = 0;
Sections[i].getAddress(SectAddr);
@@ -184,14 +184,12 @@ static void emitDOTFile(const char *FileName, const MCFunction &f,
Out << "}\n";
}
-template<endianness E>
static void
-getSectionsAndSymbols(const typename MachOObjectFileMiddle<E>::Header *Header,
- const MachOObjectFileMiddle<E> *MachOObj,
+getSectionsAndSymbols(const macho::Header Header,
+ MachOObjectFile *MachOObj,
std::vector<SectionRef> &Sections,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns) {
- typedef MachOObjectFileMiddle<E> ObjType;
error_code ec;
for (symbol_iterator SI = MachOObj->begin_symbols(),
SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
@@ -205,23 +203,23 @@ getSectionsAndSymbols(const typename MachOObjectFileMiddle<E>::Header *Header,
Sections.push_back(*SI);
}
- for (unsigned i = 0; i != Header->NumLoadCommands; ++i) {
- const typename ObjType::LoadCommand *Command =
- MachOObj->getLoadCommandInfo(i);
- if (Command->Type == macho::LCT_FunctionStarts) {
+ MachOObjectFile::LoadCommandInfo Command =
+ MachOObj->getFirstLoadCommandInfo();
+ for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
+ if (Command.C.Type == macho::LCT_FunctionStarts) {
// We found a function starts segment, parse the addresses for later
// consumption.
- const typename ObjType::LinkeditDataLoadCommand *LLC =
- reinterpret_cast<const typename ObjType::LinkeditDataLoadCommand*>(Command);
+ macho::LinkeditDataLoadCommand LLC =
+ MachOObj->getLinkeditDataLoadCommand(Command);
- MachOObj->ReadULEB128s(LLC->DataOffset, FoundFns);
+ MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
}
+ Command = MachOObj->getNextLoadCommandInfo(Command);
}
}
-template<endianness E>
static void DisassembleInputMachO2(StringRef Filename,
- MachOObjectFileMiddle<E> *MachOOF);
+ MachOObjectFile *MachOOF);
void llvm::DisassembleInputMachO(StringRef Filename) {
OwningPtr<MemoryBuffer> Buff;
@@ -231,20 +229,14 @@ void llvm::DisassembleInputMachO(StringRef Filename) {
return;
}
- OwningPtr<MachOObjectFileBase> MachOOF(static_cast<MachOObjectFileBase*>(
+ OwningPtr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile*>(
ObjectFile::createMachOObjectFile(Buff.take())));
- if (MachOObjectFileLE *O = dyn_cast<MachOObjectFileLE>(MachOOF.get())) {
- DisassembleInputMachO2(Filename, O);
- return;
- }
- MachOObjectFileBE *O = cast<MachOObjectFileBE>(MachOOF.get());
- DisassembleInputMachO2(Filename, O);
+ DisassembleInputMachO2(Filename, MachOOF.get());
}
-template<endianness E>
static void DisassembleInputMachO2(StringRef Filename,
- MachOObjectFileMiddle<E> *MachOOF) {
+ MachOObjectFile *MachOOF) {
const Target *TheTarget = GetTarget(MachOOF);
if (!TheTarget) {
// GetTarget prints out stuff.
@@ -273,8 +265,7 @@ static void DisassembleInputMachO2(StringRef Filename,
outs() << '\n' << Filename << ":\n\n";
- const typename MachOObjectFileMiddle<E>::Header *Header =
- MachOOF->getHeader();
+ macho::Header Header = MachOOF->getHeader();
std::vector<SectionRef> Sections;
std::vector<SymbolRef> Symbols;
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 6f4b101..9985599 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -191,14 +191,6 @@ bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
return a_addr < b_addr;
}
-StringRef
-getSectionFinalSegmentName(const MachOObjectFileBase *MachO, DataRefImpl DR) {
- if (const MachOObjectFileLE *O = dyn_cast<MachOObjectFileLE>(MachO))
- return O->getSectionFinalSegmentName(DR);
- const MachOObjectFileBE *O = dyn_cast<MachOObjectFileBE>(MachO);
- return O->getSectionFinalSegmentName(DR);
-}
-
static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
const Target *TheTarget = getTarget(Obj);
// getTarget() will have already issued a diagnostic if necessary, so
@@ -263,10 +255,10 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
StringRef SegmentName = "";
- if (const MachOObjectFileBase *MachO =
- dyn_cast<const MachOObjectFileBase>(Obj)) {
+ if (const MachOObjectFile *MachO =
+ dyn_cast<const MachOObjectFile>(Obj)) {
DataRefImpl DR = i->getRawDataRefImpl();
- SegmentName = getSectionFinalSegmentName(MachO, DR);
+ SegmentName = MachO->getSectionFinalSegmentName(DR);
}
StringRef name;
if (error(i->getName(name))) break;
@@ -608,10 +600,10 @@ static void PrintSymbolTable(const ObjectFile *o) {
else if (Section == o->end_sections())
outs() << "*UND*";
else {
- if (const MachOObjectFileBase *MachO =
- dyn_cast<const MachOObjectFileBase>(o)) {
+ if (const MachOObjectFile *MachO =
+ dyn_cast<const MachOObjectFile>(o)) {
DataRefImpl DR = Section->getRawDataRefImpl();
- StringRef SegmentName = getSectionFinalSegmentName(MachO, DR);
+ StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ",";
}
StringRef SectionName;