Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

714 lines
26 KiB

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