LLVM API Documentation
00001 //===-- llvm/Support/MachO.h - The MachO file format ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines manifest constants for the MachO object file format. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SUPPORT_MACHO_H 00015 #define LLVM_SUPPORT_MACHO_H 00016 00017 #include "llvm/Support/DataTypes.h" 00018 00019 // NOTE: The enums in this file are intentially named to be different than those 00020 // in the headers in /usr/include/mach (on darwin systems) to avoid conflicts 00021 // with those macros. 00022 namespace llvm { 00023 namespace MachO { 00024 // Enums from <mach-o/loader.h> 00025 enum { 00026 // Constants for the "magic" field in llvm::MachO::mach_header and 00027 // llvm::MachO::mach_header_64 00028 HeaderMagic32 = 0xFEEDFACEu, // MH_MAGIC 00029 HeaderMagic32Swapped = 0xCEFAEDFEu, // MH_CIGAM 00030 HeaderMagic64 = 0xFEEDFACFu, // MH_MAGIC_64 00031 HeaderMagic64Swapped = 0xCFFAEDFEu, // MH_CIGAM_64 00032 UniversalMagic = 0xCAFEBABEu, // FAT_MAGIC 00033 UniversalMagicSwapped = 0xBEBAFECAu, // FAT_CIGAM 00034 00035 // Constants for the "filetype" field in llvm::MachO::mach_header and 00036 // llvm::MachO::mach_header_64 00037 HeaderFileTypeObject = 0x1u, // MH_OBJECT 00038 HeaderFileTypeExecutable = 0x2u, // MH_EXECUTE 00039 HeaderFileTypeFixedVMShlib = 0x3u, // MH_FVMLIB 00040 HeaderFileTypeCore = 0x4u, // MH_CORE 00041 HeaderFileTypePreloadedExecutable = 0x5u, // MH_PRELOAD 00042 HeaderFileTypeDynamicShlib = 0x6u, // MH_DYLIB 00043 HeaderFileTypeDynamicLinkEditor = 0x7u, // MH_DYLINKER 00044 HeaderFileTypeBundle = 0x8u, // MH_BUNDLE 00045 HeaderFileTypeDynamicShlibStub = 0x9u, // MH_DYLIB_STUB 00046 HeaderFileTypeDSYM = 0xAu, // MH_DSYM 00047 HeaderFileTypeKextBundle = 0xBu, // MH_KEXT_BUNDLE 00048 00049 // Constant bits for the "flags" field in llvm::MachO::mach_header and 00050 // llvm::MachO::mach_header_64 00051 HeaderFlagBitNoUndefinedSymbols = 0x00000001u, // MH_NOUNDEFS 00052 HeaderFlagBitIsIncrementalLinkObject= 0x00000002u, // MH_INCRLINK 00053 HeaderFlagBitIsDynamicLinkObject = 0x00000004u, // MH_DYLDLINK 00054 HeaderFlagBitBindAtLoad = 0x00000008u, // MH_BINDATLOAD 00055 HeaderFlagBitPrebound = 0x00000010u, // MH_PREBOUND 00056 HeaderFlagBitSplitSegments = 0x00000020u, // MH_SPLIT_SEGS 00057 HeaderFlagBitLazyInit = 0x00000040u, // MH_LAZY_INIT 00058 HeaderFlagBitTwoLevelNamespace = 0x00000080u, // MH_TWOLEVEL 00059 HeaderFlagBitForceFlatNamespace = 0x00000100u, // MH_FORCE_FLAT 00060 HeaderFlagBitNoMultipleDefintions = 0x00000200u, // MH_NOMULTIDEFS 00061 HeaderFlagBitNoFixPrebinding = 0x00000400u, // MH_NOFIXPREBINDING 00062 HeaderFlagBitPrebindable = 0x00000800u, // MH_PREBINDABLE 00063 HeaderFlagBitAllModulesBound = 0x00001000u, // MH_ALLMODSBOUND 00064 HeaderFlagBitSubsectionsViaSymbols = 0x00002000u, // MH_SUBSECTIONS_VIA_SYMBOLS 00065 HeaderFlagBitCanonical = 0x00004000u, // MH_CANONICAL 00066 HeaderFlagBitWeakDefines = 0x00008000u, // MH_WEAK_DEFINES 00067 HeaderFlagBitBindsToWeak = 0x00010000u, // MH_BINDS_TO_WEAK 00068 HeaderFlagBitAllowStackExecution = 0x00020000u, // MH_ALLOW_STACK_EXECUTION 00069 HeaderFlagBitRootSafe = 0x00040000u, // MH_ROOT_SAFE 00070 HeaderFlagBitSetUIDSafe = 0x00080000u, // MH_SETUID_SAFE 00071 HeaderFlagBitNoReexportedDylibs = 0x00100000u, // MH_NO_REEXPORTED_DYLIBS 00072 HeaderFlagBitPIE = 0x00200000u, // MH_PIE 00073 HeaderFlagBitDeadStrippableDylib = 0x00400000u, // MH_DEAD_STRIPPABLE_DYLIB 00074 00075 // Constants for the "cmd" field in llvm::MachO::load_command 00076 LoadCommandDynamicLinkerRequired = 0x80000000u, // LC_REQ_DYLD 00077 LoadCommandSegment32 = 0x00000001u, // LC_SEGMENT 00078 LoadCommandSymtab = 0x00000002u, // LC_SYMTAB 00079 LoadCommandSymSeg = 0x00000003u, // LC_SYMSEG 00080 LoadCommandThread = 0x00000004u, // LC_THREAD 00081 LoadCommandUnixThread = 0x00000005u, // LC_UNIXTHREAD 00082 LoadCommandFixedVMShlibLoad = 0x00000006u, // LC_LOADFVMLIB 00083 LoadCommandFixedVMShlibIdent = 0x00000007u, // LC_IDFVMLIB 00084 LoadCommandIdent = 0x00000008u, // LC_IDENT 00085 LoadCommandFixedVMFileInclusion = 0x00000009u, // LC_FVMFILE 00086 LoadCommandPrePage = 0x0000000Au, // LC_PREPAGE 00087 LoadCommandDynamicSymtabInfo = 0x0000000Bu, // LC_DYSYMTAB 00088 LoadCommandDylibLoad = 0x0000000Cu, // LC_LOAD_DYLIB 00089 LoadCommandDylibIdent = 0x0000000Du, // LC_ID_DYLIB 00090 LoadCommandDynamicLinkerLoad = 0x0000000Eu, // LC_LOAD_DYLINKER 00091 LoadCommandDynamicLinkerIdent = 0x0000000Fu, // LC_ID_DYLINKER 00092 LoadCommandDylibPrebound = 0x00000010u, // LC_PREBOUND_DYLIB 00093 LoadCommandRoutines32 = 0x00000011u, // LC_ROUTINES 00094 LoadCommandSubFramework = 0x00000012u, // LC_SUB_FRAMEWORK 00095 LoadCommandSubUmbrella = 0x00000013u, // LC_SUB_UMBRELLA 00096 LoadCommandSubClient = 0x00000014u, // LC_SUB_CLIENT 00097 LoadCommandSubLibrary = 0x00000015u, // LC_SUB_LIBRARY 00098 LoadCommandTwoLevelHints = 0x00000016u, // LC_TWOLEVEL_HINTS 00099 LoadCommandPreBindChecksum = 0x00000017u, // LC_PREBIND_CKSUM 00100 LoadCommandDylibLoadWeak = 0x80000018u, // LC_LOAD_WEAK_DYLIB 00101 LoadCommandSegment64 = 0x00000019u, // LC_SEGMENT_64 00102 LoadCommandRoutines64 = 0x0000001Au, // LC_ROUTINES_64 00103 LoadCommandUUID = 0x0000001Bu, // LC_UUID 00104 LoadCommandRunpath = 0x8000001Cu, // LC_RPATH 00105 LoadCommandCodeSignature = 0x0000001Du, // LC_CODE_SIGNATURE 00106 LoadCommandSegmentSplitInfo = 0x0000001Eu, // LC_SEGMENT_SPLIT_INFO 00107 LoadCommandDylibReexport = 0x8000001Fu, // LC_REEXPORT_DYLIB 00108 LoadCommandDylibLazyLoad = 0x00000020u, // LC_LAZY_LOAD_DYLIB 00109 LoadCommandEncryptionInfo = 0x00000021u, // LC_ENCRYPTION_INFO 00110 LoadCommandDynamicLinkerInfo = 0x00000022u, // LC_DYLD_INFO 00111 LoadCommandDynamicLinkerInfoOnly = 0x80000022u, // LC_DYLD_INFO_ONLY 00112 LoadCommandDylibLoadUpward = 0x80000023u, // LC_LOAD_UPWARD_DYLIB 00113 LoadCommandVersionMinMacOSX = 0x00000024u, // LC_VERSION_MIN_MACOSX 00114 LoadCommandVersionMinIPhoneOS = 0x00000025u, // LC_VERSION_MIN_IPHONEOS 00115 LoadCommandFunctionStarts = 0x00000026u, // LC_FUNCTION_STARTS 00116 LoadCommandDyldEnvironment = 0x00000027u, // LC_DYLD_ENVIRONMENT 00117 LoadCommandMain = 0x80000028u, // LC_MAIN 00118 LoadCommandDataInCode = 0x00000029u, // LC_DATA_IN_CODE 00119 LoadCommandSourceVersion = 0x0000002Au, // LC_SOURCE_VERSION 00120 LoadCommandCodeSignDRs = 0x0000002Bu, // LC_DYLIB_CODE_SIGN_DRS 00121 00122 // Constant bits for the "flags" field in llvm::MachO::segment_command 00123 SegmentCommandFlagBitHighVM = 0x1u, // SG_HIGHVM 00124 SegmentCommandFlagBitFixedVMLibrary = 0x2u, // SG_FVMLIB 00125 SegmentCommandFlagBitNoRelocations = 0x4u, // SG_NORELOC 00126 SegmentCommandFlagBitProtectedVersion1 = 0x8u, // SG_PROTECTED_VERSION_1 00127 00128 00129 // Constant masks for the "flags" field in llvm::MachO::section and 00130 // llvm::MachO::section_64 00131 SectionFlagMaskSectionType = 0x000000ffu, // SECTION_TYPE 00132 SectionFlagMaskAllAttributes = 0xffffff00u, // SECTION_ATTRIBUTES 00133 SectionFlagMaskUserAttributes = 0xff000000u, // SECTION_ATTRIBUTES_USR 00134 SectionFlagMaskSystemAttributes = 0x00ffff00u, // SECTION_ATTRIBUTES_SYS 00135 00136 // Constant masks for the "flags[7:0]" field in llvm::MachO::section and 00137 // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE) 00138 SectionTypeRegular = 0x00u, // S_REGULAR 00139 SectionTypeZeroFill = 0x01u, // S_ZEROFILL 00140 SectionTypeCStringLiterals = 0x02u, // S_CSTRING_LITERALS 00141 SectionType4ByteLiterals = 0x03u, // S_4BYTE_LITERALS 00142 SectionType8ByteLiterals = 0x04u, // S_8BYTE_LITERALS 00143 SectionTypeLiteralPointers = 0x05u, // S_LITERAL_POINTERS 00144 SectionTypeNonLazySymbolPointers = 0x06u, // S_NON_LAZY_SYMBOL_POINTERS 00145 SectionTypeLazySymbolPointers = 0x07u, // S_LAZY_SYMBOL_POINTERS 00146 SectionTypeSymbolStubs = 0x08u, // S_SYMBOL_STUBS 00147 SectionTypeModuleInitFunctionPointers = 0x09u, // S_MOD_INIT_FUNC_POINTERS 00148 SectionTypeModuleTermFunctionPointers = 0x0au, // S_MOD_TERM_FUNC_POINTERS 00149 SectionTypeCoalesced = 0x0bu, // S_COALESCED 00150 SectionTypeZeroFillLarge = 0x0cu, // S_GB_ZEROFILL 00151 SectionTypeInterposing = 0x0du, // S_INTERPOSING 00152 SectionType16ByteLiterals = 0x0eu, // S_16BYTE_LITERALS 00153 SectionTypeDTraceObjectFormat = 0x0fu, // S_DTRACE_DOF 00154 SectionTypeLazyDylibSymbolPointers = 0x10u, // S_LAZY_DYLIB_SYMBOL_POINTERS 00155 00156 // Constant masks for the "flags[31:24]" field in llvm::MachO::section and 00157 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR) 00158 SectionAttrUserPureInstructions = 0x80000000u, // S_ATTR_PURE_INSTRUCTIONS 00159 SectionAttrUserNoTableOfContents = 0x40000000u, // S_ATTR_NO_TOC 00160 SectionAttrUserCanStripStaticSymbols = 0x20000000u, // S_ATTR_STRIP_STATIC_SYMS 00161 SectionAttrUserNoDeadStrip = 0x10000000u, // S_ATTR_NO_DEAD_STRIP 00162 SectionAttrUserLiveSupport = 0x08000000u, // S_ATTR_LIVE_SUPPORT 00163 SectionAttrUserSelfModifyingCode = 0x04000000u, // S_ATTR_SELF_MODIFYING_CODE 00164 SectionAttrUserDebug = 0x02000000u, // S_ATTR_DEBUG 00165 00166 // Constant masks for the "flags[23:8]" field in llvm::MachO::section and 00167 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS) 00168 SectionAttrSytemSomeInstructions = 0x00000400u, // S_ATTR_SOME_INSTRUCTIONS 00169 SectionAttrSytemHasExternalRelocations= 0x00000200u, // S_ATTR_EXT_RELOC 00170 SectionAttrSytemHasLocalRelocations = 0x00000100u, // S_ATTR_LOC_RELOC 00171 00172 IndirectSymbolLocal = 0x80000000u, // INDIRECT_SYMBOL_LOCAL 00173 IndirectSymbolAbsolute = 0x40000000u, // INDIRECT_SYMBOL_ABS 00174 00175 RebaseTypePointer = 1u, // REBASE_TYPE_POINTER 00176 RebaseTypeTextAbsolute32 = 2u, // REBASE_TYPE_TEXT_ABSOLUTE32 00177 RebaseTypeTextPCRelative32 = 3u, // REBASE_TYPE_TEXT_PCREL32 00178 00179 RebaseOpcodeMask = 0xF0u, // REBASE_OPCODE_MASK 00180 RebaseImmediateMask = 0x0Fu, // REBASE_IMMEDIATE_MASK 00181 RebaseOpcodeDone = 0x00u, // REBASE_OPCODE_DONE 00182 RebaseOpcodeSetTypeImmediate = 0x10u, // REBASE_OPCODE_SET_TYPE_IMM 00183 RebaseOpcodeSetSegmentAndOffsetULEB = 0x20u, // REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 00184 RebaseOpcodeAddAddressULEB = 0x30u, // REBASE_OPCODE_ADD_ADDR_ULEB 00185 RebaseOpcodeAddAddressImmediateScaled = 0x40u, // REBASE_OPCODE_ADD_ADDR_IMM_SCALED 00186 RebaseOpcodeDoRebaseImmediateTimes = 0x50u, // REBASE_OPCODE_DO_REBASE_IMM_TIMES 00187 RebaseOpcodeDoRebaseULEBTimes = 0x60u, // REBASE_OPCODE_DO_REBASE_ULEB_TIMES 00188 RebaseOpcodeDoRebaseAddAddressULEB = 0x70u, // REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 00189 RebaseOpcodeDoRebaseULEBTimesSkippingULEB = 0x80u, // REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 00190 00191 00192 BindTypePointer = 1u, // BIND_TYPE_POINTER 00193 BindTypeTextAbsolute32 = 2u, // BIND_TYPE_TEXT_ABSOLUTE32 00194 BindTypeTextPCRelative32 = 3u, // BIND_TYPE_TEXT_PCREL32 00195 00196 BindSpecialDylibSelf = 0u, // BIND_SPECIAL_DYLIB_SELF 00197 BindSpecialDylibMainExecutable = -1u, // BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE 00198 BindSpecialDylibFlatLookup = -2u, // BIND_SPECIAL_DYLIB_FLAT_LOOKUP 00199 00200 BindSymbolFlagsWeakImport = 0x1u, // BIND_SYMBOL_FLAGS_WEAK_IMPORT 00201 BindSymbolFlagsNonWeakDefinition = 0x8u, // BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 00202 00203 BindOpcodeMask = 0xF0u, // BIND_OPCODE_MASK 00204 BindImmediateMask = 0x0Fu, // BIND_IMMEDIATE_MASK 00205 BindOpcodeDone = 0x00u, // BIND_OPCODE_DONE 00206 BindOpcodeSetDylibOrdinalImmediate = 0x10u, // BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 00207 BindOpcodeSetDylibOrdinalULEB = 0x20u, // BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 00208 BindOpcodeSetDylibSpecialImmediate = 0x30u, // BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 00209 BindOpcodeSetSymbolTrailingFlagsImmediate = 0x40u, // BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 00210 BindOpcodeSetTypeImmediate = 0x50u, // BIND_OPCODE_SET_TYPE_IMM 00211 BindOpcodeSetAppendSLEB = 0x60u, // BIND_OPCODE_SET_ADDEND_SLEB 00212 BindOpcodeSetSegmentAndOffsetULEB = 0x70u, // BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 00213 BindOpcodeAddAddressULEB = 0x80u, // BIND_OPCODE_ADD_ADDR_ULEB 00214 BindOpcodeDoBind = 0x90u, // BIND_OPCODE_DO_BIND 00215 BindOpcodeDoBindAddAddressULEB = 0xA0u, // BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 00216 BindOpcodeDoBindAddAddressImmediateScaled = 0xB0u, // BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 00217 BindOpcodeDoBindULEBTimesSkippingULEB = 0xC0u, // BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 00218 00219 ExportSymbolFlagsKindMask = 0x03u, // EXPORT_SYMBOL_FLAGS_KIND_MASK 00220 ExportSymbolFlagsKindRegular = 0x00u, // EXPORT_SYMBOL_FLAGS_KIND_REGULAR 00221 ExportSymbolFlagsKindThreadLocal = 0x01u, // EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 00222 ExportSymbolFlagsWeakDefinition = 0x04u, // EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 00223 ExportSymbolFlagsIndirectDefinition = 0x08u, // EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 00224 ExportSymbolFlagsHasSpecializations = 0x10u, // EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 00225 00226 00227 // Constant masks for the "n_type" field in llvm::MachO::nlist and 00228 // llvm::MachO::nlist_64 00229 NlistMaskStab = 0xe0, // N_STAB 00230 NlistMaskPrivateExternal = 0x10, // N_PEXT 00231 NlistMaskType = 0x0e, // N_TYPE 00232 NlistMaskExternal = 0x01, // N_EXT 00233 00234 // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and 00235 // llvm::MachO::nlist_64 00236 NListTypeUndefined = 0x0u, // N_UNDF 00237 NListTypeAbsolute = 0x2u, // N_ABS 00238 NListTypeSection = 0xeu, // N_SECT 00239 NListTypePreboundUndefined = 0xcu, // N_PBUD 00240 NListTypeIndirect = 0xau, // N_INDR 00241 00242 // Constant masks for the "n_sect" field in llvm::MachO::nlist and 00243 // llvm::MachO::nlist_64 00244 NListSectionNoSection = 0u, // NO_SECT 00245 NListSectionMaxSection = 0xffu, // MAX_SECT 00246 00247 NListDescWeakRef = 0x40u, 00248 NListDescWeakDef = 0x80u, 00249 00250 // Constant values for the "n_type" field in llvm::MachO::nlist and 00251 // llvm::MachO::nlist_64 when "(n_type & NlistMaskStab) != 0" 00252 StabGlobalSymbol = 0x20u, // N_GSYM 00253 StabFunctionName = 0x22u, // N_FNAME 00254 StabFunction = 0x24u, // N_FUN 00255 StabStaticSymbol = 0x26u, // N_STSYM 00256 StabLocalCommon = 0x28u, // N_LCSYM 00257 StabBeginSymbol = 0x2Eu, // N_BNSYM 00258 StabSourceFileOptions = 0x3Cu, // N_OPT 00259 StabRegisterSymbol = 0x40u, // N_RSYM 00260 StabSourceLine = 0x44u, // N_SLINE 00261 StabEndSymbol = 0x4Eu, // N_ENSYM 00262 StabStructureType = 0x60u, // N_SSYM 00263 StabSourceFileName = 0x64u, // N_SO 00264 StabObjectFileName = 0x66u, // N_OSO 00265 StabLocalSymbol = 0x80u, // N_LSYM 00266 StabBeginIncludeFileName = 0x82u, // N_BINCL 00267 StabIncludeFileName = 0x84u, // N_SOL 00268 StabCompilerParameters = 0x86u, // N_PARAMS 00269 StabCompilerVersion = 0x88u, // N_VERSION 00270 StabCompilerOptLevel = 0x8Au, // N_OLEVEL 00271 StabParameter = 0xA0u, // N_PSYM 00272 StabEndIncludeFile = 0xA2u, // N_EINCL 00273 StabAlternateEntry = 0xA4u, // N_ENTRY 00274 StabLeftBracket = 0xC0u, // N_LBRAC 00275 StabDeletedIncludeFile = 0xC2u, // N_EXCL 00276 StabRightBracket = 0xE0u, // N_RBRAC 00277 StabBeginCommon = 0xE2u, // N_BCOMM 00278 StabEndCommon = 0xE4u, // N_ECOMM 00279 StabEndCommonLocal = 0xE8u, // N_ECOML 00280 StabLength = 0xFEu // N_LENG 00281 00282 }; 00283 00284 // Structs from <mach-o/loader.h> 00285 00286 struct mach_header { 00287 uint32_t magic; 00288 uint32_t cputype; 00289 uint32_t cpusubtype; 00290 uint32_t filetype; 00291 uint32_t ncmds; 00292 uint32_t sizeofcmds; 00293 uint32_t flags; 00294 }; 00295 00296 struct mach_header_64 { 00297 uint32_t magic; 00298 uint32_t cputype; 00299 uint32_t cpusubtype; 00300 uint32_t filetype; 00301 uint32_t ncmds; 00302 uint32_t sizeofcmds; 00303 uint32_t flags; 00304 uint32_t reserved; 00305 }; 00306 00307 struct load_command { 00308 uint32_t cmd; 00309 uint32_t cmdsize; 00310 }; 00311 00312 struct segment_command { 00313 uint32_t cmd; 00314 uint32_t cmdsize; 00315 char segname[16]; 00316 uint32_t vmaddr; 00317 uint32_t vmsize; 00318 uint32_t fileoff; 00319 uint32_t filesize; 00320 uint32_t maxprot; 00321 uint32_t initprot; 00322 uint32_t nsects; 00323 uint32_t flags; 00324 }; 00325 00326 struct segment_command_64 { 00327 uint32_t cmd; 00328 uint32_t cmdsize; 00329 char segname[16]; 00330 uint64_t vmaddr; 00331 uint64_t vmsize; 00332 uint64_t fileoff; 00333 uint64_t filesize; 00334 uint32_t maxprot; 00335 uint32_t initprot; 00336 uint32_t nsects; 00337 uint32_t flags; 00338 }; 00339 00340 struct section { 00341 char sectname[16]; 00342 char segname[16]; 00343 uint32_t addr; 00344 uint32_t size; 00345 uint32_t offset; 00346 uint32_t align; 00347 uint32_t reloff; 00348 uint32_t nreloc; 00349 uint32_t flags; 00350 uint32_t reserved1; 00351 uint32_t reserved2; 00352 }; 00353 00354 struct section_64 { 00355 char sectname[16]; 00356 char segname[16]; 00357 uint64_t addr; 00358 uint64_t size; 00359 uint32_t offset; 00360 uint32_t align; 00361 uint32_t reloff; 00362 uint32_t nreloc; 00363 uint32_t flags; 00364 uint32_t reserved1; 00365 uint32_t reserved2; 00366 uint32_t reserved3; 00367 }; 00368 00369 struct fvmlib { 00370 uint32_t name; 00371 uint32_t minor_version; 00372 uint32_t header_addr; 00373 }; 00374 00375 struct fvmlib_command { 00376 uint32_t cmd; 00377 uint32_t cmdsize; 00378 struct fvmlib fvmlib; 00379 }; 00380 00381 struct dylib { 00382 uint32_t name; 00383 uint32_t timestamp; 00384 uint32_t current_version; 00385 uint32_t compatibility_version; 00386 }; 00387 00388 struct dylib_command { 00389 uint32_t cmd; 00390 uint32_t cmdsize; 00391 struct dylib dylib; 00392 }; 00393 00394 struct sub_framework_command { 00395 uint32_t cmd; 00396 uint32_t cmdsize; 00397 uint32_t umbrella; 00398 }; 00399 00400 struct sub_client_command { 00401 uint32_t cmd; 00402 uint32_t cmdsize; 00403 uint32_t client; 00404 }; 00405 00406 struct sub_umbrella_command { 00407 uint32_t cmd; 00408 uint32_t cmdsize; 00409 uint32_t sub_umbrella; 00410 }; 00411 00412 struct sub_library_command { 00413 uint32_t cmd; 00414 uint32_t cmdsize; 00415 uint32_t sub_library; 00416 }; 00417 00418 struct prebound_dylib_command { 00419 uint32_t cmd; 00420 uint32_t cmdsize; 00421 uint32_t name; 00422 uint32_t nmodules; 00423 uint32_t linked_modules; 00424 }; 00425 00426 struct dylinker_command { 00427 uint32_t cmd; 00428 uint32_t cmdsize; 00429 uint32_t name; 00430 }; 00431 00432 struct thread_command { 00433 uint32_t cmd; 00434 uint32_t cmdsize; 00435 }; 00436 00437 struct routines_command { 00438 uint32_t cmd; 00439 uint32_t cmdsize; 00440 uint32_t init_address; 00441 uint32_t init_module; 00442 uint32_t reserved1; 00443 uint32_t reserved2; 00444 uint32_t reserved3; 00445 uint32_t reserved4; 00446 uint32_t reserved5; 00447 uint32_t reserved6; 00448 }; 00449 00450 struct routines_command_64 { 00451 uint32_t cmd; 00452 uint32_t cmdsize; 00453 uint64_t init_address; 00454 uint64_t init_module; 00455 uint64_t reserved1; 00456 uint64_t reserved2; 00457 uint64_t reserved3; 00458 uint64_t reserved4; 00459 uint64_t reserved5; 00460 uint64_t reserved6; 00461 }; 00462 00463 struct symtab_command { 00464 uint32_t cmd; 00465 uint32_t cmdsize; 00466 uint32_t symoff; 00467 uint32_t nsyms; 00468 uint32_t stroff; 00469 uint32_t strsize; 00470 }; 00471 00472 struct dysymtab_command { 00473 uint32_t cmd; 00474 uint32_t cmdsize; 00475 uint32_t ilocalsym; 00476 uint32_t nlocalsym; 00477 uint32_t iextdefsym; 00478 uint32_t nextdefsym; 00479 uint32_t iundefsym; 00480 uint32_t nundefsym; 00481 uint32_t tocoff; 00482 uint32_t ntoc; 00483 uint32_t modtaboff; 00484 uint32_t nmodtab; 00485 uint32_t extrefsymoff; 00486 uint32_t nextrefsyms; 00487 uint32_t indirectsymoff; 00488 uint32_t nindirectsyms; 00489 uint32_t extreloff; 00490 uint32_t nextrel; 00491 uint32_t locreloff; 00492 uint32_t nlocrel; 00493 }; 00494 00495 struct dylib_table_of_contents { 00496 uint32_t symbol_index; 00497 uint32_t module_index; 00498 }; 00499 00500 struct dylib_module { 00501 uint32_t module_name; 00502 uint32_t iextdefsym; 00503 uint32_t nextdefsym; 00504 uint32_t irefsym; 00505 uint32_t nrefsym; 00506 uint32_t ilocalsym; 00507 uint32_t nlocalsym; 00508 uint32_t iextrel; 00509 uint32_t nextrel; 00510 uint32_t iinit_iterm; 00511 uint32_t ninit_nterm; 00512 uint32_t objc_module_info_addr; 00513 uint32_t objc_module_info_size; 00514 }; 00515 00516 struct dylib_module_64 { 00517 uint32_t module_name; 00518 uint32_t iextdefsym; 00519 uint32_t nextdefsym; 00520 uint32_t irefsym; 00521 uint32_t nrefsym; 00522 uint32_t ilocalsym; 00523 uint32_t nlocalsym; 00524 uint32_t iextrel; 00525 uint32_t nextrel; 00526 uint32_t iinit_iterm; 00527 uint32_t ninit_nterm; 00528 uint32_t objc_module_info_size; 00529 uint64_t objc_module_info_addr; 00530 }; 00531 00532 struct dylib_reference { 00533 uint32_t isym:24, 00534 flags:8; 00535 }; 00536 00537 00538 struct twolevel_hints_command { 00539 uint32_t cmd; 00540 uint32_t cmdsize; 00541 uint32_t offset; 00542 uint32_t nhints; 00543 }; 00544 00545 struct twolevel_hint { 00546 uint32_t isub_image:8, 00547 itoc:24; 00548 }; 00549 00550 struct prebind_cksum_command { 00551 uint32_t cmd; 00552 uint32_t cmdsize; 00553 uint32_t cksum; 00554 }; 00555 00556 struct uuid_command { 00557 uint32_t cmd; 00558 uint32_t cmdsize; 00559 uint8_t uuid[16]; 00560 }; 00561 00562 struct rpath_command { 00563 uint32_t cmd; 00564 uint32_t cmdsize; 00565 uint32_t path; 00566 }; 00567 00568 struct linkedit_data_command { 00569 uint32_t cmd; 00570 uint32_t cmdsize; 00571 uint32_t dataoff; 00572 uint32_t datasize; 00573 }; 00574 00575 struct encryption_info_command { 00576 uint32_t cmd; 00577 uint32_t cmdsize; 00578 uint32_t cryptoff; 00579 uint32_t cryptsize; 00580 uint32_t cryptid; 00581 }; 00582 00583 struct version_min_command { 00584 uint32_t cmd; 00585 uint32_t cmdsize; 00586 uint32_t version; 00587 uint32_t reserved; 00588 }; 00589 00590 struct dyld_info_command { 00591 uint32_t cmd; 00592 uint32_t cmdsize; 00593 uint32_t rebase_off; 00594 uint32_t rebase_size; 00595 uint32_t bind_off; 00596 uint32_t bind_size; 00597 uint32_t weak_bind_off; 00598 uint32_t weak_bind_size; 00599 uint32_t lazy_bind_off; 00600 uint32_t lazy_bind_size; 00601 uint32_t export_off; 00602 uint32_t export_size; 00603 }; 00604 00605 struct symseg_command { 00606 uint32_t cmd; 00607 uint32_t cmdsize; 00608 uint32_t offset; 00609 uint32_t size; 00610 }; 00611 00612 struct ident_command { 00613 uint32_t cmd; 00614 uint32_t cmdsize; 00615 }; 00616 00617 struct fvmfile_command { 00618 uint32_t cmd; 00619 uint32_t cmdsize; 00620 uint32_t name; 00621 uint32_t header_addr; 00622 }; 00623 00624 00625 // Structs from <mach-o/fat.h> 00626 struct fat_header { 00627 uint32_t magic; 00628 uint32_t nfat_arch; 00629 }; 00630 00631 struct fat_arch { 00632 uint32_t cputype; 00633 uint32_t cpusubtype; 00634 uint32_t offset; 00635 uint32_t size; 00636 uint32_t align; 00637 }; 00638 00639 // Structs from <mach-o/fat.h> 00640 struct nlist { 00641 uint32_t n_strx; 00642 uint8_t n_type; 00643 uint8_t n_sect; 00644 int16_t n_desc; 00645 uint32_t n_value; 00646 }; 00647 00648 struct nlist_64 { 00649 uint32_t n_strx; 00650 uint8_t n_type; 00651 uint8_t n_sect; 00652 uint16_t n_desc; 00653 uint64_t n_value; 00654 }; 00655 00656 // Get/Set functions from <mach-o/nlist.h> 00657 00658 static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) 00659 { 00660 return (((n_desc) >> 8u) & 0xffu); 00661 } 00662 00663 static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) 00664 { 00665 n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8)); 00666 } 00667 00668 static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc) 00669 { 00670 return (n_desc >> 8u) & 0x0fu; 00671 } 00672 00673 static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align) 00674 { 00675 n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u)); 00676 } 00677 00678 // Enums from <mach/machine.h> 00679 enum { 00680 // Capability bits used in the definition of cpu_type. 00681 CPUArchMask = 0xff000000, // Mask for architecture bits 00682 CPUArchABI64 = 0x01000000, // 64 bit ABI 00683 00684 // Constants for the cputype field. 00685 CPUTypeI386 = 7, 00686 CPUTypeX86_64 = CPUTypeI386 | CPUArchABI64, 00687 CPUTypeARM = 12, 00688 CPUTypeSPARC = 14, 00689 CPUTypePowerPC = 18, 00690 CPUTypePowerPC64 = CPUTypePowerPC | CPUArchABI64, 00691 00692 00693 // Constants for the cpusubtype field. 00694 00695 // X86 00696 CPUSubType_I386_ALL = 3, 00697 CPUSubType_X86_64_ALL = 3, 00698 00699 // ARM 00700 CPUSubType_ARM_ALL = 0, 00701 CPUSubType_ARM_V4T = 5, 00702 CPUSubType_ARM_V5 = 7, 00703 CPUSubType_ARM_V6 = 6, 00704 CPUSubType_ARM_V7 = 9, 00705 00706 // PowerPC 00707 CPUSubType_POWERPC_ALL = 0, 00708 00709 CPUSubType_SPARC_ALL = 0 00710 }; 00711 } // end namespace MachO 00712 } // end namespace llvm 00713 00714 #endif