forked from OSchip/llvm-project
Add all 4 MachO object types. Use the stored type to implement is64Bits().
llvm-svn: 179021
This commit is contained in:
parent
5f11dd390a
commit
d66c414619
|
|
@ -41,11 +41,17 @@ protected:
|
||||||
// Object and children.
|
// Object and children.
|
||||||
ID_StartObjects,
|
ID_StartObjects,
|
||||||
ID_COFF,
|
ID_COFF,
|
||||||
|
|
||||||
ID_ELF32L, // ELF 32-bit, little endian
|
ID_ELF32L, // ELF 32-bit, little endian
|
||||||
ID_ELF32B, // ELF 32-bit, big endian
|
ID_ELF32B, // ELF 32-bit, big endian
|
||||||
ID_ELF64L, // ELF 64-bit, little endian
|
ID_ELF64L, // ELF 64-bit, little endian
|
||||||
ID_ELF64B, // ELF 64-bit, big endian
|
ID_ELF64B, // ELF 64-bit, big endian
|
||||||
ID_MachO,
|
|
||||||
|
ID_MachO32L, // MachO 32-bit, little endian
|
||||||
|
ID_MachO32B, // MachO 32-bit, big endian
|
||||||
|
ID_MachO64L, // MachO 64-bit, little endian
|
||||||
|
ID_MachO64B, // MachO 64-bit, big endian
|
||||||
|
|
||||||
ID_EndObjects
|
ID_EndObjects
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -56,6 +62,13 @@ protected:
|
||||||
return is64Bits ? ID_ELF64B : ID_ELF32B;
|
return is64Bits ? ID_ELF64B : ID_ELF32B;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int getMachOType(bool isLE, bool is64Bits) {
|
||||||
|
if (isLE)
|
||||||
|
return is64Bits ? ID_MachO64L : ID_MachO32L;
|
||||||
|
else
|
||||||
|
return is64Bits ? ID_MachO64B : ID_MachO32B;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Binary();
|
virtual ~Binary();
|
||||||
|
|
||||||
|
|
@ -79,7 +92,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMachO() const {
|
bool isMachO() const {
|
||||||
return TypeID == ID_MachO;
|
return TypeID >= ID_MachO32L && TypeID <= ID_MachO64B;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isCOFF() const {
|
bool isCOFF() const {
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ namespace MachOFormat {
|
||||||
|
|
||||||
class MachOObjectFile : public ObjectFile {
|
class MachOObjectFile : public ObjectFile {
|
||||||
public:
|
public:
|
||||||
MachOObjectFile(MemoryBuffer *Object, error_code &ec);
|
MachOObjectFile(MemoryBuffer *Object, bool Is64bits, error_code &ec);
|
||||||
|
|
||||||
virtual symbol_iterator begin_symbols() const;
|
virtual symbol_iterator begin_symbols() const;
|
||||||
virtual symbol_iterator end_symbols() const;
|
virtual symbol_iterator end_symbols() const;
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,9 @@ using namespace object;
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace object {
|
namespace object {
|
||||||
|
|
||||||
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, error_code &ec)
|
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool Is64bits,
|
||||||
: ObjectFile(Binary::ID_MachO, Object) {
|
error_code &ec)
|
||||||
|
: ObjectFile(getMachOType(true, Is64bits), Object) {
|
||||||
DataRefImpl DRI;
|
DataRefImpl DRI;
|
||||||
moveToNextSection(DRI);
|
moveToNextSection(DRI);
|
||||||
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
uint32_t LoadCommandCount = getHeader()->NumLoadCommands;
|
||||||
|
|
@ -41,8 +42,8 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, error_code &ec)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MachOObjectFile::is64Bit() const {
|
bool MachOObjectFile::is64Bit() const {
|
||||||
StringRef Magic = getData(0, 4);
|
unsigned int Type = getType();
|
||||||
return (Magic == "\xFE\xED\xFA\xCF") || (Magic == "\xCF\xFA\xED\xFE");
|
return Type == ID_MachO64L || Type == ID_MachO64B;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MachOFormat::LoadCommand *
|
const MachOFormat::LoadCommand *
|
||||||
|
|
@ -88,8 +89,10 @@ StringRef MachOObjectFile::getData(size_t Offset, size_t Size) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
|
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
|
||||||
|
StringRef Magic = Buffer->getBuffer().slice(0, 4);
|
||||||
error_code ec;
|
error_code ec;
|
||||||
ObjectFile *Ret = new MachOObjectFile(Buffer, ec);
|
bool Is64Bits = Magic == "\xFE\xED\xFA\xCF" || Magic == "\xCF\xFA\xED\xFE";
|
||||||
|
ObjectFile *Ret = new MachOObjectFile(Buffer, Is64Bits, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
return NULL;
|
return NULL;
|
||||||
return Ret;
|
return Ret;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue