1 //===-- llvm/Support/MachO.h - The MachO file format ------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines manifest constants for the MachO object file format. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_SUPPORT_MACHO_H 15 #define LLVM_SUPPORT_MACHO_H 16 17 #include "llvm/Support/DataTypes.h" 18 19 // NOTE: The enums in this file are intentially named to be different than those 20 // in the headers in /usr/include/mach (on darwin systems) to avoid conflicts 21 // with those macros. 22 namespace llvm { 23 namespace MachO { 24 // Enums from <mach-o/loader.h> 25 enum { 26 // Constants for the "magic" field in llvm::MachO::mach_header and 27 // llvm::MachO::mach_header_64 28 HeaderMagic32 = 0xFEEDFACEu, // MH_MAGIC 29 HeaderMagic32Swapped = 0xCEFAEDFEu, // MH_CIGAM 30 HeaderMagic64 = 0xFEEDFACFu, // MH_MAGIC_64 31 HeaderMagic64Swapped = 0xCFFAEDFEu, // MH_CIGAM_64 32 UniversalMagic = 0xCAFEBABEu, // FAT_MAGIC 33 UniversalMagicSwapped = 0xBEBAFECAu, // FAT_CIGAM 34 35 // Constants for the "filetype" field in llvm::MachO::mach_header and 36 // llvm::MachO::mach_header_64 37 HeaderFileTypeObject = 0x1u, // MH_OBJECT 38 HeaderFileTypeExecutable = 0x2u, // MH_EXECUTE 39 HeaderFileTypeFixedVMShlib = 0x3u, // MH_FVMLIB 40 HeaderFileTypeCore = 0x4u, // MH_CORE 41 HeaderFileTypePreloadedExecutable = 0x5u, // MH_PRELOAD 42 HeaderFileTypeDynamicShlib = 0x6u, // MH_DYLIB 43 HeaderFileTypeDynamicLinkEditor = 0x7u, // MH_DYLINKER 44 HeaderFileTypeBundle = 0x8u, // MH_BUNDLE 45 HeaderFileTypeDynamicShlibStub = 0x9u, // MH_DYLIB_STUB 46 HeaderFileTypeDSYM = 0xAu, // MH_DSYM 47 HeaderFileTypeKextBundle = 0xBu, // MH_KEXT_BUNDLE 48 49 // Constant bits for the "flags" field in llvm::MachO::mach_header and 50 // llvm::MachO::mach_header_64 51 HeaderFlagBitNoUndefinedSymbols = 0x00000001u, // MH_NOUNDEFS 52 HeaderFlagBitIsIncrementalLinkObject= 0x00000002u, // MH_INCRLINK 53 HeaderFlagBitIsDynamicLinkObject = 0x00000004u, // MH_DYLDLINK 54 HeaderFlagBitBindAtLoad = 0x00000008u, // MH_BINDATLOAD 55 HeaderFlagBitPrebound = 0x00000010u, // MH_PREBOUND 56 HeaderFlagBitSplitSegments = 0x00000020u, // MH_SPLIT_SEGS 57 HeaderFlagBitLazyInit = 0x00000040u, // MH_LAZY_INIT 58 HeaderFlagBitTwoLevelNamespace = 0x00000080u, // MH_TWOLEVEL 59 HeaderFlagBitForceFlatNamespace = 0x00000100u, // MH_FORCE_FLAT 60 HeaderFlagBitNoMultipleDefintions = 0x00000200u, // MH_NOMULTIDEFS 61 HeaderFlagBitNoFixPrebinding = 0x00000400u, // MH_NOFIXPREBINDING 62 HeaderFlagBitPrebindable = 0x00000800u, // MH_PREBINDABLE 63 HeaderFlagBitAllModulesBound = 0x00001000u, // MH_ALLMODSBOUND 64 HeaderFlagBitSubsectionsViaSymbols = 0x00002000u, // MH_SUBSECTIONS_VIA_SYMBOLS 65 HeaderFlagBitCanonical = 0x00004000u, // MH_CANONICAL 66 HeaderFlagBitWeakDefines = 0x00008000u, // MH_WEAK_DEFINES 67 HeaderFlagBitBindsToWeak = 0x00010000u, // MH_BINDS_TO_WEAK 68 HeaderFlagBitAllowStackExecution = 0x00020000u, // MH_ALLOW_STACK_EXECUTION 69 HeaderFlagBitRootSafe = 0x00040000u, // MH_ROOT_SAFE 70 HeaderFlagBitSetUIDSafe = 0x00080000u, // MH_SETUID_SAFE 71 HeaderFlagBitNoReexportedDylibs = 0x00100000u, // MH_NO_REEXPORTED_DYLIBS 72 HeaderFlagBitPIE = 0x00200000u, // MH_PIE 73 HeaderFlagBitDeadStrippableDylib = 0x00400000u, // MH_DEAD_STRIPPABLE_DYLIB 74 75 // Constants for the "cmd" field in llvm::MachO::load_command 76 LoadCommandDynamicLinkerRequired = 0x80000000u, // LC_REQ_DYLD 77 LoadCommandSegment32 = 0x00000001u, // LC_SEGMENT 78 LoadCommandSymtab = 0x00000002u, // LC_SYMTAB 79 LoadCommandSymSeg = 0x00000003u, // LC_SYMSEG 80 LoadCommandThread = 0x00000004u, // LC_THREAD 81 LoadCommandUnixThread = 0x00000005u, // LC_UNIXTHREAD 82 LoadCommandFixedVMShlibLoad = 0x00000006u, // LC_LOADFVMLIB 83 LoadCommandFixedVMShlibIdent = 0x00000007u, // LC_IDFVMLIB 84 LoadCommandIdent = 0x00000008u, // LC_IDENT 85 LoadCommandFixedVMFileInclusion = 0x00000009u, // LC_FVMFILE 86 LoadCommandPrePage = 0x0000000Au, // LC_PREPAGE 87 LoadCommandDynamicSymtabInfo = 0x0000000Bu, // LC_DYSYMTAB 88 LoadCommandDylibLoad = 0x0000000Cu, // LC_LOAD_DYLIB 89 LoadCommandDylibIdent = 0x0000000Du, // LC_ID_DYLIB 90 LoadCommandDynamicLinkerLoad = 0x0000000Eu, // LC_LOAD_DYLINKER 91 LoadCommandDynamicLinkerIdent = 0x0000000Fu, // LC_ID_DYLINKER 92 LoadCommandDylibPrebound = 0x00000010u, // LC_PREBOUND_DYLIB 93 LoadCommandRoutines32 = 0x00000011u, // LC_ROUTINES 94 LoadCommandSubFramework = 0x00000012u, // LC_SUB_FRAMEWORK 95 LoadCommandSubUmbrella = 0x00000013u, // LC_SUB_UMBRELLA 96 LoadCommandSubClient = 0x00000014u, // LC_SUB_CLIENT 97 LoadCommandSubLibrary = 0x00000015u, // LC_SUB_LIBRARY 98 LoadCommandTwoLevelHints = 0x00000016u, // LC_TWOLEVEL_HINTS 99 LoadCommandPreBindChecksum = 0x00000017u, // LC_PREBIND_CKSUM 100 LoadCommandDylibLoadWeak = 0x80000018u, // LC_LOAD_WEAK_DYLIB 101 LoadCommandSegment64 = 0x00000019u, // LC_SEGMENT_64 102 LoadCommandRoutines64 = 0x0000001Au, // LC_ROUTINES_64 103 LoadCommandUUID = 0x0000001Bu, // LC_UUID 104 LoadCommandRunpath = 0x8000001Cu, // LC_RPATH 105 LoadCommandCodeSignature = 0x0000001Du, // LC_CODE_SIGNATURE 106 LoadCommandSegmentSplitInfo = 0x0000001Eu, // LC_SEGMENT_SPLIT_INFO 107 LoadCommandDylibReexport = 0x8000001Fu, // LC_REEXPORT_DYLIB 108 LoadCommandDylibLazyLoad = 0x00000020u, // LC_LAZY_LOAD_DYLIB 109 LoadCommandEncryptionInfo = 0x00000021u, // LC_ENCRYPTION_INFO 110 LoadCommandDynamicLinkerInfo = 0x00000022u, // LC_DYLD_INFO 111 LoadCommandDynamicLinkerInfoOnly = 0x80000022u, // LC_DYLD_INFO_ONLY 112 LoadCommandDylibLoadUpward = 0x80000023u, // LC_LOAD_UPWARD_DYLIB 113 LoadCommandVersionMinMacOSX = 0x00000024u, // LC_VERSION_MIN_MACOSX 114 LoadCommandVersionMinIPhoneOS = 0x00000025u, // LC_VERSION_MIN_IPHONEOS 115 LoadCommandFunctionStarts = 0x00000026u, // LC_FUNCTION_STARTS 116 LoadCommandDyldEnvironment = 0x00000027u, // LC_DYLD_ENVIRONMENT 117 118 // Constant bits for the "flags" field in llvm::MachO::segment_command 119 SegmentCommandFlagBitHighVM = 0x1u, // SG_HIGHVM 120 SegmentCommandFlagBitFixedVMLibrary = 0x2u, // SG_FVMLIB 121 SegmentCommandFlagBitNoRelocations = 0x4u, // SG_NORELOC 122 SegmentCommandFlagBitProtectedVersion1 = 0x8u, // SG_PROTECTED_VERSION_1 123 124 125 // Constant masks for the "flags" field in llvm::MachO::section and 126 // llvm::MachO::section_64 127 SectionFlagMaskSectionType = 0x000000ffu, // SECTION_TYPE 128 SectionFlagMaskAllAttributes = 0xffffff00u, // SECTION_ATTRIBUTES 129 SectionFlagMaskUserAttributes = 0xff000000u, // SECTION_ATTRIBUTES_USR 130 SectionFlagMaskSystemAttributes = 0x00ffff00u, // SECTION_ATTRIBUTES_SYS 131 132 // Constant masks for the "flags[7:0]" field in llvm::MachO::section and 133 // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE) 134 SectionTypeRegular = 0x00u, // S_REGULAR 135 SectionTypeZeroFill = 0x01u, // S_ZEROFILL 136 SectionTypeCStringLiterals = 0x02u, // S_CSTRING_LITERALS 137 SectionType4ByteLiterals = 0x03u, // S_4BYTE_LITERALS 138 SectionType8ByteLiterals = 0x04u, // S_8BYTE_LITERALS 139 SectionTypeLiteralPointers = 0x05u, // S_LITERAL_POINTERS 140 SectionTypeNonLazySymbolPointers = 0x06u, // S_NON_LAZY_SYMBOL_POINTERS 141 SectionTypeLazySymbolPointers = 0x07u, // S_LAZY_SYMBOL_POINTERS 142 SectionTypeSymbolStubs = 0x08u, // S_SYMBOL_STUBS 143 SectionTypeModuleInitFunctionPointers = 0x09u, // S_MOD_INIT_FUNC_POINTERS 144 SectionTypeModuleTermFunctionPointers = 0x0au, // S_MOD_TERM_FUNC_POINTERS 145 SectionTypeCoalesced = 0x0bu, // S_COALESCED 146 SectionTypeZeroFillLarge = 0x0cu, // S_GB_ZEROFILL 147 SectionTypeInterposing = 0x0du, // S_INTERPOSING 148 SectionType16ByteLiterals = 0x0eu, // S_16BYTE_LITERALS 149 SectionTypeDTraceObjectFormat = 0x0fu, // S_DTRACE_DOF 150 SectionTypeLazyDylibSymbolPointers = 0x10u, // S_LAZY_DYLIB_SYMBOL_POINTERS 151 152 // Constant masks for the "flags[31:24]" field in llvm::MachO::section and 153 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR) 154 SectionAttrUserPureInstructions = 0x80000000u, // S_ATTR_PURE_INSTRUCTIONS 155 SectionAttrUserNoTableOfContents = 0x40000000u, // S_ATTR_NO_TOC 156 SectionAttrUserCanStripStaticSymbols = 0x20000000u, // S_ATTR_STRIP_STATIC_SYMS 157 SectionAttrUserNoDeadStrip = 0x10000000u, // S_ATTR_NO_DEAD_STRIP 158 SectionAttrUserLiveSupport = 0x08000000u, // S_ATTR_LIVE_SUPPORT 159 SectionAttrUserSelfModifyingCode = 0x04000000u, // S_ATTR_SELF_MODIFYING_CODE 160 SectionAttrUserDebug = 0x02000000u, // S_ATTR_DEBUG 161 162 // Constant masks for the "flags[23:8]" field in llvm::MachO::section and 163 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS) 164 SectionAttrSytemSomeInstructions = 0x00000400u, // S_ATTR_SOME_INSTRUCTIONS 165 SectionAttrSytemHasExternalRelocations= 0x00000200u, // S_ATTR_EXT_RELOC 166 SectionAttrSytemHasLocalRelocations = 0x00000100u, // S_ATTR_LOC_RELOC 167 168 IndirectSymbolLocal = 0x80000000u, // INDIRECT_SYMBOL_LOCAL 169 IndirectSymbolAbsolute = 0x40000000u, // INDIRECT_SYMBOL_ABS 170 171 RebaseTypePointer = 1u, // REBASE_TYPE_POINTER 172 RebaseTypeTextAbsolute32 = 2u, // REBASE_TYPE_TEXT_ABSOLUTE32 173 RebaseTypeTextPCRelative32 = 3u, // REBASE_TYPE_TEXT_PCREL32 174 175 RebaseOpcodeMask = 0xF0u, // REBASE_OPCODE_MASK 176 RebaseImmediateMask = 0x0Fu, // REBASE_IMMEDIATE_MASK 177 RebaseOpcodeDone = 0x00u, // REBASE_OPCODE_DONE 178 RebaseOpcodeSetTypeImmediate = 0x10u, // REBASE_OPCODE_SET_TYPE_IMM 179 RebaseOpcodeSetSegmentAndOffsetULEB = 0x20u, // REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 180 RebaseOpcodeAddAddressULEB = 0x30u, // REBASE_OPCODE_ADD_ADDR_ULEB 181 RebaseOpcodeAddAddressImmediateScaled = 0x40u, // REBASE_OPCODE_ADD_ADDR_IMM_SCALED 182 RebaseOpcodeDoRebaseImmediateTimes = 0x50u, // REBASE_OPCODE_DO_REBASE_IMM_TIMES 183 RebaseOpcodeDoRebaseULEBTimes = 0x60u, // REBASE_OPCODE_DO_REBASE_ULEB_TIMES 184 RebaseOpcodeDoRebaseAddAddressULEB = 0x70u, // REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 185 RebaseOpcodeDoRebaseULEBTimesSkippingULEB = 0x80u, // REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 186 187 188 BindTypePointer = 1u, // BIND_TYPE_POINTER 189 BindTypeTextAbsolute32 = 2u, // BIND_TYPE_TEXT_ABSOLUTE32 190 BindTypeTextPCRelative32 = 3u, // BIND_TYPE_TEXT_PCREL32 191 192 BindSpecialDylibSelf = 0u, // BIND_SPECIAL_DYLIB_SELF 193 BindSpecialDylibMainExecutable = -1u, // BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE 194 BindSpecialDylibFlatLookup = -2u, // BIND_SPECIAL_DYLIB_FLAT_LOOKUP 195 196 BindSymbolFlagsWeakImport = 0x1u, // BIND_SYMBOL_FLAGS_WEAK_IMPORT 197 BindSymbolFlagsNonWeakDefinition = 0x8u, // BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 198 199 BindOpcodeMask = 0xF0u, // BIND_OPCODE_MASK 200 BindImmediateMask = 0x0Fu, // BIND_IMMEDIATE_MASK 201 BindOpcodeDone = 0x00u, // BIND_OPCODE_DONE 202 BindOpcodeSetDylibOrdinalImmediate = 0x10u, // BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 203 BindOpcodeSetDylibOrdinalULEB = 0x20u, // BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 204 BindOpcodeSetDylibSpecialImmediate = 0x30u, // BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 205 BindOpcodeSetSymbolTrailingFlagsImmediate = 0x40u, // BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 206 BindOpcodeSetTypeImmediate = 0x50u, // BIND_OPCODE_SET_TYPE_IMM 207 BindOpcodeSetAppendSLEB = 0x60u, // BIND_OPCODE_SET_ADDEND_SLEB 208 BindOpcodeSetSegmentAndOffsetULEB = 0x70u, // BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 209 BindOpcodeAddAddressULEB = 0x80u, // BIND_OPCODE_ADD_ADDR_ULEB 210 BindOpcodeDoBind = 0x90u, // BIND_OPCODE_DO_BIND 211 BindOpcodeDoBindAddAddressULEB = 0xA0u, // BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 212 BindOpcodeDoBindAddAddressImmediateScaled = 0xB0u, // BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 213 BindOpcodeDoBindULEBTimesSkippingULEB = 0xC0u, // BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 214 215 ExportSymbolFlagsKindMask = 0x03u, // EXPORT_SYMBOL_FLAGS_KIND_MASK 216 ExportSymbolFlagsKindRegular = 0x00u, // EXPORT_SYMBOL_FLAGS_KIND_REGULAR 217 ExportSymbolFlagsKindThreadLocal = 0x01u, // EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 218 ExportSymbolFlagsWeakDefinition = 0x04u, // EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 219 ExportSymbolFlagsIndirectDefinition = 0x08u, // EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 220 ExportSymbolFlagsHasSpecializations = 0x10u, // EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 221 222 223 // Constant masks for the "n_type" field in llvm::MachO::nlist and 224 // llvm::MachO::nlist_64 225 NlistMaskStab = 0xe0, // N_STAB 226 NlistMaskPrivateExternal = 0x10, // N_PEXT 227 NlistMaskType = 0x0e, // N_TYPE 228 NlistMaskExternal = 0x01, // N_EXT 229 230 // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and 231 // llvm::MachO::nlist_64 232 NListTypeUndefined = 0x0u, // N_UNDF 233 NListTypeAbsolute = 0x2u, // N_ABS 234 NListTypeSection = 0xeu, // N_SECT 235 NListTypePreboundUndefined = 0xcu, // N_PBUD 236 NListTypeIndirect = 0xau, // N_INDR 237 238 // Constant masks for the "n_sect" field in llvm::MachO::nlist and 239 // llvm::MachO::nlist_64 240 NListSectionNoSection = 0u, // NO_SECT 241 NListSectionMaxSection = 0xffu, // MAX_SECT 242 243 NListDescWeakRef = 0x40u, 244 NListDescWeakDef = 0x80u, 245 246 // Constant values for the "n_type" field in llvm::MachO::nlist and 247 // llvm::MachO::nlist_64 when "(n_type & NlistMaskStab) != 0" 248 StabGlobalSymbol = 0x20u, // N_GSYM 249 StabFunctionName = 0x22u, // N_FNAME 250 StabFunction = 0x24u, // N_FUN 251 StabStaticSymbol = 0x26u, // N_STSYM 252 StabLocalCommon = 0x28u, // N_LCSYM 253 StabBeginSymbol = 0x2Eu, // N_BNSYM 254 StabSourceFileOptions = 0x3Cu, // N_OPT 255 StabRegisterSymbol = 0x40u, // N_RSYM 256 StabSourceLine = 0x44u, // N_SLINE 257 StabEndSymbol = 0x4Eu, // N_ENSYM 258 StabStructureType = 0x60u, // N_SSYM 259 StabSourceFileName = 0x64u, // N_SO 260 StabObjectFileName = 0x66u, // N_OSO 261 StabLocalSymbol = 0x80u, // N_LSYM 262 StabBeginIncludeFileName = 0x82u, // N_BINCL 263 StabIncludeFileName = 0x84u, // N_SOL 264 StabCompilerParameters = 0x86u, // N_PARAMS 265 StabCompilerVersion = 0x88u, // N_VERSION 266 StabCompilerOptLevel = 0x8Au, // N_OLEVEL 267 StabParameter = 0xA0u, // N_PSYM 268 StabEndIncludeFile = 0xA2u, // N_EINCL 269 StabAlternateEntry = 0xA4u, // N_ENTRY 270 StabLeftBracket = 0xC0u, // N_LBRAC 271 StabDeletedIncludeFile = 0xC2u, // N_EXCL 272 StabRightBracket = 0xE0u, // N_RBRAC 273 StabBeginCommon = 0xE2u, // N_BCOMM 274 StabEndCommon = 0xE4u, // N_ECOMM 275 StabEndCommonLocal = 0xE8u, // N_ECOML 276 StabLength = 0xFEu // N_LENG 277 278 }; 279 280 // Structs from <mach-o/loader.h> 281 282 struct mach_header { 283 uint32_t magic; 284 uint32_t cputype; 285 uint32_t cpusubtype; 286 uint32_t filetype; 287 uint32_t ncmds; 288 uint32_t sizeofcmds; 289 uint32_t flags; 290 }; 291 292 struct mach_header_64 { 293 uint32_t magic; 294 uint32_t cputype; 295 uint32_t cpusubtype; 296 uint32_t filetype; 297 uint32_t ncmds; 298 uint32_t sizeofcmds; 299 uint32_t flags; 300 uint32_t reserved; 301 }; 302 303 struct load_command { 304 uint32_t cmd; 305 uint32_t cmdsize; 306 }; 307 308 struct segment_command { 309 uint32_t cmd; 310 uint32_t cmdsize; 311 char segname[16]; 312 uint32_t vmaddr; 313 uint32_t vmsize; 314 uint32_t fileoff; 315 uint32_t filesize; 316 uint32_t maxprot; 317 uint32_t initprot; 318 uint32_t nsects; 319 uint32_t flags; 320 }; 321 322 struct segment_command_64 { 323 uint32_t cmd; 324 uint32_t cmdsize; 325 char segname[16]; 326 uint64_t vmaddr; 327 uint64_t vmsize; 328 uint64_t fileoff; 329 uint64_t filesize; 330 uint32_t maxprot; 331 uint32_t initprot; 332 uint32_t nsects; 333 uint32_t flags; 334 }; 335 336 struct section { 337 char sectname[16]; 338 char segname[16]; 339 uint32_t addr; 340 uint32_t size; 341 uint32_t offset; 342 uint32_t align; 343 uint32_t reloff; 344 uint32_t nreloc; 345 uint32_t flags; 346 uint32_t reserved1; 347 uint32_t reserved2; 348 }; 349 350 struct section_64 { 351 char sectname[16]; 352 char segname[16]; 353 uint64_t addr; 354 uint64_t size; 355 uint32_t offset; 356 uint32_t align; 357 uint32_t reloff; 358 uint32_t nreloc; 359 uint32_t flags; 360 uint32_t reserved1; 361 uint32_t reserved2; 362 uint32_t reserved3; 363 }; 364 365 struct fvmlib { 366 uint32_t name; 367 uint32_t minor_version; 368 uint32_t header_addr; 369 }; 370 371 struct fvmlib_command { 372 uint32_t cmd; 373 uint32_t cmdsize; 374 struct fvmlib fvmlib; 375 }; 376 377 struct dylib { 378 uint32_t name; 379 uint32_t timestamp; 380 uint32_t current_version; 381 uint32_t compatibility_version; 382 }; 383 384 struct dylib_command { 385 uint32_t cmd; 386 uint32_t cmdsize; 387 struct dylib dylib; 388 }; 389 390 struct sub_framework_command { 391 uint32_t cmd; 392 uint32_t cmdsize; 393 uint32_t umbrella; 394 }; 395 396 struct sub_client_command { 397 uint32_t cmd; 398 uint32_t cmdsize; 399 uint32_t client; 400 }; 401 402 struct sub_umbrella_command { 403 uint32_t cmd; 404 uint32_t cmdsize; 405 uint32_t sub_umbrella; 406 }; 407 408 struct sub_library_command { 409 uint32_t cmd; 410 uint32_t cmdsize; 411 uint32_t sub_library; 412 }; 413 414 struct prebound_dylib_command { 415 uint32_t cmd; 416 uint32_t cmdsize; 417 uint32_t name; 418 uint32_t nmodules; 419 uint32_t linked_modules; 420 }; 421 422 struct dylinker_command { 423 uint32_t cmd; 424 uint32_t cmdsize; 425 uint32_t name; 426 }; 427 428 struct thread_command { 429 uint32_t cmd; 430 uint32_t cmdsize; 431 }; 432 433 struct routines_command { 434 uint32_t cmd; 435 uint32_t cmdsize; 436 uint32_t init_address; 437 uint32_t init_module; 438 uint32_t reserved1; 439 uint32_t reserved2; 440 uint32_t reserved3; 441 uint32_t reserved4; 442 uint32_t reserved5; 443 uint32_t reserved6; 444 }; 445 446 struct routines_command_64 { 447 uint32_t cmd; 448 uint32_t cmdsize; 449 uint64_t init_address; 450 uint64_t init_module; 451 uint64_t reserved1; 452 uint64_t reserved2; 453 uint64_t reserved3; 454 uint64_t reserved4; 455 uint64_t reserved5; 456 uint64_t reserved6; 457 }; 458 459 struct symtab_command { 460 uint32_t cmd; 461 uint32_t cmdsize; 462 uint32_t symoff; 463 uint32_t nsyms; 464 uint32_t stroff; 465 uint32_t strsize; 466 }; 467 468 struct dysymtab_command { 469 uint32_t cmd; 470 uint32_t cmdsize; 471 uint32_t ilocalsym; 472 uint32_t nlocalsym; 473 uint32_t iextdefsym; 474 uint32_t nextdefsym; 475 uint32_t iundefsym; 476 uint32_t nundefsym; 477 uint32_t tocoff; 478 uint32_t ntoc; 479 uint32_t modtaboff; 480 uint32_t nmodtab; 481 uint32_t extrefsymoff; 482 uint32_t nextrefsyms; 483 uint32_t indirectsymoff; 484 uint32_t nindirectsyms; 485 uint32_t extreloff; 486 uint32_t nextrel; 487 uint32_t locreloff; 488 uint32_t nlocrel; 489 }; 490 491 struct dylib_table_of_contents { 492 uint32_t symbol_index; 493 uint32_t module_index; 494 }; 495 496 struct dylib_module { 497 uint32_t module_name; 498 uint32_t iextdefsym; 499 uint32_t nextdefsym; 500 uint32_t irefsym; 501 uint32_t nrefsym; 502 uint32_t ilocalsym; 503 uint32_t nlocalsym; 504 uint32_t iextrel; 505 uint32_t nextrel; 506 uint32_t iinit_iterm; 507 uint32_t ninit_nterm; 508 uint32_t objc_module_info_addr; 509 uint32_t objc_module_info_size; 510 }; 511 512 struct dylib_module_64 { 513 uint32_t module_name; 514 uint32_t iextdefsym; 515 uint32_t nextdefsym; 516 uint32_t irefsym; 517 uint32_t nrefsym; 518 uint32_t ilocalsym; 519 uint32_t nlocalsym; 520 uint32_t iextrel; 521 uint32_t nextrel; 522 uint32_t iinit_iterm; 523 uint32_t ninit_nterm; 524 uint32_t objc_module_info_size; 525 uint64_t objc_module_info_addr; 526 }; 527 528 struct dylib_reference { 529 uint32_t isym:24, 530 flags:8; 531 }; 532 533 534 struct twolevel_hints_command { 535 uint32_t cmd; 536 uint32_t cmdsize; 537 uint32_t offset; 538 uint32_t nhints; 539 }; 540 541 struct twolevel_hint { 542 uint32_t isub_image:8, 543 itoc:24; 544 }; 545 546 struct prebind_cksum_command { 547 uint32_t cmd; 548 uint32_t cmdsize; 549 uint32_t cksum; 550 }; 551 552 struct uuid_command { 553 uint32_t cmd; 554 uint32_t cmdsize; 555 uint8_t uuid[16]; 556 }; 557 558 struct rpath_command { 559 uint32_t cmd; 560 uint32_t cmdsize; 561 uint32_t path; 562 }; 563 564 struct linkedit_data_command { 565 uint32_t cmd; 566 uint32_t cmdsize; 567 uint32_t dataoff; 568 uint32_t datasize; 569 }; 570 571 struct encryption_info_command { 572 uint32_t cmd; 573 uint32_t cmdsize; 574 uint32_t cryptoff; 575 uint32_t cryptsize; 576 uint32_t cryptid; 577 }; 578 579 struct version_min_command { 580 uint32_t cmd; 581 uint32_t cmdsize; 582 uint32_t version; 583 uint32_t reserved; 584 }; 585 586 struct dyld_info_command { 587 uint32_t cmd; 588 uint32_t cmdsize; 589 uint32_t rebase_off; 590 uint32_t rebase_size; 591 uint32_t bind_off; 592 uint32_t bind_size; 593 uint32_t weak_bind_off; 594 uint32_t weak_bind_size; 595 uint32_t lazy_bind_off; 596 uint32_t lazy_bind_size; 597 uint32_t export_off; 598 uint32_t export_size; 599 }; 600 601 struct symseg_command { 602 uint32_t cmd; 603 uint32_t cmdsize; 604 uint32_t offset; 605 uint32_t size; 606 }; 607 608 struct ident_command { 609 uint32_t cmd; 610 uint32_t cmdsize; 611 }; 612 613 struct fvmfile_command { 614 uint32_t cmd; 615 uint32_t cmdsize; 616 uint32_t name; 617 uint32_t header_addr; 618 }; 619 620 621 // Structs from <mach-o/fat.h> 622 struct fat_header { 623 uint32_t magic; 624 uint32_t nfat_arch; 625 }; 626 627 struct fat_arch { 628 uint32_t cputype; 629 uint32_t cpusubtype; 630 uint32_t offset; 631 uint32_t size; 632 uint32_t align; 633 }; 634 635 // Structs from <mach-o/fat.h> 636 struct nlist { 637 uint32_t n_strx; 638 uint8_t n_type; 639 uint8_t n_sect; 640 int16_t n_desc; 641 uint32_t n_value; 642 }; 643 644 struct nlist_64 { 645 uint32_t n_strx; 646 uint8_t n_type; 647 uint8_t n_sect; 648 uint16_t n_desc; 649 uint64_t n_value; 650 }; 651 652 // Get/Set functions from <mach-o/nlist.h> 653 654 static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) 655 { 656 return (((n_desc) >> 8u) & 0xffu); 657 } 658 659 static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) 660 { 661 n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8)); 662 } 663 664 static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc) 665 { 666 return (n_desc >> 8u) & 0x0fu; 667 } 668 669 static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align) 670 { 671 n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u)); 672 } 673 674 // Enums from <mach/machine.h> 675 enum { 676 // Capability bits used in the definition of cpu_type. 677 CPUArchMask = 0xff000000, // Mask for architecture bits 678 CPUArchABI64 = 0x01000000, // 64 bit ABI 679 680 // Constants for the cputype field. 681 CPUTypeI386 = 7, 682 CPUTypeX86_64 = CPUTypeI386 | CPUArchABI64, 683 CPUTypeARM = 12, 684 CPUTypeSPARC = 14, 685 CPUTypePowerPC = 18, 686 CPUTypePowerPC64 = CPUTypePowerPC | CPUArchABI64, 687 688 689 // Constants for the cpusubtype field. 690 691 // X86 692 CPUSubType_I386_ALL = 3, 693 CPUSubType_X86_64_ALL = 3, 694 695 // ARM 696 CPUSubType_ARM_ALL = 0, 697 CPUSubType_ARM_V4T = 5, 698 CPUSubType_ARM_V5 = 7, 699 CPUSubType_ARM_V6 = 6, 700 CPUSubType_ARM_V7 = 9, 701 702 // PowerPC 703 CPUSubType_POWERPC_ALL = 0, 704 705 CPUSubType_SPARC_ALL = 0 706 }; 707 } // end namespace MachO 708 } // end namespace llvm 709 710 #endif 711