#ifndef LLVM_OBJECT_MACHOFORMAT_H
#define LLVM_OBJECT_MACHOFORMAT_H
#include "llvm/Support/DataTypes.h"
namespace llvm {
namespace object {
namespace mach {
enum CPUTypeFlagsMask {
CTFM_ArchMask = 0xFF000000,
CTFM_ArchABI64 = 0x01000000
};
enum CPUTypeMachine {
CTM_i386 = 7,
CTM_x86_64 = CTM_i386 | CTFM_ArchABI64,
CTM_ARM = 12,
CTM_SPARC = 14,
CTM_PowerPC = 18,
CTM_PowerPC64 = CTM_PowerPC | CTFM_ArchABI64
};
enum CPUSubtypeFlagsMask {
CSFM_SubtypeMask = 0xFF000000,
CSFM_SubtypeLib64 = 0x80000000
};
enum CPUSubtypeARM {
CSARM_ALL = 0,
CSARM_V4T = 5,
CSARM_V6 = 6,
CSARM_V5TEJ = 7,
CSARM_XSCALE = 8,
CSARM_V7 = 9,
CSARM_V7F = 10,
CSARM_V7S = 11,
CSARM_V7K = 12
};
enum CPUSubtypePowerPC {
CSPPC_ALL = 0
};
enum CPUSubtypeSPARC {
CSSPARC_ALL = 0
};
enum CPUSubtypeX86 {
CSX86_ALL = 3
};
}
namespace macho {
enum StructureSizes {
Header32Size = 28,
Header64Size = 32,
SegmentLoadCommand32Size = 56,
SegmentLoadCommand64Size = 72,
Section32Size = 68,
Section64Size = 80,
SymtabLoadCommandSize = 24,
DysymtabLoadCommandSize = 80,
Nlist32Size = 12,
Nlist64Size = 16,
RelocationInfoSize = 8,
LinkeditLoadCommandSize = 16
};
enum HeaderMagic {
HM_Object32 = 0xFEEDFACE, HM_Object64 = 0xFEEDFACF, HM_Universal = 0xCAFEBABE };
struct Header {
uint32_t Magic;
uint32_t CPUType;
uint32_t CPUSubtype;
uint32_t FileType;
uint32_t NumLoadCommands;
uint32_t SizeOfLoadCommands;
uint32_t Flags;
};
struct Header64Ext {
uint32_t Reserved;
};
enum HeaderFileType {
HFT_Object = 0x1
};
enum HeaderFlags {
HF_SubsectionsViaSymbols = 0x2000
};
enum LoadCommandType {
LCT_Segment = 0x1,
LCT_Symtab = 0x2,
LCT_Dysymtab = 0xb,
LCT_Segment64 = 0x19,
LCT_UUID = 0x1b,
LCT_CodeSignature = 0x1d,
LCT_SegmentSplitInfo = 0x1e,
LCT_FunctionStarts = 0x26,
LCT_DataInCode = 0x29
};
struct LoadCommand {
uint32_t Type;
uint32_t Size;
};
struct SegmentLoadCommand {
uint32_t Type;
uint32_t Size;
char Name[16];
uint32_t VMAddress;
uint32_t VMSize;
uint32_t FileOffset;
uint32_t FileSize;
uint32_t MaxVMProtection;
uint32_t InitialVMProtection;
uint32_t NumSections;
uint32_t Flags;
};
struct Segment64LoadCommand {
uint32_t Type;
uint32_t Size;
char Name[16];
uint64_t VMAddress;
uint64_t VMSize;
uint64_t FileOffset;
uint64_t FileSize;
uint32_t MaxVMProtection;
uint32_t InitialVMProtection;
uint32_t NumSections;
uint32_t Flags;
};
struct SymtabLoadCommand {
uint32_t Type;
uint32_t Size;
uint32_t SymbolTableOffset;
uint32_t NumSymbolTableEntries;
uint32_t StringTableOffset;
uint32_t StringTableSize;
};
struct DysymtabLoadCommand {
uint32_t Type;
uint32_t Size;
uint32_t LocalSymbolsIndex;
uint32_t NumLocalSymbols;
uint32_t ExternalSymbolsIndex;
uint32_t NumExternalSymbols;
uint32_t UndefinedSymbolsIndex;
uint32_t NumUndefinedSymbols;
uint32_t TOCOffset;
uint32_t NumTOCEntries;
uint32_t ModuleTableOffset;
uint32_t NumModuleTableEntries;
uint32_t ReferenceSymbolTableOffset;
uint32_t NumReferencedSymbolTableEntries;
uint32_t IndirectSymbolTableOffset;
uint32_t NumIndirectSymbolTableEntries;
uint32_t ExternalRelocationTableOffset;
uint32_t NumExternalRelocationTableEntries;
uint32_t LocalRelocationTableOffset;
uint32_t NumLocalRelocationTableEntries;
};
struct LinkeditDataLoadCommand {
uint32_t Type;
uint32_t Size;
uint32_t DataOffset;
uint32_t DataSize;
};
struct Section {
char Name[16];
char SegmentName[16];
uint32_t Address;
uint32_t Size;
uint32_t Offset;
uint32_t Align;
uint32_t RelocationTableOffset;
uint32_t NumRelocationTableEntries;
uint32_t Flags;
uint32_t Reserved1;
uint32_t Reserved2;
};
struct Section64 {
char Name[16];
char SegmentName[16];
uint64_t Address;
uint64_t Size;
uint32_t Offset;
uint32_t Align;
uint32_t RelocationTableOffset;
uint32_t NumRelocationTableEntries;
uint32_t Flags;
uint32_t Reserved1;
uint32_t Reserved2;
uint32_t Reserved3;
};
struct SymbolTableEntry {
uint32_t StringIndex;
uint8_t Type;
uint8_t SectionIndex;
uint16_t Flags;
uint32_t Value;
};
#pragma pack(push)
#pragma pack(4)
struct Symbol64TableEntry {
uint32_t StringIndex;
uint8_t Type;
uint8_t SectionIndex;
uint16_t Flags;
uint64_t Value;
};
#pragma pack(pop)
enum DataRegionType { Data = 1, JumpTable8, JumpTable16, JumpTable32 };
struct DataInCodeTableEntry {
uint32_t Offset;
uint16_t Length;
uint16_t Kind;
};
struct IndirectSymbolTableEntry {
uint32_t Index;
};
struct RelocationEntry {
uint32_t Word0;
uint32_t Word1;
};
enum SymbolTypeType {
STT_Undefined = 0x00,
STT_Absolute = 0x02,
STT_Section = 0x0e
};
enum SymbolTypeFlags {
STF_StabsEntryMask = 0xe0,
STF_TypeMask = 0x0e,
STF_External = 0x01,
STF_PrivateExtern = 0x10
};
enum IndirectSymbolFlags {
ISF_Local = 0x80000000,
ISF_Absolute = 0x40000000
};
enum RelocationFlags {
RF_Scattered = 0x80000000
};
enum RelocationInfoType {
RIT_Vanilla = 0,
RIT_Pair = 1,
RIT_Difference = 2
};
enum RelocationInfoType_Generic {
RIT_Generic_PreboundLazyPointer = 3,
RIT_Generic_LocalDifference = 4,
RIT_Generic_TLV = 5
};
enum RelocationInfoTypeX86_64 {
RIT_X86_64_Unsigned = 0,
RIT_X86_64_Signed = 1,
RIT_X86_64_Branch = 2,
RIT_X86_64_GOTLoad = 3,
RIT_X86_64_GOT = 4,
RIT_X86_64_Subtractor = 5,
RIT_X86_64_Signed1 = 6,
RIT_X86_64_Signed2 = 7,
RIT_X86_64_Signed4 = 8,
RIT_X86_64_TLV = 9
};
enum RelocationInfoTypeARM {
RIT_ARM_LocalDifference = 3,
RIT_ARM_PreboundLazyPointer = 4,
RIT_ARM_Branch24Bit = 5,
RIT_ARM_ThumbBranch22Bit = 6,
RIT_ARM_ThumbBranch32Bit = 7,
RIT_ARM_Half = 8,
RIT_ARM_HalfDifference = 9
};
}
} }
#endif