//===- MachOObjectFile.cpp - Mach-O object file binding ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the MachOObjectFile class, which binds the MachOObject
// class to the generic ObjectFile wrapper.
//
//===----------------------------------------------------------------------===//
#include "llvm/Object/MachO.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Object/MachOFormat.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cctype>
#include <cstring>
#include <limits>
using namespace llvm;
using namespace object;
namespace llvm {
namespace object {
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool Is64bits,
error_code &ec)
: ObjectFile(getMachOType(true, Is64bits), Object) {
DataRefImpl DRI;
moveToNextSection(DRI);
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
while (DRI.d.a < LoadCommandCount) {
Sections.push_back(DRI);
DRI.d.b++;
moveToNextSection(DRI);
}
}
bool MachOObjectFile::is64Bit() const {
unsigned int Type = getType();
return Type == ID_MachO64L || Type == ID_MachO64B;
}
const MachOFormat::LoadCommand *
MachOObjectFile::getLoadCommandInfo(unsigned Index) const {
uint64_t Offset;
uint64_t NewOffset = getHeaderSize();
const MachOFormat::LoadCommand *Load;
unsigned I = 0;
do {
Offset = NewOffset;
StringRef Data = getData(Offset, sizeof(MachOFormat::LoadCommand));
Load = reinterpret_cast<const MachOFormat::LoadCommand*>(Data.data());
NewOffset = Offset + Load->Size;
++I;
} while (I != Index + 1);
return Load;
}
void MachOObjectFile::ReadULEB128s(uint64_t Index,