#ifndef LLVM_SUPPORT_MACHO_H
#define LLVM_SUPPORT_MACHO_H
#include "llvm/Support/DataTypes.h"
namespace llvm {
namespace MachO {
enum {
HeaderMagic32 = 0xFEEDFACEu, HeaderMagic32Swapped = 0xCEFAEDFEu, HeaderMagic64 = 0xFEEDFACFu, HeaderMagic64Swapped = 0xCFFAEDFEu, UniversalMagic = 0xCAFEBABEu, UniversalMagicSwapped = 0xBEBAFECAu,
HeaderFileTypeObject = 0x1u, HeaderFileTypeExecutable = 0x2u, HeaderFileTypeFixedVMShlib = 0x3u, HeaderFileTypeCore = 0x4u, HeaderFileTypePreloadedExecutable = 0x5u, HeaderFileTypeDynamicShlib = 0x6u, HeaderFileTypeDynamicLinkEditor = 0x7u, HeaderFileTypeBundle = 0x8u, HeaderFileTypeDynamicShlibStub = 0x9u, HeaderFileTypeDSYM = 0xAu, HeaderFileTypeKextBundle = 0xBu,
HeaderFlagBitNoUndefinedSymbols = 0x00000001u, HeaderFlagBitIsIncrementalLinkObject= 0x00000002u, HeaderFlagBitIsDynamicLinkObject = 0x00000004u, HeaderFlagBitBindAtLoad = 0x00000008u, HeaderFlagBitPrebound = 0x00000010u, HeaderFlagBitSplitSegments = 0x00000020u, HeaderFlagBitLazyInit = 0x00000040u, HeaderFlagBitTwoLevelNamespace = 0x00000080u, HeaderFlagBitForceFlatNamespace = 0x00000100u, HeaderFlagBitNoMultipleDefintions = 0x00000200u, HeaderFlagBitNoFixPrebinding = 0x00000400u, HeaderFlagBitPrebindable = 0x00000800u, HeaderFlagBitAllModulesBound = 0x00001000u, HeaderFlagBitSubsectionsViaSymbols = 0x00002000u, HeaderFlagBitCanonical = 0x00004000u, HeaderFlagBitWeakDefines = 0x00008000u, HeaderFlagBitBindsToWeak = 0x00010000u, HeaderFlagBitAllowStackExecution = 0x00020000u, HeaderFlagBitRootSafe = 0x00040000u, HeaderFlagBitSetUIDSafe = 0x00080000u, HeaderFlagBitNoReexportedDylibs = 0x00100000u, HeaderFlagBitPIE = 0x00200000u, HeaderFlagBitDeadStrippableDylib = 0x00400000u,
LoadCommandDynamicLinkerRequired = 0x80000000u, LoadCommandSegment32 = 0x00000001u, LoadCommandSymtab = 0x00000002u, LoadCommandSymSeg = 0x00000003u, LoadCommandThread = 0x00000004u, LoadCommandUnixThread = 0x00000005u, LoadCommandFixedVMShlibLoad = 0x00000006u, LoadCommandFixedVMShlibIdent = 0x00000007u, LoadCommandIdent = 0x00000008u, LoadCommandFixedVMFileInclusion = 0x00000009u, LoadCommandPrePage = 0x0000000Au, LoadCommandDynamicSymtabInfo = 0x0000000Bu, LoadCommandDylibLoad = 0x0000000Cu, LoadCommandDylibIdent = 0x0000000Du, LoadCommandDynamicLinkerLoad = 0x0000000Eu, LoadCommandDynamicLinkerIdent = 0x0000000Fu, LoadCommandDylibPrebound = 0x00000010u, LoadCommandRoutines32 = 0x00000011u, LoadCommandSubFramework = 0x00000012u, LoadCommandSubUmbrella = 0x00000013u, LoadCommandSubClient = 0x00000014u, LoadCommandSubLibrary = 0x00000015u, LoadCommandTwoLevelHints = 0x00000016u, LoadCommandPreBindChecksum = 0x00000017u, LoadCommandDylibLoadWeak = 0x80000018u, LoadCommandSegment64 = 0x00000019u, LoadCommandRoutines64 = 0x0000001Au, LoadCommandUUID = 0x0000001Bu, LoadCommandRunpath = 0x8000001Cu, LoadCommandCodeSignature = 0x0000001Du, LoadCommandSegmentSplitInfo = 0x0000001Eu, LoadCommandDylibReexport = 0x8000001Fu, LoadCommandDylibLazyLoad = 0x00000020u, LoadCommandEncryptionInfo = 0x00000021u, LoadCommandDynamicLinkerInfo = 0x00000022u, LoadCommandDynamicLinkerInfoOnly = 0x80000022u, LoadCommandDylibLoadUpward = 0x80000023u, LoadCommandVersionMinMacOSX = 0x00000024u, LoadCommandVersionMinIPhoneOS = 0x00000025u, LoadCommandFunctionStarts = 0x00000026u, LoadCommandDyldEnvironment = 0x00000027u, LoadCommandMain = 0x80000028u, LoadCommandDataInCode = 0x00000029u, LoadCommandSourceVersion = 0x0000002Au, LoadCommandCodeSignDRs = 0x0000002Bu,
SegmentCommandFlagBitHighVM = 0x1u, SegmentCommandFlagBitFixedVMLibrary = 0x2u, SegmentCommandFlagBitNoRelocations = 0x4u, SegmentCommandFlagBitProtectedVersion1 = 0x8u,
SectionFlagMaskSectionType = 0x000000ffu, SectionFlagMaskAllAttributes = 0xffffff00u, SectionFlagMaskUserAttributes = 0xff000000u, SectionFlagMaskSystemAttributes = 0x00ffff00u,
SectionTypeRegular = 0x00u, SectionTypeZeroFill = 0x01u, SectionTypeCStringLiterals = 0x02u, SectionType4ByteLiterals = 0x03u, SectionType8ByteLiterals = 0x04u, SectionTypeLiteralPointers = 0x05u, SectionTypeNonLazySymbolPointers = 0x06u, SectionTypeLazySymbolPointers = 0x07u, SectionTypeSymbolStubs = 0x08u, SectionTypeModuleInitFunctionPointers = 0x09u, SectionTypeModuleTermFunctionPointers = 0x0au, SectionTypeCoalesced = 0x0bu, SectionTypeZeroFillLarge = 0x0cu, SectionTypeInterposing = 0x0du, SectionType16ByteLiterals = 0x0eu, SectionTypeDTraceObjectFormat = 0x0fu, SectionTypeLazyDylibSymbolPointers = 0x10u,
SectionAttrUserPureInstructions = 0x80000000u, SectionAttrUserNoTableOfContents = 0x40000000u, SectionAttrUserCanStripStaticSymbols = 0x20000000u, SectionAttrUserNoDeadStrip = 0x10000000u, SectionAttrUserLiveSupport = 0x08000000u, SectionAttrUserSelfModifyingCode = 0x04000000u, SectionAttrUserDebug = 0x02000000u,
SectionAttrSytemSomeInstructions = 0x00000400u, SectionAttrSytemHasExternalRelocations= 0x00000200u, SectionAttrSytemHasLocalRelocations = 0x00000100u,
IndirectSymbolLocal = 0x80000000u, IndirectSymbolAbsolute = 0x40000000u,
RebaseTypePointer = 1u, RebaseTypeTextAbsolute32 = 2u, RebaseTypeTextPCRelative32 = 3u,
RebaseOpcodeMask = 0xF0u, RebaseImmediateMask = 0x0Fu, RebaseOpcodeDone = 0x00u, RebaseOpcodeSetTypeImmediate = 0x10u, RebaseOpcodeSetSegmentAndOffsetULEB = 0x20u, RebaseOpcodeAddAddressULEB = 0x30u, RebaseOpcodeAddAddressImmediateScaled = 0x40u, RebaseOpcodeDoRebaseImmediateTimes = 0x50u, RebaseOpcodeDoRebaseULEBTimes = 0x60u, RebaseOpcodeDoRebaseAddAddressULEB = 0x70u, RebaseOpcodeDoRebaseULEBTimesSkippingULEB = 0x80u,
BindTypePointer = 1u, BindTypeTextAbsolute32 = 2u, BindTypeTextPCRelative32 = 3u,
BindSpecialDylibSelf = 0u, BindSpecialDylibMainExecutable = -1u, BindSpecialDylibFlatLookup = -2u,
BindSymbolFlagsWeakImport = 0x1u, BindSymbolFlagsNonWeakDefinition = 0x8u,
BindOpcodeMask = 0xF0u, BindImmediateMask = 0x0Fu, BindOpcodeDone = 0x00u, BindOpcodeSetDylibOrdinalImmediate = 0x10u, BindOpcodeSetDylibOrdinalULEB = 0x20u, BindOpcodeSetDylibSpecialImmediate = 0x30u, BindOpcodeSetSymbolTrailingFlagsImmediate = 0x40u, BindOpcodeSetTypeImmediate = 0x50u, BindOpcodeSetAppendSLEB = 0x60u, BindOpcodeSetSegmentAndOffsetULEB = 0x70u, BindOpcodeAddAddressULEB = 0x80u, BindOpcodeDoBind = 0x90u, BindOpcodeDoBindAddAddressULEB = 0xA0u, BindOpcodeDoBindAddAddressImmediateScaled = 0xB0u, BindOpcodeDoBindULEBTimesSkippingULEB = 0xC0u,
ExportSymbolFlagsKindMask = 0x03u, ExportSymbolFlagsKindRegular = 0x00u, ExportSymbolFlagsKindThreadLocal = 0x01u, ExportSymbolFlagsWeakDefinition = 0x04u, ExportSymbolFlagsIndirectDefinition = 0x08u, ExportSymbolFlagsHasSpecializations = 0x10u,
NlistMaskStab = 0xe0, NlistMaskPrivateExternal = 0x10, NlistMaskType = 0x0e, NlistMaskExternal = 0x01,
NListTypeUndefined = 0x0u, NListTypeAbsolute = 0x2u, NListTypeSection = 0xeu, NListTypePreboundUndefined = 0xcu, NListTypeIndirect = 0xau,
NListSectionNoSection = 0u, NListSectionMaxSection = 0xffu,
NListDescWeakRef = 0x40u,
NListDescWeakDef = 0x80u,
StabGlobalSymbol = 0x20u, StabFunctionName = 0x22u, StabFunction = 0x24u, StabStaticSymbol = 0x26u, StabLocalCommon = 0x28u, StabBeginSymbol = 0x2Eu, StabSourceFileOptions = 0x3Cu, StabRegisterSymbol = 0x40u, StabSourceLine = 0x44u, StabEndSymbol = 0x4Eu, StabStructureType = 0x60u, StabSourceFileName = 0x64u, StabObjectFileName = 0x66u, StabLocalSymbol = 0x80u, StabBeginIncludeFileName = 0x82u, StabIncludeFileName = 0x84u, StabCompilerParameters = 0x86u, StabCompilerVersion = 0x88u, StabCompilerOptLevel = 0x8Au, StabParameter = 0xA0u, StabEndIncludeFile = 0xA2u, StabAlternateEntry = 0xA4u, StabLeftBracket = 0xC0u, StabDeletedIncludeFile = 0xC2u, StabRightBracket = 0xE0u, StabBeginCommon = 0xE2u, StabEndCommon = 0xE4u, StabEndCommonLocal = 0xE8u, StabLength = 0xFEu
};
struct mach_header {
uint32_t magic;
uint32_t cputype;
uint32_t cpusubtype;
uint32_t filetype;
uint32_t ncmds;
uint32_t sizeofcmds;
uint32_t flags;
};
struct mach_header_64 {
uint32_t magic;
uint32_t cputype;
uint32_t cpusubtype;
uint32_t filetype;
uint32_t ncmds;
uint32_t sizeofcmds;
uint32_t flags;
uint32_t reserved;
};
struct load_command {
uint32_t cmd;
uint32_t cmdsize;
};
struct segment_command {
uint32_t cmd;
uint32_t cmdsize;
char segname[16];
uint32_t vmaddr;
uint32_t vmsize;
uint32_t fileoff;
uint32_t filesize;
uint32_t maxprot;
uint32_t initprot;
uint32_t nsects;
uint32_t flags;
};
struct segment_command_64 {
uint32_t cmd;
uint32_t cmdsize;
char segname[16];
uint64_t vmaddr;
uint64_t vmsize;
uint64_t fileoff;
uint64_t filesize;
uint32_t maxprot;
uint32_t initprot;
uint32_t nsects;
uint32_t flags;
};
struct section {
char sectname[16];
char segname[16];
uint32_t addr;
uint32_t size;
uint32_t offset;
uint32_t align;
uint32_t reloff;
uint32_t nreloc;
uint32_t flags;
uint32_t reserved1;
uint32_t reserved2;
};
struct section_64 {
char sectname[16];
char segname[16];
uint64_t addr;
uint64_t size;
uint32_t offset;
uint32_t align;
uint32_t reloff;
uint32_t nreloc;
uint32_t flags;
uint32_t reserved1;
uint32_t reserved2;
uint32_t reserved3;
};
struct fvmlib {
uint32_t name;
uint32_t minor_version;
uint32_t header_addr;
};
struct fvmlib_command {
uint32_t cmd;
uint32_t cmdsize;
struct fvmlib fvmlib;
};
struct dylib {
uint32_t name;
uint32_t timestamp;
uint32_t current_version;
uint32_t compatibility_version;
};
struct dylib_command {
uint32_t cmd;
uint32_t cmdsize;
struct dylib dylib;
};
struct sub_framework_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t umbrella;
};
struct sub_client_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t client;
};
struct sub_umbrella_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t sub_umbrella;
};
struct sub_library_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t sub_library;
};
struct prebound_dylib_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t name;
uint32_t nmodules;
uint32_t linked_modules;
};
struct dylinker_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t name;
};
struct thread_command {
uint32_t cmd;
uint32_t cmdsize;
};
struct routines_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t init_address;
uint32_t init_module;
uint32_t reserved1;
uint32_t reserved2;
uint32_t reserved3;
uint32_t reserved4;
uint32_t reserved5;
uint32_t reserved6;
};
struct routines_command_64 {
uint32_t cmd;
uint32_t cmdsize;
uint64_t init_address;
uint64_t init_module;
uint64_t reserved1;
uint64_t reserved2;
uint64_t reserved3;
uint64_t reserved4;
uint64_t reserved5;
uint64_t reserved6;
};
struct symtab_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t symoff;
uint32_t nsyms;
uint32_t stroff;
uint32_t strsize;
};
struct dysymtab_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t ilocalsym;
uint32_t nlocalsym;
uint32_t iextdefsym;
uint32_t nextdefsym;
uint32_t iundefsym;
uint32_t nundefsym;
uint32_t tocoff;
uint32_t ntoc;
uint32_t modtaboff;
uint32_t nmodtab;
uint32_t extrefsymoff;
uint32_t nextrefsyms;
uint32_t indirectsymoff;
uint32_t nindirectsyms;
uint32_t extreloff;
uint32_t nextrel;
uint32_t locreloff;
uint32_t nlocrel;
};
struct dylib_table_of_contents {
uint32_t symbol_index;
uint32_t module_index;
};
struct dylib_module {
uint32_t module_name;
uint32_t iextdefsym;
uint32_t nextdefsym;
uint32_t irefsym;
uint32_t nrefsym;
uint32_t ilocalsym;
uint32_t nlocalsym;
uint32_t iextrel;
uint32_t nextrel;
uint32_t iinit_iterm;
uint32_t ninit_nterm;
uint32_t objc_module_info_addr;
uint32_t objc_module_info_size;
};
struct dylib_module_64 {
uint32_t module_name;
uint32_t iextdefsym;
uint32_t nextdefsym;
uint32_t irefsym;
uint32_t nrefsym;
uint32_t ilocalsym;
uint32_t nlocalsym;
uint32_t iextrel;
uint32_t nextrel;
uint32_t iinit_iterm;
uint32_t ninit_nterm;
uint32_t objc_module_info_size;
uint64_t objc_module_info_addr;
};
struct dylib_reference {
uint32_t isym:24,
flags:8;
};
struct twolevel_hints_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t offset;
uint32_t nhints;
};
struct twolevel_hint {
uint32_t isub_image:8,
itoc:24;
};
struct prebind_cksum_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t cksum;
};
struct uuid_command {
uint32_t cmd;
uint32_t cmdsize;
uint8_t uuid[16];
};
struct rpath_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t path;
};
struct linkedit_data_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t dataoff;
uint32_t datasize;
};
struct encryption_info_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t cryptoff;
uint32_t cryptsize;
uint32_t cryptid;
};
struct version_min_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t version;
uint32_t reserved;
};
struct dyld_info_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t rebase_off;
uint32_t rebase_size;
uint32_t bind_off;
uint32_t bind_size;
uint32_t weak_bind_off;
uint32_t weak_bind_size;
uint32_t lazy_bind_off;
uint32_t lazy_bind_size;
uint32_t export_off;
uint32_t export_size;
};
struct symseg_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t offset;
uint32_t size;
};
struct ident_command {
uint32_t cmd;
uint32_t cmdsize;
};
struct fvmfile_command {
uint32_t cmd;
uint32_t cmdsize;
uint32_t name;
uint32_t header_addr;
};
struct fat_header {
uint32_t magic;
uint32_t nfat_arch;
};
struct fat_arch {
uint32_t cputype;
uint32_t cpusubtype;
uint32_t offset;
uint32_t size;
uint32_t align;
};
struct nlist {
uint32_t n_strx;
uint8_t n_type;
uint8_t n_sect;
int16_t n_desc;
uint32_t n_value;
};
struct nlist_64 {
uint32_t n_strx;
uint8_t n_type;
uint8_t n_sect;
uint16_t n_desc;
uint64_t n_value;
};
static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
{
return (((n_desc) >> 8u) & 0xffu);
}
static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal)
{
n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8));
}
static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc)
{
return (n_desc >> 8u) & 0x0fu;
}
static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align)
{
n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
}
enum {
CPUArchMask = 0xff000000, CPUArchABI64 = 0x01000000,
CPUTypeI386 = 7,
CPUTypeX86_64 = CPUTypeI386 | CPUArchABI64,
CPUTypeARM = 12,
CPUTypeSPARC = 14,
CPUTypePowerPC = 18,
CPUTypePowerPC64 = CPUTypePowerPC | CPUArchABI64,
CPUSubType_I386_ALL = 3,
CPUSubType_X86_64_ALL = 3,
CPUSubType_ARM_ALL = 0,
CPUSubType_ARM_V4T = 5,
CPUSubType_ARM_V5 = 7,
CPUSubType_ARM_V6 = 6,
CPUSubType_ARM_V7 = 9,
CPUSubType_POWERPC_ALL = 0,
CPUSubType_SPARC_ALL = 0
};
} }
#endif