macho.pas 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  1. unit macho;
  2. {
  3. * Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
  4. *
  5. * @APPLE_LICENSE_HEADER_START@
  6. *
  7. * This file contains Original Code and/or Modifications of Original Code
  8. * as defined in and that are subject to the Apple Public Source License
  9. * Version 2.0 (the 'License'). You may not use this file except in
  10. * compliance with the License. Please obtain a copy of the License at
  11. * http://www.opensource.apple.com/apsl/ and read it before using this
  12. * file.
  13. *
  14. * The Original Code and all software distributed under the License are
  15. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  16. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  17. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  19. * Please see the License for the specific language governing rights and
  20. * limitations under the License.
  21. *
  22. * @APPLE_LICENSE_HEADER_END@
  23. }
  24. { converted by Dmitry Boyarintsev 2009 }
  25. {$i fpcdefs.inc}
  26. {$H+}
  27. interface
  28. {$IFDEF FPC}
  29. {$PACKRECORDS C}
  30. {$PACKENUM 4}
  31. {$ENDIF}
  32. // mach/$arch/machine.h
  33. // $arch can be: i386, x86_64, ppc, arm
  34. // currently used is i386
  35. type
  36. integer_t = Integer;
  37. uint8_t = Byte;
  38. int16_t = SmallInt;
  39. uint16_t = Word;
  40. uint32_t = LongWord;
  41. int32_t = Integer;
  42. uint64_t = QWord;
  43. // mach/thread_status.h
  44. {$ifdef i386}
  45. {$endif i386}
  46. // mach/machine.h
  47. type
  48. cpu_type_t = integer_t;
  49. cpu_subtype_t = integer_t;
  50. cpu_threadtype_t = integer_t;
  51. const
  52. CPU_STATE_MAX = 4;
  53. CPU_STATE_USER = 0;
  54. CPU_STATE_SYSTEM = 1;
  55. CPU_STATE_IDLE = 2;
  56. CPU_STATE_NICE = 3;
  57. {* Capability bits used in the definition of cpu_type. }
  58. CPU_ARCH_MASK = $ff000000; { mask for architecture bits }
  59. CPU_ARCH_ABI64 = $01000000; { 64 bit ABI }
  60. { Machine types known by all. }
  61. CPU_TYPE_ANY = -1;
  62. CPU_TYPE_VAX = 1;
  63. CPU_TYPE_MC680x0 = 6;
  64. CPU_TYPE_X86 = 7;
  65. CPU_TYPE_I386 = CPU_TYPE_X86; { compatibility }
  66. CPU_TYPE_X86_64 = CPU_TYPE_X86 or CPU_ARCH_ABI64;
  67. // skip CPU_TYPE_MIPS = 8;
  68. CPU_TYPE_MC98000 = 10;
  69. CPU_TYPE_HPPA = 11;
  70. CPU_TYPE_ARM = 12;
  71. CPU_TYPE_ARM64 = CPU_TYPE_ARM or CPU_ARCH_ABI64;
  72. CPU_TYPE_MC88000 = 13;
  73. CPU_TYPE_SPARC = 14;
  74. CPU_TYPE_I860 = 15;
  75. // skip CPU_TYPE_ALPHA = 16; */
  76. CPU_TYPE_POWERPC = 18;
  77. CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC or CPU_ARCH_ABI64;
  78. {*
  79. * Machine subtypes (these are defined here, instead of in a machine
  80. * dependent directory, so that any program can get all definitions
  81. * regardless of where is it compiled).
  82. *}
  83. {*
  84. * Capability bits used in the definition of cpu_subtype.
  85. *}
  86. CPU_SUBTYPE_MASK = $ff000000; { mask for feature flags }
  87. CPU_SUBTYPE_LIB64 = $80000000; { 64 bit libraries }
  88. {*
  89. * Object files that are hand-crafted to run on any
  90. * implementation of an architecture are tagged with
  91. * CPU_SUBTYPE_MULTIPLE. This functions essentially the same as
  92. * the "ALL" subtype of an architecture except that it allows us
  93. * to easily find object files that may need to be modified
  94. * whenever a new implementation of an architecture comes out.
  95. *
  96. * It is the responsibility of the implementor to make sure the
  97. * software handles unsupported implementations elegantly.
  98. *}
  99. CPU_SUBTYPE_MULTIPLE = -1;
  100. CPU_SUBTYPE_LITTLE_ENDIAN = 0;
  101. CPU_SUBTYPE_BIG_ENDIAN = 1;
  102. {*
  103. * Machine threadtypes.
  104. * This is none - not defined - for most machine types/subtypes.
  105. *}
  106. CPU_THREADTYPE_NONE = 0;
  107. {*
  108. * VAX subtypes (these do *not* necessary conform to the actual cpu
  109. * ID assigned by DEC available via the SID register).
  110. *}
  111. CPU_SUBTYPE_VAX_ALL = 0;
  112. CPU_SUBTYPE_VAX780 = 1;
  113. CPU_SUBTYPE_VAX785 = 2;
  114. CPU_SUBTYPE_VAX750 = 3;
  115. CPU_SUBTYPE_VAX730 = 4;
  116. CPU_SUBTYPE_UVAXI = 5;
  117. CPU_SUBTYPE_UVAXII = 6;
  118. CPU_SUBTYPE_VAX8200 = 7;
  119. CPU_SUBTYPE_VAX8500 = 8;
  120. CPU_SUBTYPE_VAX8600 = 9;
  121. CPU_SUBTYPE_VAX8650 = 10;
  122. CPU_SUBTYPE_VAX8800 = 11;
  123. CPU_SUBTYPE_UVAXIII = 12;
  124. {*
  125. * 680x0 subtypes
  126. *
  127. * The subtype definitions here are unusual for historical reasons.
  128. * NeXT used to consider 68030 code as generic 68000 code. For
  129. * backwards compatability:
  130. *
  131. * CPU_SUBTYPE_MC68030 symbol has been preserved for source code
  132. * compatability.
  133. *
  134. * CPU_SUBTYPE_MC680x0_ALL has been defined to be the same
  135. * subtype as CPU_SUBTYPE_MC68030 for binary comatability.
  136. *
  137. * CPU_SUBTYPE_MC68030_ONLY has been added to allow new object
  138. * files to be tagged as containing 68030-specific instructions.
  139. *}
  140. CPU_SUBTYPE_MC680x0_ALL = 1;
  141. CPU_SUBTYPE_MC68030 = 1; { compat }
  142. CPU_SUBTYPE_MC68040 = 2;
  143. CPU_SUBTYPE_MC68030_ONLY = 3;
  144. {* I386 subtypes *}
  145. CPU_SUBTYPE_I386_ALL = 3 + (0 shl 4);
  146. CPU_SUBTYPE_386 = 3 + (0 shl 4);
  147. CPU_SUBTYPE_486 = 4 + (0 shl 4);
  148. CPU_SUBTYPE_486SX = 4 + (8 shl 4); // 8 << 4 = 128
  149. CPU_SUBTYPE_586 = 5 + (0 shl 4);
  150. CPU_SUBTYPE_PENT = 5 + (0 shl 4);
  151. CPU_SUBTYPE_PENTPRO = 6 + (1 shl 4);
  152. CPU_SUBTYPE_PENTII_M3 = 6 + (3 shl 4);
  153. CPU_SUBTYPE_PENTII_M5 = 6 + (5 shl 4);
  154. CPU_SUBTYPE_CELERON = 7 + (6 shl 4);
  155. CPU_SUBTYPE_CELERON_MOBILE = 7 + (7 shl 4);
  156. CPU_SUBTYPE_PENTIUM_3 = 8 + (0 shl 4);
  157. CPU_SUBTYPE_PENTIUM_3_M = 8 + (1 shl 4);
  158. CPU_SUBTYPE_PENTIUM_3_XEON = 8 + (2 shl 4);
  159. CPU_SUBTYPE_PENTIUM_M = 9 + (0 shl 4);
  160. CPU_SUBTYPE_PENTIUM_4 = 10 + (0 shl 4);
  161. CPU_SUBTYPE_PENTIUM_4_M = 10 + (1 shl 4);
  162. CPU_SUBTYPE_ITANIUM = 11 + (0 shl 4);
  163. CPU_SUBTYPE_ITANIUM_2 = 11 + (1 shl 4);
  164. CPU_SUBTYPE_XEON = 12 + (0 shl 4);
  165. CPU_SUBTYPE_XEON_MP = 12 + (1 shl 4);
  166. CPU_SUBTYPE_INTEL_FAMILY_MAX = 15;
  167. CPU_SUBTYPE_INTEL_MODEL_ALL = 0;
  168. {* X86 subtypes. *}
  169. CPU_SUBTYPE_X86_ALL = 3;
  170. CPU_SUBTYPE_X86_64_ALL = 3;
  171. CPU_SUBTYPE_X86_ARCH1 = 4;
  172. CPU_THREADTYPE_INTEL_HTT = 1;
  173. {* Mips subtypes. *}
  174. CPU_SUBTYPE_MIPS_ALL = 0;
  175. CPU_SUBTYPE_MIPS_R2300 = 1;
  176. CPU_SUBTYPE_MIPS_R2600 = 2;
  177. CPU_SUBTYPE_MIPS_R2800 = 3;
  178. CPU_SUBTYPE_MIPS_R2000a = 4; {* pmax *}
  179. CPU_SUBTYPE_MIPS_R2000 = 5;
  180. CPU_SUBTYPE_MIPS_R3000a = 6; { 3max *}
  181. CPU_SUBTYPE_MIPS_R3000 = 7;
  182. {* MC98000 (PowerPC) subtypes *}
  183. CPU_SUBTYPE_MC98000_ALL = 0;
  184. CPU_SUBTYPE_MC98601 = 1;
  185. {*
  186. * HPPA subtypes for Hewlett-Packard HP-PA family of
  187. * risc processors. Port by NeXT to 700 series.
  188. *}
  189. CPU_SUBTYPE_HPPA_ALL = 0;
  190. CPU_SUBTYPE_HPPA_7100 = 0; {* compat *}
  191. CPU_SUBTYPE_HPPA_7100LC = 1;
  192. {* MC88000 subtypes. *}
  193. CPU_SUBTYPE_MC88000_ALL = 0;
  194. CPU_SUBTYPE_MC88100 = 1;
  195. CPU_SUBTYPE_MC88110 = 2;
  196. {* SPARC subtypes *}
  197. CPU_SUBTYPE_SPARC_ALL = 0;
  198. {* I860 subtypes *}
  199. CPU_SUBTYPE_I860_ALL = 0;
  200. CPU_SUBTYPE_I860_860 = 1;
  201. {* PowerPC subtypes *}
  202. CPU_SUBTYPE_POWERPC_ALL = 0;
  203. CPU_SUBTYPE_POWERPC_601 = 1;
  204. CPU_SUBTYPE_POWERPC_602 = 2;
  205. CPU_SUBTYPE_POWERPC_603 = 3;
  206. CPU_SUBTYPE_POWERPC_603e = 4;
  207. CPU_SUBTYPE_POWERPC_603ev = 5;
  208. CPU_SUBTYPE_POWERPC_604 = 6;
  209. CPU_SUBTYPE_POWERPC_604e = 7;
  210. CPU_SUBTYPE_POWERPC_620 = 8;
  211. CPU_SUBTYPE_POWERPC_750 = 9;
  212. CPU_SUBTYPE_POWERPC_7400 = 10;
  213. CPU_SUBTYPE_POWERPC_7450 = 11;
  214. CPU_SUBTYPE_POWERPC_970 = 100;
  215. {* ARM subtypes *}
  216. CPU_SUBTYPE_ARM_ALL = 0;
  217. CPU_SUBTYPE_ARM_V4T = 5;
  218. CPU_SUBTYPE_ARM_V6 = 6;
  219. CPU_SUBTYPE_ARM_V5TEJ = 7;
  220. CPU_SUBTYPE_ARM_XSCALE = 8;
  221. {*
  222. * CPU families (sysctl hw.cpufamily)
  223. *
  224. * These are meant to identify the CPU's marketing name - an
  225. * application can map these to (possibly) localized strings.
  226. * NB: the encodings of the CPU families are intentionally arbitrary.
  227. * There is no ordering, and you should never try to deduce whether
  228. * or not some feature is available based on the family.
  229. * Use feature flags (eg, hw.optional.altivec) to test for optional
  230. * functionality.
  231. *}
  232. CPUFAMILY_UNKNOWN = 0;
  233. CPUFAMILY_POWERPC_G3 = $cee41549;
  234. CPUFAMILY_POWERPC_G4 = $77c184ae;
  235. CPUFAMILY_POWERPC_G5 = $ed76d8aa;
  236. CPUFAMILY_INTEL_6_13 = $aa33392b;
  237. CPUFAMILY_INTEL_6_14 = $73d67300; { "Intel Core Solo" and "Intel Core Duo" (32-bit Pentium-M with SSE3) }
  238. CPUFAMILY_INTEL_6_15 = $426f69ef; { "Intel Core 2 Duo" }
  239. CPUFAMILY_INTEL_6_23 = $78ea4fbc; { Penryn }
  240. CPUFAMILY_INTEL_6_26 = $6b5a4cd2; { Nehalem }
  241. CPUFAMILY_ARM_9 = $e73283ae;
  242. CPUFAMILY_ARM_11 = $8ff620d8;
  243. CPUFAMILY_ARM_XSCALE = $53b005f5;
  244. CPUFAMILY_INTEL_YONAH = CPUFAMILY_INTEL_6_14;
  245. CPUFAMILY_INTEL_MEROM = CPUFAMILY_INTEL_6_15;
  246. CPUFAMILY_INTEL_PENRYN = CPUFAMILY_INTEL_6_23;
  247. CPUFAMILY_INTEL_NEHALEM = CPUFAMILY_INTEL_6_26;
  248. CPUFAMILY_INTEL_CORE = CPUFAMILY_INTEL_6_14;
  249. CPUFAMILY_INTEL_CORE2 = CPUFAMILY_INTEL_6_15;
  250. // mach/vm_prot.h
  251. type
  252. vm_prot_t = Integer;
  253. const
  254. VM_PROT_NONE = $00;
  255. VM_PROT_READ = $01; {* read permission *}
  256. VM_PROT_WRITE = $02; {* write permission *}
  257. VM_PROT_EXECUTE = $04; {* execute permission *}
  258. {*
  259. * The default protection for newly-created virtual memory
  260. *}
  261. VM_PROT_DEFAULT = VM_PROT_READ or VM_PROT_WRITE;
  262. {*
  263. * The maximum privileges possible, for parameter checking.
  264. *}
  265. VM_PROT_ALL = VM_PROT_READ or VM_PROT_WRITE or VM_PROT_EXECUTE;
  266. {*
  267. * An invalid protection value.
  268. * Used only by memory_object_lock_request to indicate no change
  269. * to page locks. Using -1 here is a bad idea because it
  270. * looks like VM_PROT_ALL and then some.
  271. *}
  272. VM_PROT_NO_CHANGE = $08;
  273. {*
  274. * When a caller finds that he cannot obtain write permission on a
  275. * mapped entry, the following flag can be used. The entry will
  276. * be made "needs copy" effectively copying the object (using COW),
  277. * and write permission will be added to the maximum protections
  278. * for the associated entry.
  279. *}
  280. VM_PROT_COPY = $10;
  281. {*
  282. * Another invalid protection value.
  283. * Used only by memory_object_data_request upon an object
  284. * which has specified a copy_call copy strategy. It is used
  285. * when the kernel wants a page belonging to a copy of the
  286. * object, and is only asking the object as a result of
  287. * following a shadow chain. This solves the race between pages
  288. * being pushed up by the memory manager and the kernel
  289. * walking down the shadow chain.
  290. *}
  291. VM_PROT_WANTS_COPY = $10;
  292. { Constant for the magic field of the mach_header (32-bit architectures) the mach magic number }
  293. const
  294. MH_MAGIC = $feedface;
  295. MH_CIGAM = $cefaedfe; { NXSwapInt(MH_MAGIC) }
  296. type
  297. { * The 32-bit mach header appears at the very beginning of the object file for 32-bit architectures. }
  298. mach_header = record
  299. magic : uint32_t; { mach magic number identifier }
  300. cputype : cpu_type_t; { cpu specifier }
  301. cpusubtype : cpu_subtype_t; { machine specifier }
  302. filetype : uint32_t; { type of file }
  303. ncmds : uint32_t; { number of load commands }
  304. sizeofcmds : uint32_t; { the size of all the load commands }
  305. flags : uint32_t; { flags }
  306. end;
  307. pmach_header = ^mach_header;
  308. type
  309. {* The 64-bit mach header appears at the very beginning of object files for
  310. * 64-bit architectures. }
  311. mach_header_64 = record
  312. magic : uint32_t; { mach magic number identifier }
  313. cputype : cpu_type_t; { cpu specifier }
  314. cpusubtype : cpu_subtype_t; { machine specifier }
  315. filetype : uint32_t; { type of file }
  316. ncmds : uint32_t; { number of load commands }
  317. sizeofcmds : uint32_t; { the size of all the load commands }
  318. flags : uint32_t; { flags }
  319. reserved : uint32_t; { reserved }
  320. end;
  321. pmach_header_64 = ^mach_header_64;
  322. { Constant for the magic field of the mach_header_64 (64-bit architectures) }
  323. { the 64-bit mach magic number }
  324. const
  325. MH_MAGIC_64 = $feedfacf;
  326. MH_CIGAM_64 = $cffaedfe; { NXSwapInt(MH_MAGIC_64) }
  327. {* The layout of the file depends on the filetype. For all but the MH_OBJECT
  328. * file type the segments are padded out and aligned on a segment alignment
  329. * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB,
  330. * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part
  331. * of their first segment.
  332. *
  333. * The file type MH_OBJECT is a compact format intended as output of the
  334. * assembler and input (and possibly output) of the link editor (the .o
  335. * format). All sections are in one unnamed segment with no segment padding.
  336. * This format is used as an executable format when the file is so small the
  337. * segment padding greatly increases its size.
  338. *
  339. * The file type MH_PRELOAD is an executable format intended for things that
  340. * are not executed under the kernel (proms, stand alones, kernels, etc). The
  341. * format can be executed under the kernel but may demand paged it and not
  342. * preload it before execution.
  343. *
  344. * A core file is in MH_CORE format and can be any in an arbritray legal
  345. * Mach-O file.
  346. *
  347. * Constants for the filetype field of the mach_header }
  348. const
  349. MH_OBJECT = $1; { relocatable object file }
  350. MH_EXECUTE = $2; { demand paged executable file }
  351. MH_FVMLIB = $3; { fixed VM shared library file }
  352. MH_CORE = $4; { core file }
  353. MH_PRELOAD = $5; { preloaded executable file }
  354. MH_DYLIB = $6; { dynamically bound shared library }
  355. MH_DYLINKER = $7; { dynamic link editor }
  356. MH_BUNDLE = $8; { dynamically bound bundle file }
  357. MH_DYLIB_STUB = $9; { shared library stub for static }
  358. MH_DSYM = $a; { linking only, no section contents }
  359. { companion file with only debug sections }
  360. const
  361. { Constants for the flags field of the mach_header }
  362. MH_NOUNDEFS = $1; { the object file has no undefined references }
  363. MH_INCRLINK = $2; { the object file is the output of an incremental link against a base file and can't be link edited again }
  364. MH_DYLDLINK = $4; { the object file is input for the dynamic linker and can't be staticly link edited again }
  365. MH_BINDATLOAD = $8; { the object file's undefined references are bound by the dynamic linker when loaded. }
  366. MH_PREBOUND = $10; { the file has its dynamic undefined references prebound. }
  367. MH_SPLIT_SEGS = $20; { the file has its read-only and read-write segments split }
  368. MH_LAZY_INIT = $40; { the shared library init routine is to be run lazily via catching memory faults to its writeable segments (obsolete) }
  369. MH_TWOLEVEL = $80; { the image is using two-level name space bindings }
  370. MH_FORCE_FLAT = $100; { the executable is forcing all images to use flat name space bindings }
  371. MH_NOMULTIDEFS = $200; { this umbrella guarantees no multiple defintions of symbols in its sub-images so the two-level namespace hints can always be used. }
  372. MH_NOFIXPREBINDING = $400; { do not have dyld notify the prebinding agent about this executable }
  373. MH_PREBINDABLE = $800; { the binary is not prebound but can have its prebinding redone. only used when MH_PREBOUND is not set. }
  374. MH_ALLMODSBOUND = $1000; { indicates that this binary binds to all two-level namespace modules of }
  375. { its dependent libraries. only used when MH_PREBINDABLE and MH_TWOLEVEL are both set. }
  376. MH_SUBSECTIONS_VIA_SYMBOLS = $2000; { safe to divide up the sections into sub-sections via symbols for dead code stripping }
  377. MH_CANONICAL = $4000; { the binary has been canonicalized via the unprebind operation }
  378. MH_WEAK_DEFINES = $8000; { the final linked image contains external weak symbols }
  379. MH_BINDS_TO_WEAK = $10000; { the final linked image uses weak symbols }
  380. MH_ALLOW_STACK_EXECUTION = $20000; { When this bit is set, all stacks in the task will be given stack }
  381. { execution privilege. Only used in MH_EXECUTE filetypes. }
  382. MH_ROOT_SAFE = $40000; { When this bit is set, the binary declares it is safe for use in processes with uid zero }
  383. MH_SETUID_SAFE = $80000; { When this bit is set, the binary declares it is safe for use in processes when issetugid() is true }
  384. MH_NO_REEXPORTED_DYLIBS = $100000; { When this bit is set on a dylib, the static linker does not need to examine dependent dylibs to see if any are re-exported }
  385. MH_PIE = $200000; { When this bit is set, the OS will load the main executable at a random address. Only used in MH_EXECUTE filetypes. }
  386. {
  387. * The load commands directly follow the mach_header. The total size of all
  388. * of the commands is given by the sizeofcmds field in the mach_header. All
  389. * load commands must have as their first two fields cmd and cmdsize. The cmd
  390. * field is filled in with a constant for that command type. Each command type
  391. * has a structure specifically for it. The cmdsize field is the size in bytes
  392. * of the particular load command structure plus anything that follows it that
  393. * is a part of the load command (i.e. section structures, strings, etc.). To
  394. * advance to the next load command the cmdsize can be added to the offset or
  395. * pointer of the current load command. The cmdsize for 32-bit architectures
  396. * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple
  397. * of 8 bytes (these are forever the maximum alignment of any load commands).
  398. * The padded bytes must be zero. All tables in the object file must also
  399. * follow these rules so the file can be memory mapped. Otherwise the pointers
  400. * to these tables will not work well or at all on some machines. With all
  401. * padding zeroed like objects will compare byte for byte.
  402. }
  403. type
  404. load_command = record
  405. cmd : uint32_t; { type of load command }
  406. cmdsize : uint32_t; { total size of command in bytes }
  407. end;
  408. pload_command = ^load_command;
  409. {
  410. * After MacOS X 10.1 when a new load command is added that is required to be
  411. * understood by the dynamic linker for the image to execute properly the
  412. * LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic
  413. * linker sees such a load command it it does not understand will issue a
  414. * "unknown load command required for execution" error and refuse to use the
  415. * image. Other load commands without this bit that are not understood will
  416. * simply be ignored.
  417. }
  418. const
  419. LC_REQ_DYLD = $80000000;
  420. { Constants for the cmd field of all load commands, the type }
  421. const
  422. LC_SEGMENT = $1; { segment of this file to be mapped }
  423. LC_SYMTAB = $2; { link-edit stab symbol table info }
  424. LC_SYMSEG = $3; { link-edit gdb symbol table info (obsolete) }
  425. LC_THREAD = $4; { thread }
  426. LC_UNIXTHREAD = $5; { unix thread (includes a stack) }
  427. LC_LOADFVMLIB = $6; { load a specified fixed VM shared library }
  428. LC_IDFVMLIB = $7; { fixed VM shared library identification }
  429. LC_IDENT = $8; { object identification info (obsolete) }
  430. LC_FVMFILE = $9; { fixed VM file inclusion (internal use) }
  431. LC_PREPAGE = $a; { prepage command (internal use) }
  432. LC_DYSYMTAB = $b; { dynamic link-edit symbol table info }
  433. LC_LOAD_DYLIB = $c; { load a dynamically linked shared library }
  434. LC_ID_DYLIB = $d; { dynamically linked shared lib ident }
  435. LC_LOAD_DYLINKER = $e; { load a dynamic linker }
  436. LC_ID_DYLINKER = $f; { dynamic linker identification }
  437. LC_PREBOUND_DYLIB = $10; { modules prebound for a dynamically linked shared library }
  438. LC_ROUTINES = $11; { image routines }
  439. LC_SUB_FRAMEWORK = $12; { sub framework }
  440. LC_SUB_UMBRELLA = $13; { sub umbrella }
  441. LC_SUB_CLIENT = $14; { sub client }
  442. LC_SUB_LIBRARY = $15; { sub library }
  443. LC_TWOLEVEL_HINTS = $16; { two-level namespace lookup hints }
  444. LC_PREBIND_CKSUM = $17; { prebind checksum }
  445. LC_LOAD_WEAK_DYLIB = $18 or LC_REQ_DYLD; { load a dynamically linked shared library that is allowed to be missing (all symbols are weak imported). }
  446. LC_SEGMENT_64 = $19; { 64-bit segment of this file to be mapped }
  447. LC_ROUTINES_64 = $1a; { 64-bit image routines }
  448. LC_UUID = $1b; { the uuid }
  449. LC_RPATH = $1c or LC_REQ_DYLD; { runpath additions }
  450. LC_CODE_SIGNATURE = $1d; { local of code signature }
  451. LC_SEGMENT_SPLIT_INFO = $1e; { local of info to split segments }
  452. LC_REEXPORT_DYLIB = $1f or LC_REQ_DYLD; { load and re-export dylib }
  453. LC_LAZY_LOAD_DYLIB = $20; { delay load of dylib until first use }
  454. LC_ENCRYPTION_INFO = $21; { encrypted segment information }
  455. {
  456. * A variable length string in a load command is represented by an lc_str
  457. * union. The strings are stored just after the load command structure and
  458. * the offset is from the start of the load command structure. The size
  459. * of the string is reflected in the cmdsize field of the load command.
  460. * Once again any padded bytes to bring the cmdsize field to a multiple
  461. * of 4 bytes must be zero.
  462. }
  463. { offset to the string }
  464. {$ifndef __LP64__}
  465. { pointer to the string }
  466. {$endif}
  467. type
  468. lc_str = record
  469. case longint of
  470. 0 : ( offset : uint32_t );
  471. 1 : ( ptr : ^char );
  472. end;
  473. {
  474. * The segment load command indicates that a part of this file is to be
  475. * mapped into the task's address space. The size of this segment in memory,
  476. * vmsize, maybe equal to or larger than the amount to map from this file,
  477. * filesize. The file is mapped starting at fileoff to the beginning of
  478. * the segment in memory, vmaddr. The rest of the memory of the segment,
  479. * if any, is allocated zero fill on demand. The segment's maximum virtual
  480. * memory protection and initial virtual memory protection are specified
  481. * by the maxprot and initprot fields. If the segment has sections then the
  482. * section structures directly follow the segment command and their size is
  483. * reflected in cmdsize.
  484. }
  485. { for 32-bit architectures }
  486. segment_command = record
  487. cmd : uint32_t; { LC_SEGMENT }
  488. cmdsize : uint32_t; { includes sizeof section structs }
  489. segname : array[0..15] of char; { segment name }
  490. vmaddr : uint32_t; { memory address of this segment }
  491. vmsize : uint32_t; { memory size of this segment }
  492. fileoff : uint32_t; { file offset of this segment }
  493. filesize : uint32_t; { amount to map from the file }
  494. maxprot : vm_prot_t; { maximum VM protection }
  495. initprot : vm_prot_t; { initial VM protection }
  496. nsects : uint32_t; { number of sections in segment }
  497. flags : uint32_t; { flags }
  498. end;
  499. psegment_command = ^segment_command;
  500. {
  501. * The 64-bit segment load command indicates that a part of this file is to be
  502. * mapped into a 64-bit task's address space. If the 64-bit segment has
  503. * sections then section_64 structures directly follow the 64-bit segment
  504. * command and their size is reflected in cmdsize.
  505. }
  506. { for 64-bit architectures }
  507. segment_command_64 = record
  508. cmd : uint32_t; { LC_SEGMENT_64 }
  509. cmdsize : uint32_t; { includes sizeof section_64 structs }
  510. segname : array[0..15] of char; { segment name }
  511. vmaddr : uint64_t; { memory address of this segment }
  512. vmsize : uint64_t; { memory size of this segment }
  513. fileoff : uint64_t; { file offset of this segment }
  514. filesize : uint64_t; { amount to map from the file }
  515. maxprot : vm_prot_t; { maximum VM protection }
  516. initprot : vm_prot_t; { initial VM protection }
  517. nsects : uint32_t; { number of sections in segment }
  518. flags : uint32_t; { flags }
  519. end;
  520. psegment_command_64 = ^segment_command_64;
  521. { Constants for the flags field of the segment_command }
  522. const
  523. SG_HIGHVM = $1; { the file contents for this segment is for }
  524. { the high part of the VM space, the low part }
  525. { is zero filled (for stacks in core files) }
  526. SG_FVMLIB = $2; { this segment is the VM that is allocated by }
  527. { a fixed VM library, for overlap checking in }
  528. { the link editor }
  529. SG_NORELOC = $4; { this segment has nothing that was relocated }
  530. { in it and nothing relocated to it, that is }
  531. { it maybe safely replaced without relocation }
  532. SG_PROTECTED_VERSION_1 = $8; { This segment is protected. If the }
  533. { segment starts at file offset 0, the }
  534. { first page of the segment is not }
  535. { protected. All other pages of the }
  536. { segment are protected. }
  537. {* A segment is made up of zero or more sections. Non-MH_OBJECT files have
  538. * all of their segments with the proper sections in each, and padded to the
  539. * specified segment alignment when produced by the link editor. The first
  540. * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header
  541. * and load commands of the object file before its first section. The zero
  542. * fill sections are always last in their segment (in all formats). This
  543. * allows the zeroed segment padding to be mapped into memory where zero fill
  544. * sections might be. The gigabyte zero fill sections, those with the section
  545. * type S_GB_ZEROFILL, can only be in a segment with sections of this type.
  546. * These segments are then placed after all other segments.
  547. *
  548. * The MH_OBJECT format has all of its sections in one segment for
  549. * compactness. There is no padding to a specified segment boundary and the
  550. * mach_header and load commands are not part of the segment.
  551. *
  552. * Sections with the same section name, sectname, going into the same segment,
  553. * segname, are combined by the link editor. The resulting section is aligned
  554. * to the maximum alignment of the combined sections and is the new section's
  555. * alignment. The combined sections are aligned to their original alignment in
  556. * the combined section. Any padded bytes to get the specified alignment are
  557. * zeroed.
  558. *
  559. * The format of the relocation entries referenced by the reloff and nreloc
  560. * fields of the section structure for mach object files is described in the
  561. * header file <reloc.h>. }
  562. type
  563. { for 32-bit architectures }
  564. section = record
  565. sectname : array[0..15] of char; { name of this section }
  566. segname : array[0..15] of char; { segment this section goes in }
  567. addr : uint32_t; { memory address of this section }
  568. size : uint32_t; { size in bytes of this section }
  569. offset : uint32_t; { file offset of this section }
  570. align : uint32_t; { section alignment (power of 2) }
  571. reloff : uint32_t; { file offset of relocation entries }
  572. nreloc : uint32_t; { number of relocation entries }
  573. flags : uint32_t; { flags (section type and attributes) }
  574. reserved1 : uint32_t; { reserved (for offset or index) }
  575. reserved2 : uint32_t; { reserved (for count or sizeof) }
  576. end;
  577. psection = ^section;
  578. { for 64-bit architectures }
  579. section_64 = record
  580. sectname : array[0..15] of char; { name of this section }
  581. segname : array[0..15] of char; { segment this section goes in }
  582. addr : uint64_t; { memory address of this section }
  583. size : uint64_t; { size in bytes of this section }
  584. offset : uint32_t; { file offset of this section }
  585. align : uint32_t; { section alignment (power of 2) }
  586. reloff : uint32_t; { file offset of relocation entries }
  587. nreloc : uint32_t; { number of relocation entries }
  588. flags : uint32_t; { flags (section type and attributes) }
  589. reserved1 : uint32_t; { reserved (for offset or index) }
  590. reserved2 : uint32_t; { reserved (for count or sizeof) }
  591. reserved3 : uint32_t; { reserved }
  592. end;
  593. psection_64 = ^section_64;
  594. {* The flags field of a section structure is separated into two parts a section
  595. * type and section attributes. The section types are mutually exclusive (it
  596. * can only have one type) but the section attributes are not (it may have more
  597. * than one attribute). }
  598. { 256 section types }
  599. const
  600. SECTION_TYPE = $000000ff; { Constants for the type of a section }
  601. SECTION_ATTRIBUTES = $ffffff00; { 24 section attributes }
  602. S_REGULAR = $0; { regular section }
  603. S_ZEROFILL = $1; { zero fill on demand section }
  604. S_CSTRING_LITERALS = $2; { section with only literal C strings }
  605. S_4BYTE_LITERALS = $3; { section with only 4 byte literals }
  606. S_8BYTE_LITERALS = $4; { section with only 8 byte literals }
  607. S_LITERAL_POINTERS = $5; { section with only pointers to literals }
  608. {* For the two types of symbol pointers sections and the symbol stubs section
  609. * they have indirect symbol table entries. For each of the entries in the
  610. * section the indirect symbol table entries, in corresponding order in the
  611. * indirect symbol table, start at the index stored in the reserved1 field
  612. * of the section structure. Since the indirect symbol table entries
  613. * correspond to the entries in the section the number of indirect symbol table
  614. * entries is inferred from the size of the section divided by the size of the
  615. * entries in the section. For symbol pointers sections the size of the entries
  616. * in the section is 4 bytes and for symbol stubs sections the byte size of the
  617. * stubs is stored in the reserved2 field of the section structure. }
  618. S_NON_LAZY_SYMBOL_POINTERS = $6; { section with only non-lazy symbol pointers }
  619. S_LAZY_SYMBOL_POINTERS = $7; { section with only lazy symbol pointers }
  620. S_SYMBOL_STUBS = $8; { section with only symbol stubs, byte size of stub in the reserved2 field }
  621. S_MOD_INIT_FUNC_POINTERS = $9; { section with only function pointers for initialization }
  622. S_MOD_TERM_FUNC_POINTERS = $a; { section with only function pointers for termination }
  623. S_COALESCED = $b; { section contains symbols that are to be coalesced }
  624. S_GB_ZEROFILL = $c; { zero fill on demand section (that can be larger than 4 gigabytes) }
  625. S_INTERPOSING = $d; { section with only pairs of function pointers for interposing }
  626. S_16BYTE_LITERALS = $e; { section with only 16 byte literals }
  627. S_DTRACE_DOF = $f; { section contains DTrace Object Format }
  628. S_LAZY_DYLIB_SYMBOL_POINTERS = $10; { section with only lazy symbol pointers to lazy loaded dylibs }
  629. {* Constants for the section attributes part of the flags field of a section structure. }
  630. SECTION_ATTRIBUTES_USR = $ff000000; { User setable attributes }
  631. S_ATTR_PURE_INSTRUCTIONS = $80000000; { section contains only true machine instructions }
  632. S_ATTR_NO_TOC = $40000000; { section contains coalesced symbols }
  633. { that are not to be in a ranlib table of contents }
  634. S_ATTR_STRIP_STATIC_SYMS = $20000000; { ok to strip static symbols this section }
  635. { in files with the MH_DYLDLINK flag }
  636. S_ATTR_NO_DEAD_STRIP = $10000000; { no dead stripping }
  637. S_ATTR_LIVE_SUPPORT = $08000000; { blocks are live if they reference live blocks }
  638. S_ATTR_SELF_MODIFYING_CODE = $04000000; { Used with i386 code stubs written on by dyld }
  639. {
  640. * If a segment contains any sections marked with S_ATTR_DEBUG then all
  641. * sections in that segment must have this attribute. No section other than
  642. * a section marked with this attribute may reference the contents of this
  643. * section. A section with this attribute may contain no symbols and must have
  644. * a section type S_REGULAR. The static linker will not copy section contents
  645. * from sections with this attribute into its output file. These sections
  646. * generally contain DWARF debugging info.
  647. } { a debug section }
  648. S_ATTR_DEBUG = $02000000;
  649. { system setable attributes }
  650. SECTION_ATTRIBUTES_SYS = $00ffff00;
  651. { section contains some
  652. machine instructions }
  653. S_ATTR_SOME_INSTRUCTIONS = $00000400;
  654. { section has external
  655. relocation entries }
  656. S_ATTR_EXT_RELOC = $00000200;
  657. { section has local
  658. relocation entries }
  659. S_ATTR_LOC_RELOC = $00000100;
  660. {
  661. * The names of segments and sections in them are mostly meaningless to the
  662. * link-editor. But there are few things to support traditional UNIX
  663. * executables that require the link-editor and assembler to use some names
  664. * agreed upon by convention.
  665. *
  666. * The initial protection of the "__TEXT" segment has write protection turned
  667. * off (not writeable).
  668. *
  669. * The link-editor will allocate common symbols at the end of the "__common"
  670. * section in the "__DATA" segment. It will create the section and segment
  671. * if needed.
  672. }
  673. { The currently known segment names and the section names in those segments }
  674. SEG_PAGEZERO = '__PAGEZERO'; { the pagezero segment which has no }
  675. { protections and catches NULL references for MH_EXECUTE files }
  676. SEG_TEXT = '__TEXT'; { the tradition UNIX text segment }
  677. SECT_TEXT = '__text'; { the real text part of the text }
  678. SECT_FVMLIB_INIT0 = '__fvmlib_init0'; { the fvmlib initialization section }
  679. SECT_FVMLIB_INIT1 = '__fvmlib_init1'; { the section following the fvmlib initialization section }
  680. SEG_DATA = '__DATA'; { the tradition UNIX data segment }
  681. SECT_DATA = '__data'; { the real initialized data section no padding, no bss overlap }
  682. SECT_BSS = '__bss'; { the real uninitialized data section no padding }
  683. SECT_COMMON = '__common'; { the section common symbols are allocated in by the link editor }
  684. SEG_OBJC = '__OBJC'; { objective-C runtime segment }
  685. SECT_OBJC_SYMBOLS = '__symbol_table'; { symbol table }
  686. SECT_OBJC_MODULES = '__module_info'; { module information }
  687. SECT_OBJC_STRINGS = '__selector_strs'; { string table }
  688. SECT_OBJC_REFS = '__selector_refs'; { string table }
  689. SEG_ICON = '__ICON'; { the icon segment }
  690. SECT_ICON_HEADER = '__header'; { the icon headers }
  691. SECT_ICON_TIFF = '__tiff'; { the icons in tiff format }
  692. SEG_LINKEDIT = '__LINKEDIT'; { the segment containing all structs }
  693. { created and maintained by the linkeditor. }
  694. { Created with -seglinkedit option to ld(1) for MH_EXECUTE and FVMLIB file types only }
  695. SEG_UNIXSTACK = '__UNIXSTACK'; { the unix stack segment }
  696. SEG_IMPORT = '__IMPORT'; { the segment for the self (dyld) }
  697. { modifing code stubs that has read, write and execute permissions }
  698. {* Fixed virtual memory shared libraries are identified by two things. The
  699. * target pathname (the name of the library as found for execution), and the
  700. * minor version number. The address of where the headers are loaded is in
  701. * header_addr. (THIS IS OBSOLETE and no longer supported). }
  702. type
  703. fvmlib = record
  704. name : lc_str; { library's target pathname }
  705. minor_version : uint32_t; { library's minor version number }
  706. header_addr : uint32_t; { library's header address }
  707. end;
  708. {* A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
  709. * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library.
  710. * An object that uses a fixed virtual shared library also contains a
  711. * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses.
  712. * (THIS IS OBSOLETE and no longer supported). }
  713. fvmlib_command = record
  714. cmd : uint32_t; { LC_IDFVMLIB or LC_LOADFVMLIB }
  715. cmdsize : uint32_t; { includes pathname string }
  716. fvmlib : fvmlib; { the library identification }
  717. end;
  718. pfvmlib_command = ^fvmlib_command;
  719. {* Dynamicly linked shared libraries are identified by two things. The
  720. * pathname (the name of the library as found for execution), and the
  721. * compatibility version number. The pathname must match and the compatibility
  722. * number in the user of the library must be greater than or equal to the
  723. * library being used. The time stamp is used to record the time a library was
  724. * built and copied into user so it can be use to determined if the library used
  725. * at runtime is exactly the same as used to built the program. }
  726. dylib = record
  727. name : lc_str; { library's path name }
  728. timestamp : uint32_t; { library's build time stamp }
  729. current_version : uint32_t; { library's current version number }
  730. compatibility_version : uint32_t; { library's compatibility vers number }
  731. end;
  732. {* A dynamically linked shared library (filetype == MH_DYLIB in the mach header)
  733. * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library.
  734. * An object that uses a dynamically linked shared library also contains a
  735. * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or
  736. * LC_REEXPORT_DYLIB) for each library it uses. }
  737. dylib_command = record
  738. cmd : uint32_t; { LC_ID_DYLIB, LC_LOAD_DYLIB,WEAK_DYLIB, LC_REEXPORT_DYLIB }
  739. cmdsize : uint32_t; { includes pathname string }
  740. dylib : dylib; { the library identification }
  741. end;
  742. pdylib_command = ^dylib_command;
  743. {* A dynamically linked shared library may be a subframework of an umbrella
  744. * framework. If so it will be linked with "-umbrella umbrella_name" where
  745. * Where "umbrella_name" is the name of the umbrella framework. A subframework
  746. * can only be linked against by its umbrella framework or other subframeworks
  747. * that are part of the same umbrella framework. Otherwise the static link
  748. * editor produces an error and states to link against the umbrella framework.
  749. * The name of the umbrella framework for subframeworks is recorded in the
  750. * following structure. }
  751. sub_framework_command = record
  752. cmd : uint32_t; { LC_SUB_FRAMEWORK }
  753. cmdsize : uint32_t; { includes umbrella string }
  754. umbrella : lc_str; { the umbrella framework name }
  755. end;
  756. psub_framework_command = ^sub_framework_command;
  757. {* For dynamically linked shared libraries that are subframework of an umbrella
  758. * framework they can allow clients other than the umbrella framework or other
  759. * subframeworks in the same umbrella framework. To do this the subframework
  760. * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load
  761. * command is created for each -allowable_client flag. The client_name is
  762. * usually a framework name. It can also be a name used for bundles clients
  763. * where the bundle is built with "-client_name client_name". }
  764. sub_client_command = record
  765. cmd : uint32_t; { LC_SUB_CLIENT }
  766. cmdsize : uint32_t; { includes client string }
  767. client : lc_str; { the client name }
  768. end;
  769. psub_client_command = ^sub_client_command;
  770. {
  771. * A dynamically linked shared library may be a sub_umbrella of an umbrella
  772. * framework. If so it will be linked with "-sub_umbrella umbrella_name" where
  773. * Where "umbrella_name" is the name of the sub_umbrella framework. When
  774. * staticly linking when -twolevel_namespace is in effect a twolevel namespace
  775. * umbrella framework will only cause its subframeworks and those frameworks
  776. * listed as sub_umbrella frameworks to be implicited linked in. Any other
  777. * dependent dynamic libraries will not be linked it when -twolevel_namespace
  778. * is in effect. The primary library recorded by the static linker when
  779. * resolving a symbol in these libraries will be the umbrella framework.
  780. * Zero or more sub_umbrella frameworks may be use by an umbrella framework.
  781. * The name of a sub_umbrella framework is recorded in the following structure.
  782. }
  783. sub_umbrella_command = record
  784. cmd : uint32_t; { LC_SUB_UMBRELLA }
  785. cmdsize : uint32_t; { includes sub_umbrella string }
  786. sub_umbrella : lc_str; { the sub_umbrella framework name }
  787. end;
  788. {* A dynamically linked shared library may be a sub_library of another shared
  789. * library. If so it will be linked with "-sub_library library_name" where
  790. * Where "library_name" is the name of the sub_library shared library. When
  791. * staticly linking when -twolevel_namespace is in effect a twolevel namespace
  792. * shared library will only cause its subframeworks and those frameworks
  793. * listed as sub_umbrella frameworks and libraries listed as sub_libraries to
  794. * be implicited linked in. Any other dependent dynamic libraries will not be
  795. * linked it when -twolevel_namespace is in effect. The primary library
  796. * recorded by the static linker when resolving a symbol in these libraries
  797. * will be the umbrella framework (or dynamic library). Zero or more sub_library
  798. * shared libraries may be use by an umbrella framework or (or dynamic library).
  799. * The name of a sub_library framework is recorded in the following structure.
  800. * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".}
  801. sub_library_command = record
  802. cmd : uint32_t; { LC_SUB_LIBRARY }
  803. cmdsize : uint32_t; { includes sub_library string }
  804. sub_library : lc_str; { the sub_library name }
  805. end;
  806. psub_library_command = ^sub_library_command;
  807. {* A program (filetype == MH_EXECUTE) that is
  808. * prebound to its dynamic libraries has one of these for each library that
  809. * the static linker used in prebinding. It contains a bit vector for the
  810. * modules in the library. The bits indicate which modules are bound (1) and
  811. * which are not (0) from the library. The bit for module 0 is the low bit
  812. * of the first byte. So the bit for the Nth module is:
  813. * (linked_modules[N/8] >> N%8) & 1 }
  814. prebound_dylib_command = record
  815. cmd : uint32_t; { LC_PREBOUND_DYLIB }
  816. cmdsize : uint32_t; { includes strings }
  817. name : lc_str; { library's path name }
  818. nmodules : uint32_t; { number of modules in library }
  819. linked_modules : lc_str; { bit vector of linked modules }
  820. end;
  821. pprebound_dylib_command = ^prebound_dylib_command;
  822. {* A program that uses a dynamic linker contains a dylinker_command to identify
  823. * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker
  824. * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER).
  825. * A file can have at most one of these.}
  826. dylinker_command = record
  827. cmd : uint32_t; { LC_ID_DYLINKER or LC_LOAD_DYLINKER }
  828. cmdsize : uint32_t; { includes pathname string }
  829. name : lc_str; { dynamic linker's path name }
  830. end;
  831. pdylinker_command = ^dylinker_command;
  832. {
  833. * Thread commands contain machine-specific data structures suitable for
  834. * use in the thread state primitives. The machine specific data structures
  835. * follow the struct thread_command as follows.
  836. * Each flavor of machine specific data structure is preceded by an unsigned
  837. * long constant for the flavor of that data structure, an uint32_t
  838. * that is the count of longs of the size of the state data structure and then
  839. * the state data structure follows. This triple may be repeated for many
  840. * flavors. The constants for the flavors, counts and state data structure
  841. * definitions are expected to be in the header file <machine/thread_status.h>.
  842. * These machine specific data structures sizes must be multiples of
  843. * 4 bytes The cmdsize reflects the total size of the thread_command
  844. * and all of the sizes of the constants for the flavors, counts and state
  845. * data structures.
  846. *
  847. * For executable objects that are unix processes there will be one
  848. * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.
  849. * This is the same as a LC_THREAD, except that a stack is automatically
  850. * created (based on the shell's limit for the stack size). Command arguments
  851. * and environment variables are copied onto that stack.
  852. }
  853. thread_command = record
  854. cmd : uint32_t; { LC_THREAD or LC_UNIXTHREAD }
  855. cmdsize : uint32_t; { total size of this command }
  856. flavor : uint32_t; { uint32_t flavor flavor of thread state }
  857. count : uint32_t; { uint32_t count count of longs in thread state }
  858. { struct XXX_thread_state state thread state for this flavor }
  859. { ... }
  860. end;
  861. pthread_command = ^thread_command;
  862. {* The routines command contains the address of the dynamic shared library
  863. * initialization routine and an index into the module table for the module
  864. * that defines the routine. Before any modules are used from the library the
  865. * dynamic linker fully binds the module that defines the initialization routine
  866. * and then calls it. This gets called before any module initialization
  867. * routines (used for C++ static constructors) in the library. }
  868. { for 32-bit architectures }
  869. routines_command = record
  870. cmd : uint32_t; { LC_ROUTINES }
  871. cmdsize : uint32_t; { total size of this command }
  872. init_address : uint32_t; { address of initialization routine }
  873. init_module : uint32_t; { index into the module table that the init routine is defined in }
  874. reserved1 : uint32_t;
  875. reserved2 : uint32_t;
  876. reserved3 : uint32_t;
  877. reserved4 : uint32_t;
  878. reserved5 : uint32_t;
  879. reserved6 : uint32_t;
  880. end;
  881. proutines_command = ^routines_command;
  882. { * The 64-bit routines command. Same use as above. }
  883. { for 64-bit architectures }
  884. routines_command_64 = record
  885. cmd : uint32_t; { LC_ROUTINES_64 }
  886. cmdsize : uint32_t; { total size of this command }
  887. init_address : uint64_t; { address of initialization routine }
  888. init_module : uint64_t; { index into the module table that }
  889. { the init routine is defined in }
  890. reserved1 : uint64_t;
  891. reserved2 : uint64_t;
  892. reserved3 : uint64_t;
  893. reserved4 : uint64_t;
  894. reserved5 : uint64_t;
  895. reserved6 : uint64_t;
  896. end;
  897. proutines_command_64 = ^routines_command_64;
  898. {* The symtab_command contains the offsets and sizes of the link-edit 4.3BSD
  899. * "stab" style symbol table information as described in the header files
  900. * <nlist.h> and <stab.h>.
  901. }
  902. symtab_command = record
  903. cmd : uint32_t; { LC_SYMTAB }
  904. cmdsize : uint32_t; { sizeof(struct symtab_command) }
  905. symoff : uint32_t; { symbol table offset }
  906. nsyms : uint32_t; { number of symbol table entries }
  907. stroff : uint32_t; { string table offset }
  908. strsize : uint32_t; { string table size in bytes }
  909. end;
  910. psymtab_command = ^symtab_command;
  911. {
  912. * This is the second set of the symbolic information which is used to support
  913. * the data structures for the dynamically link editor.
  914. *
  915. * The original set of symbolic information in the symtab_command which contains
  916. * the symbol and string tables must also be present when this load command is
  917. * present. When this load command is present the symbol table is organized
  918. * into three groups of symbols:
  919. * local symbols (static and debugging symbols) - grouped by module
  920. * defined external symbols - grouped by module (sorted by name if not lib)
  921. * undefined external symbols (sorted by name if MH_BINDATLOAD is not set,
  922. * and in order the were seen by the static
  923. * linker if MH_BINDATLOAD is set)
  924. * In this load command there are offsets and counts to each of the three groups
  925. * of symbols.
  926. *
  927. * This load command contains a the offsets and sizes of the following new
  928. * symbolic information tables:
  929. * table of contents
  930. * module table
  931. * reference symbol table
  932. * indirect symbol table
  933. * The first three tables above (the table of contents, module table and
  934. * reference symbol table) are only present if the file is a dynamically linked
  935. * shared library. For executable and object modules, which are files
  936. * containing only one module, the information that would be in these three
  937. * tables is determined as follows:
  938. * table of contents - the defined external symbols are sorted by name
  939. * module table - the file contains only one module so everything in the
  940. * file is part of the module.
  941. * reference symbol table - is the defined and undefined external symbols
  942. *
  943. * For dynamically linked shared library files this load command also contains
  944. * offsets and sizes to the pool of relocation entries for all sections
  945. * separated into two groups:
  946. * external relocation entries
  947. * local relocation entries
  948. * For executable and object modules the relocation entries continue to hang
  949. * off the section structures.
  950. }
  951. dysymtab_command = record
  952. cmd : uint32_t; { LC_DYSYMTAB }
  953. cmdsize : uint32_t; { sizeof(struct dysymtab_command) }
  954. {
  955. * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
  956. * are grouped into the following three groups:
  957. * local symbols (further grouped by the module they are from)
  958. * defined external symbols (further grouped by the module they are from)
  959. * undefined symbols
  960. *
  961. * The local symbols are used only for debugging. The dynamic binding
  962. * process may have to use them to indicate to the debugger the local
  963. * symbols for a module that is being bound.
  964. *
  965. * The last two groups are used by the dynamic binding process to do the
  966. * binding (indirectly through the module table and the reference symbol
  967. * table when this is a dynamically linked shared library file).
  968. }
  969. ilocalsym : uint32_t; { index to local symbols }
  970. nlocalsym : uint32_t; { number of local symbols }
  971. iextdefsym : uint32_t; { index to externally defined symbols }
  972. nextdefsym : uint32_t; { number of externally defined symbols }
  973. iundefsym : uint32_t; { index to undefined symbols }
  974. nundefsym : uint32_t; { number of undefined symbols }
  975. {
  976. * For the for the dynamic binding process to find which module a symbol
  977. * is defined in the table of contents is used (analogous to the ranlib
  978. * structure in an archive) which maps defined external symbols to modules
  979. * they are defined in. This exists only in a dynamically linked shared
  980. * library file. For executable and object modules the defined external
  981. * symbols are sorted by name and is use as the table of contents.
  982. }
  983. tocoff : uint32_t; { file offset to table of contents }
  984. ntoc : uint32_t; { number of entries in table of contents }
  985. {
  986. * To support dynamic binding of "modules" (whole object files) the symbol
  987. * table must reflect the modules that the file was created from. This is
  988. * done by having a module table that has indexes and counts into the merged
  989. * tables for each module. The module structure that these two entries
  990. * refer to is described below. This exists only in a dynamically linked
  991. * shared library file. For executable and object modules the file only
  992. * contains one module so everything in the file belongs to the module.
  993. }
  994. modtaboff : uint32_t; { file offset to module table }
  995. nmodtab : uint32_t; { number of module table entries }
  996. {
  997. * To support dynamic module binding the module structure for each module
  998. * indicates the external references (defined and undefined) each module
  999. * makes. For each module there is an offset and a count into the
  1000. * reference symbol table for the symbols that the module references.
  1001. * This exists only in a dynamically linked shared library file. For
  1002. * executable and object modules the defined external symbols and the
  1003. * undefined external symbols indicates the external references.
  1004. }
  1005. extrefsymoff : uint32_t; { offset to referenced symbol table }
  1006. nextrefsyms : uint32_t; { number of referenced symbol table entries }
  1007. {
  1008. * The sections that contain "symbol pointers" and "routine stubs" have
  1009. * indexes and (implied counts based on the size of the section and fixed
  1010. * size of the entry) into the "indirect symbol" table for each pointer
  1011. * and stub. For every section of these two types the index into the
  1012. * indirect symbol table is stored in the section header in the field
  1013. * reserved1. An indirect symbol table entry is simply a 32bit index into
  1014. * the symbol table to the symbol that the pointer or stub is referring to.
  1015. * The indirect symbol table is ordered to match the entries in the section.
  1016. }
  1017. indirectsymoff : uint32_t; { file offset to the indirect symbol table }
  1018. nindirectsyms : uint32_t; { number of indirect symbol table entries }
  1019. { * To support relocating an individual module in a library file quickly the
  1020. * external relocation entries for each module in the library need to be
  1021. * accessed efficiently. Since the relocation entries can't be accessed
  1022. * through the section headers for a library file they are separated into
  1023. * groups of local and external entries further grouped by module. In this
  1024. * case the presents of this load command who's extreloff, nextrel,
  1025. * locreloff and nlocrel fields are non-zero indicates that the relocation
  1026. * entries of non-merged sections are not referenced through the section
  1027. * structures (and the reloff and nreloc fields in the section headers are
  1028. * set to zero).
  1029. *
  1030. * Since the relocation entries are not accessed through the section headers
  1031. * this requires the r_address field to be something other than a section
  1032. * offset to identify the item to be relocated. In this case r_address is
  1033. * set to the offset from the vmaddr of the first LC_SEGMENT command.
  1034. * For MH_SPLIT_SEGS images r_address is set to the the offset from the
  1035. * vmaddr of the first read-write LC_SEGMENT command.
  1036. *
  1037. * The relocation entries are grouped by module and the module table
  1038. * entries have indexes and counts into them for the group of external
  1039. * relocation entries for that the module.
  1040. *
  1041. * For sections that are merged across modules there must not be any
  1042. * remaining external relocation entries for them (for merged sections
  1043. * remaining relocation entries must be local).
  1044. }
  1045. extreloff : uint32_t; { offset to external relocation entries }
  1046. nextrel : uint32_t; { number of external relocation entries }
  1047. { * All the local relocation entries are grouped together (they are not
  1048. * grouped by their module since they are only used if the object is moved
  1049. * from it staticly link edited address). }
  1050. locreloff : uint32_t; { offset to local relocation entries }
  1051. nlocrel : uint32_t; { number of local relocation entries }
  1052. end;
  1053. {
  1054. * An indirect symbol table entry is simply a 32bit index into the symbol table
  1055. * to the symbol that the pointer or stub is refering to. Unless it is for a
  1056. * non-lazy symbol pointer section for a defined symbol which strip(1) as
  1057. * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the
  1058. * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.
  1059. }
  1060. const
  1061. INDIRECT_SYMBOL_LOCAL = $80000000;
  1062. INDIRECT_SYMBOL_ABS = $40000000;
  1063. type
  1064. dylib_table_of_contents = record { a table of contents entry }
  1065. symbol_index : uint32_t; { the defined external symbol (index into the symbol table) }
  1066. module_index : uint32_t; { index into the module table this symbol is defined in }
  1067. end;
  1068. dylib_module = record { a module table entry }
  1069. module_name : uint32_t; { the module name (index into string table) }
  1070. iextdefsym : uint32_t; { index into externally defined symbols }
  1071. nextdefsym : uint32_t; { number of externally defined symbols }
  1072. irefsym : uint32_t; { index into reference symbol table }
  1073. nrefsym : uint32_t; { number of reference symbol table entries }
  1074. ilocalsym : uint32_t; { index into symbols for local symbols }
  1075. nlocalsym : uint32_t; { number of local symbols }
  1076. iextrel : uint32_t; { index into external relocation entries }
  1077. nextrel : uint32_t; { number of external relocation entries }
  1078. iinit_iterm : uint32_t; { low 16 bits are the index into the init
  1079. section, high 16 bits are the index into
  1080. the term section }
  1081. ninit_nterm : uint32_t; { low 16 bits are the number of init section
  1082. entries, high 16 bits are the number of
  1083. term section entries }
  1084. objc_module_info_addr : uint32_t; { for this module address of the start of the (__OBJC,__module_info) section }
  1085. objc_module_info_size : uint32_t; { for this module size of the (__OBJC,__module_info) section }
  1086. end;
  1087. dylib_module_64 = record { a 64-bit module table entry }
  1088. module_name : uint32_t; { the module name (index into string table) }
  1089. iextdefsym : uint32_t; { index into externally defined symbols }
  1090. nextdefsym : uint32_t; { number of externally defined symbols }
  1091. irefsym : uint32_t; { index into reference symbol table }
  1092. nrefsym : uint32_t; { number of reference symbol table entries }
  1093. ilocalsym : uint32_t; { index into symbols for local symbols }
  1094. nlocalsym : uint32_t; { number of local symbols }
  1095. iextrel : uint32_t; { index into external relocation entries }
  1096. nextrel : uint32_t; { number of external relocation entries }
  1097. iinit_iterm : uint32_t; { low 16 bits are the index into the init
  1098. section, high 16 bits are the index into
  1099. the term section }
  1100. ninit_nterm : uint32_t; { low 16 bits are the number of init section
  1101. entries, high 16 bits are the number of
  1102. term section entries }
  1103. objc_module_info_size : uint32_t; { for this module size of the (__OBJC,__module_info) section }
  1104. objc_module_info_addr : uint64_t; { for this module address of the start of the (__OBJC,__module_info) section }
  1105. end;
  1106. {
  1107. * The entries in the reference symbol table are used when loading the module
  1108. * (both by the static and dynamic link editors) and if the module is unloaded
  1109. * or replaced. Therefore all external symbols (defined and undefined) are
  1110. * listed in the module's reference table. The flags describe the type of
  1111. * reference that is being made. The constants for the flags are defined in
  1112. * <mach-o/nlist.h> as they are also used for symbol table entries.
  1113. }
  1114. { index into the symbol table }
  1115. { flags to indicate the type of reference }
  1116. dylib_reference = record
  1117. flag0 : longint;
  1118. end;
  1119. { const
  1120. bm_dylib_reference_isym = $FFFFFF;
  1121. bp_dylib_reference_isym = 0;
  1122. bm_dylib_reference_flags = $FF000000;
  1123. bp_dylib_reference_flags = 24;
  1124. function isym(var a : dylib_reference) : uint32_t;
  1125. procedure set_isym(var a : dylib_reference; __isym : uint32_t);
  1126. function flags(var a : dylib_reference) : uint32_t;
  1127. procedure set_flags(var a : dylib_reference; __flags : uint32_t);}
  1128. {* The twolevel_hints_command contains the offset and number of hints in the
  1129. * two-level namespace lookup hints table.}
  1130. type
  1131. twolevel_hints_command = record
  1132. cmd : uint32_t; { LC_TWOLEVEL_HINTS }
  1133. cmdsize : uint32_t; { sizeof(struct twolevel_hints_command) }
  1134. offset : uint32_t; { offset to the hint table }
  1135. nhints : uint32_t; { number of hints in the hint table }
  1136. end;
  1137. {
  1138. * The entries in the two-level namespace lookup hints table are twolevel_hint
  1139. * structs. These provide hints to the dynamic link editor where to start
  1140. * looking for an undefined symbol in a two-level namespace image. The
  1141. * isub_image field is an index into the sub-images (sub-frameworks and
  1142. * sub-umbrellas list) that made up the two-level image that the undefined
  1143. * symbol was found in when it was built by the static link editor. If
  1144. * isub-image is 0 the the symbol is expected to be defined in library and not
  1145. * in the sub-images. If isub-image is non-zero it is an index into the array
  1146. * of sub-images for the umbrella with the first index in the sub-images being
  1147. * 1. The array of sub-images is the ordered list of sub-images of the umbrella
  1148. * that would be searched for a symbol that has the umbrella recorded as its
  1149. * primary library. The table of contents index is an index into the
  1150. * library's table of contents. This is used as the starting point of the
  1151. * binary search or a directed linear search.
  1152. }
  1153. { index into the sub images }
  1154. { index into the table of contents }
  1155. twolevel_hint = record
  1156. flag0 : longint;
  1157. end;
  1158. { const
  1159. bm_twolevel_hint_isub_image = $FF;
  1160. bp_twolevel_hint_isub_image = 0;
  1161. bm_twolevel_hint_itoc = $FFFFFF00;
  1162. bp_twolevel_hint_itoc = 8;
  1163. function isub_image(var a : twolevel_hint) : uint32_t;
  1164. procedure set_isub_image(var a : twolevel_hint; __isub_image : uint32_t);
  1165. function itoc(var a : twolevel_hint) : uint32_t;
  1166. procedure set_itoc(var a : twolevel_hint; __itoc : uint32_t);
  1167. }
  1168. type
  1169. {* The prebind_cksum_command contains the value of the original check sum for
  1170. * prebound files or zero. When a prebound file is first created or modified
  1171. * for other than updating its prebinding information the value of the check sum
  1172. * is set to zero. When the file has it prebinding re-done and if the value of
  1173. * the check sum is zero the original check sum is calculated and stored in
  1174. * cksum field of this load command in the output file. If when the prebinding
  1175. * is re-done and the cksum field is non-zero it is left unchanged from the
  1176. * input file. }
  1177. prebind_cksum_command = record
  1178. cmd : uint32_t; { LC_PREBIND_CKSUM }
  1179. cmdsize : uint32_t; { sizeof(struct prebind_cksum_command) }
  1180. cksum : uint32_t; { the check sum or zero }
  1181. end;
  1182. pprebind_cksum_command = ^prebind_cksum_command;
  1183. {* The uuid load command contains a single 128-bit unique random number that
  1184. * identifies an object produced by the static link editor. }
  1185. uuid_command = record
  1186. cmd : uint32_t; { LC_UUID }
  1187. cmdsize : uint32_t; { sizeof(struct uuid_command) }
  1188. uuid : array[0..15] of uint8_t; { the 128-bit uuid }
  1189. end;
  1190. puuid_command = ^uuid_command;
  1191. {* The rpath_command contains a path which at runtime should be added to
  1192. * the current run path used to find @rpath prefixed dylibs.}
  1193. rpath_command = record
  1194. cmd : uint32_t; { LC_RPATH }
  1195. cmdsize : uint32_t; { includes string }
  1196. path : lc_str; { path to add to run path }
  1197. end;
  1198. prpath_command = ^rpath_command;
  1199. {* The linkedit_data_command contains the offsets and sizes of a blob
  1200. * of data in the __LINKEDIT segment.}
  1201. linkedit_data_command = record
  1202. cmd : uint32_t; { LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO }
  1203. cmdsize : uint32_t; { sizeof(struct linkedit_data_command) }
  1204. dataoff : uint32_t; { file offset of data in __LINKEDIT segment }
  1205. datasize : uint32_t; { file size of data in __LINKEDIT segment }
  1206. end;
  1207. plinkedit_data_command = ^linkedit_data_command;
  1208. {* The encryption_info_command contains the file offset and size of an
  1209. * of an encrypted segment.}
  1210. encryption_info_command = record
  1211. cmd : uint32_t; { LC_ENCRYPTION_INFO }
  1212. cmdsize : uint32_t; { sizeof(struct encryption_info_command) }
  1213. cryptoff : uint32_t; { file offset of encrypted range }
  1214. cryptsize : uint32_t; { file size of encrypted range }
  1215. cryptid : uint32_t; { which enryption system, 0 means not-encrypted yet }
  1216. end;
  1217. pencryption_info_command = ^encryption_info_command;
  1218. {* The symseg_command contains the offset and size of the GNU style
  1219. * symbol table information as described in the header file <symseg.h>.
  1220. * The symbol roots of the symbol segments must also be aligned properly
  1221. * in the file. So the requirement of keeping the offsets aligned to a
  1222. * multiple of a 4 bytes translates to the length field of the symbol
  1223. * roots also being a multiple of a long. Also the padding must again be
  1224. * zeroed. (THIS IS OBSOLETE and no longer supported). }
  1225. symseg_command = record
  1226. cmd : uint32_t; { LC_SYMSEG }
  1227. cmdsize : uint32_t; { sizeof(struct symseg_command) }
  1228. offset : uint32_t; { symbol segment offset }
  1229. size : uint32_t; { symbol segment size in bytes }
  1230. end;
  1231. psymseg_command = ^symseg_command;
  1232. {* The ident_command contains a free format string table following the
  1233. * ident_command structure. The strings are null terminated and the size of
  1234. * the command is padded out with zero bytes to a multiple of 4 bytes/
  1235. * (THIS IS OBSOLETE and no longer supported).}
  1236. ident_command = record
  1237. cmd : uint32_t; { LC_IDENT }
  1238. cmdsize : uint32_t; { strings that follow this command }
  1239. end;
  1240. pident_command = ^ident_command;
  1241. {* The fvmfile_command contains a reference to a file to be loaded at the
  1242. * specified virtual address. (Presently, this command is reserved for
  1243. * internal use. The kernel ignores this command when loading a program into
  1244. * memory). }
  1245. fvmfile_command = record
  1246. cmd : uint32_t; { LC_FVMFILE }
  1247. cmdsize : uint32_t; { includes pathname string }
  1248. name : lc_str; { files pathname }
  1249. header_addr : uint32_t; { files virtual address }
  1250. end;
  1251. pfvmfile_command = ^fvmfile_command;
  1252. {* This header file describes the structures of the file format for "fat"
  1253. * architecture specific file (wrapper design). At the begining of the file
  1254. * there is one fat_header structure followed by a number of fat_arch
  1255. * structures. For each architecture in the file, specified by a pair of
  1256. * cputype and cpusubtype, the fat_header describes the file offset, file
  1257. * size and alignment in the file of the architecture specific member.
  1258. * The padded bytes in the file to place each member on it's specific alignment
  1259. * are defined to be read as zeros and can be left as "holes" if the file system
  1260. * can support them as long as they read as zeros.
  1261. *
  1262. * All structures defined here are always written and read to/from disk
  1263. * in big-endian order.}
  1264. {* <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types
  1265. * and contains the constants for the possible values of these types.}
  1266. const
  1267. FAT_MAGIC = $cafebabe;
  1268. FAT_CIGAM = $bebafeca;
  1269. type
  1270. fat_header = record
  1271. magic : uint32_t; { FAT_MAGIC }
  1272. nfat_arch : uint32_t; { number of structs that follow }
  1273. end;
  1274. fat_arch = record
  1275. cputype : cpu_type_t; { cpu specifier (int) }
  1276. cpusubtype : cpu_subtype_t; { machine specifier (int) }
  1277. offset : uint32_t; { file offset to this object file }
  1278. size : uint32_t; { size of this object file }
  1279. align : uint32_t; { alignment as a power of 2 }
  1280. end;
  1281. {
  1282. * Format of a symbol table entry of a Mach-O file for 32-bit architectures.
  1283. * Modified from the BSD format. The modifications from the original format
  1284. * were changing n_other (an unused field) to n_sect and the addition of the
  1285. * N_SECT type. These modifications are required to support symbols in a larger
  1286. * number of sections not just the three sections (text, data and bss) in a BSD
  1287. * file.
  1288. }
  1289. type
  1290. nlist = record
  1291. n_un : record
  1292. case longint of
  1293. {$ifndef __LP64__}
  1294. 0 : ( n_name : Pchar ); { for use when in-core }
  1295. {$endif}
  1296. 1 : ( n_strx : int32_t ); { index into the string table }
  1297. end;
  1298. n_type : uint8_t; { type flag, see below }
  1299. n_sect : uint8_t; { section number or NO_SECT }
  1300. n_desc : int16_t; { see <mach-o/stab.h> }
  1301. n_value : uint32_t; { value of this symbol (or stab offset) }
  1302. end;
  1303. pnlist = ^nlist;
  1304. {* This is the symbol table entry structure for 64-bit architectures.}
  1305. nlist_64 = record
  1306. n_un : record
  1307. case longint of
  1308. 0 : ( n_strx : uint32_t ); { index into the string table }
  1309. end;
  1310. n_type : uint8_t; { type flag, see below }
  1311. n_sect : uint8_t; { section number or NO_SECT }
  1312. n_desc : uint16_t; { see <mach-o/stab.h> }
  1313. n_value : uint64_t; { value of this symbol (or stab offset) }
  1314. end;
  1315. pnlist_64 = ^nlist_64;
  1316. {* Symbols with a index into the string table of zero (n_un.n_strx == 0) are
  1317. * defined to have a null, "", name. Therefore all string indexes to non null
  1318. * names must not have a zero string index. This is bit historical information
  1319. * that has never been well documented. }
  1320. {* The n_type field really contains four fields:
  1321. * unsigned char N_STAB:3,
  1322. * N_PEXT:1,
  1323. * N_TYPE:3,
  1324. * N_EXT:1;
  1325. * which are used via the following masks.}
  1326. const
  1327. N_STAB = $e0; { if any of these bits set, a symbolic debugging entry }
  1328. N_PEXT = $10; { private external symbol bit }
  1329. N_TYPE = $0e; { mask for the type bits }
  1330. N_EXT = $01; { external symbol bit, set for external symbols }
  1331. {* Only symbolic debugging entries have some of the N_STAB bits set and if any
  1332. * of these bits are set then it is a symbolic debugging entry (a stab). In
  1333. * which case then the values of the n_type field (the entire field) are given
  1334. * in <mach-o/stab.h> }
  1335. {* Values for N_TYPE bits of the n_type field. }
  1336. N_UNDF = $0; { undefined, n_sect == NO_SECT }
  1337. N_ABS = $2; { absolute, n_sect == NO_SECT }
  1338. N_SECT = $e; { defined in section number n_sect }
  1339. N_PBUD = $c; { prebound undefined (defined in a dylib) }
  1340. N_INDR = $a; { indirect }
  1341. {* If the type is N_INDR then the symbol is defined to be the same as another
  1342. * symbol. In this case the n_value field is an index into the string table
  1343. * of the other symbol's name. When the other symbol is defined then they both
  1344. * take on the defined type and value.}
  1345. {* If the type is N_SECT then the n_sect field contains an ordinal of the
  1346. * section the symbol is defined in. The sections are numbered from 1 and
  1347. * refer to sections in order they appear in the load commands for the file
  1348. * they are in. This means the same ordinal may very well refer to different
  1349. * sections in different files.
  1350. *
  1351. * The n_value field for all symbol table entries (including N_STAB's) gets
  1352. * updated by the link editor based on the value of it's n_sect field and where
  1353. * the section n_sect references gets relocated. If the value of the n_sect
  1354. * field is NO_SECT then it's n_value field is not changed by the link editor.}
  1355. NO_SECT = 0; { symbol is not in any section }
  1356. MAX_SECT = 255; { 1 thru 255 inclusive }
  1357. {* Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
  1358. * who's values (n_value) are non-zero. In which case the value of the n_value
  1359. * field is the size (in bytes) of the common symbol. The n_sect field is set
  1360. * to NO_SECT. The alignment of a common symbol may be set as a power of 2
  1361. * between 2^1 and 2^15 as part of the n_desc field using the macros below. If
  1362. * the alignment is not set (a value of zero) then natural alignment based on
  1363. * the size is used.}
  1364. { ----- Process manually -----
  1365. #define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f)
  1366. #define SET_COMM_ALIGN(n_desc,align) \
  1367. (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8))
  1368. }
  1369. {* To support the lazy binding of undefined symbols in the dynamic link-editor,
  1370. * the undefined symbols in the symbol table (the nlist structures) are marked
  1371. * with the indication if the undefined reference is a lazy reference or
  1372. * non-lazy reference. If both a non-lazy reference and a lazy reference is
  1373. * made to the same symbol the non-lazy reference takes precedence. A reference
  1374. * is lazy only when all references to that symbol are made through a symbol
  1375. * pointer in a lazy symbol pointer section.
  1376. *
  1377. * The implementation of marking nlist structures in the symbol table for
  1378. * undefined symbols will be to use some of the bits of the n_desc field as a
  1379. * reference type. The mask REFERENCE_TYPE will be applied to the n_desc field
  1380. * of an nlist structure for an undefined symbol to determine the type of
  1381. * undefined reference (lazy or non-lazy).
  1382. *
  1383. * The constants for the REFERENCE FLAGS are propagated to the reference table
  1384. * in a shared library file. In that case the constant for a defined symbol,
  1385. * REFERENCE_FLAG_DEFINED, is also used.}
  1386. { Reference type bits of the n_desc field of undefined symbols }
  1387. REFERENCE_TYPE = $7;
  1388. { types of references }
  1389. REFERENCE_FLAG_UNDEFINED_NON_LAZY = 0;
  1390. REFERENCE_FLAG_UNDEFINED_LAZY = 1;
  1391. REFERENCE_FLAG_DEFINED = 2;
  1392. REFERENCE_FLAG_PRIVATE_DEFINED = 3;
  1393. REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY = 4;
  1394. REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY = 5;
  1395. {* To simplify stripping of objects that use are used with the dynamic link
  1396. * editor, the static link editor marks the symbols defined an object that are
  1397. * referenced by a dynamicly bound object (dynamic shared libraries, bundles).
  1398. * With this marking strip knows not to strip these symbols.}
  1399. REFERENCED_DYNAMICALLY = $0010;
  1400. {* For images created by the static link editor with the -twolevel_namespace
  1401. * option in effect the flags field of the mach header is marked with
  1402. * MH_TWOLEVEL. And the binding of the undefined references of the image are
  1403. * determined by the static link editor. Which library an undefined symbol is
  1404. * bound to is recorded by the static linker in the high 8 bits of the n_desc
  1405. * field using the SET_LIBRARY_ORDINAL macro below. The ordinal recorded
  1406. * references the libraries listed in the Mach-O's LC_LOAD_DYLIB load commands
  1407. * in the order they appear in the headers. The library ordinals start from 1.
  1408. * For a dynamic library that is built as a two-level namespace image the
  1409. * undefined references from module defined in another use the same nlist struct
  1410. * an in that case SELF_LIBRARY_ORDINAL is used as the library ordinal. For
  1411. * defined symbols in all images they also must have the library ordinal set to
  1412. * SELF_LIBRARY_ORDINAL. The EXECUTABLE_ORDINAL refers to the executable
  1413. * image for references from plugins that refer to the executable that loads
  1414. * them.
  1415. *
  1416. * The DYNAMIC_LOOKUP_ORDINAL is for undefined symbols in a two-level namespace
  1417. * image that are looked up by the dynamic linker with flat namespace semantics.
  1418. * This ordinal was added as a feature in Mac OS X 10.3 by reducing the
  1419. * value of MAX_LIBRARY_ORDINAL by one. So it is legal for existing binaries
  1420. * or binaries built with older tools to have 0xfe (254) dynamic libraries. In
  1421. * this case the ordinal value 0xfe (254) must be treated as a library ordinal
  1422. * for compatibility.}
  1423. { was #define dname(params) para_def_expr }
  1424. { argument types are unknown }
  1425. { return type might be wrong }
  1426. // function GET_LIBRARY_ORDINAL(n_desc : longint) : longint;
  1427. { -- Process Manually ---
  1428. #define SET_LIBRARY_ORDINAL(n_desc,ordinal) \
  1429. (n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8))
  1430. }
  1431. const
  1432. SELF_LIBRARY_ORDINAL = $0;
  1433. MAX_LIBRARY_ORDINAL = $fd;
  1434. DYNAMIC_LOOKUP_ORDINAL = $fe;
  1435. EXECUTABLE_ORDINAL = $ff;
  1436. {* The bit 0x0020 of the n_desc field is used for two non-overlapping purposes
  1437. * and has two different symbolic names, N_NO_DEAD_STRIP and N_DESC_DISCARDED. }
  1438. {* The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
  1439. * relocatable .o file (MH_OBJECT filetype). And is used to indicate to the
  1440. * static link editor it is never to dead strip the symbol.}
  1441. N_NO_DEAD_STRIP = $0020; { symbol is not to be dead stripped }
  1442. {* The N_DESC_DISCARDED bit of the n_desc field never appears in linked image.
  1443. * But is used in very rare cases by the dynamic link editor to mark an in
  1444. * memory symbol as discared and longer used for linking. }
  1445. N_DESC_DISCARDED = $0020; { symbol is discarded }
  1446. {* The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that
  1447. * the undefined symbol is allowed to be missing and is to have the address of
  1448. * zero when missing. }
  1449. N_WEAK_REF = $0040; { symbol is weak referenced }
  1450. {* The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic
  1451. * linkers that the symbol definition is weak, allowing a non-weak symbol to
  1452. * also be used which causes the weak definition to be discared. Currently this
  1453. * is only supported for symbols in coalesed sections. }
  1454. N_WEAK_DEF = $0080; { coalesed symbol is a weak definition }
  1455. {* The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker
  1456. * that the undefined symbol should be resolved using flat namespace searching. }
  1457. N_REF_TO_WEAK = $0080; { reference to a weak symbol }
  1458. {* The N_ARM_THUMB_DEF bit of the n_desc field indicates that the symbol is
  1459. * a defintion of a Thumb function. }
  1460. N_ARM_THUMB_DEF = $0008; { symbol is a Thumb function (ARM) }
  1461. {* There are two known orders of table of contents for archives. The first is
  1462. * the order ranlib(1) originally produced and still produces without any
  1463. * options. This table of contents has the archive member name "__.SYMDEF"
  1464. * This order has the ranlib structures in the order the objects appear in the
  1465. * archive and the symbol names of those objects in the order of symbol table.
  1466. * The second know order is sorted by symbol name and is produced with the -s
  1467. * option to ranlib(1). This table of contents has the archive member name
  1468. * "__.SYMDEF SORTED" and many programs (notably the 1.0 version of ld(1) can't
  1469. * tell the difference between names because of the imbedded blank in the name
  1470. * and works with either table of contents). This second order is used by the
  1471. * post 1.0 link editor to produce faster linking. The original 1.0 version of
  1472. * ranlib(1) gets confused when it is run on a archive with the second type of
  1473. * table of contents because it and ar(1) which it uses use different ways to
  1474. * determined the member name (ar(1) treats all blanks in the name as
  1475. * significant and ranlib(1) only checks for the first one).}
  1476. const
  1477. SYMDEF = '__.SYMDEF';
  1478. SYMDEF_SORTED = '__.SYMDEF SORTED';
  1479. {
  1480. * Structure of the __.SYMDEF table of contents for an archive.
  1481. * __.SYMDEF begins with a long giving the size in bytes of the ranlib
  1482. * structures which immediately follow, and then continues with a string
  1483. * table consisting of a long giving the number of bytes of strings which
  1484. * follow and then the strings themselves. The ran_strx fields index the
  1485. * string table whose first byte is numbered 0.
  1486. }
  1487. type
  1488. ranlib = record
  1489. ran_un : record
  1490. case longint of
  1491. 0 : ( ran_strx : uint32_t );
  1492. 1 : ( ran_name : ^char );
  1493. end;
  1494. ran_off : uint32_t;
  1495. end;
  1496. type
  1497. {* Format of a relocation entry of a Mach-O file. Modified from the 4.3BSD
  1498. * format. The modifications from the original format were changing the value
  1499. * of the r_symbolnum field for "local" (r_extern == 0) relocation entries.
  1500. * This modification is required to support symbols in an arbitrary number of
  1501. * sections not just the three sections (text, data and bss) in a 4.3BSD file.
  1502. * Also the last 4 bits have had the r_type tag added to them. }
  1503. relocation_info = record
  1504. r_address : int32_t; { offset in the section to what is being relocated }
  1505. r_info : longint;
  1506. // r_symbolnum:24, {* symbol index if r_extern == 1 or section ordinal if r_extern == 0 *}
  1507. // r_pcrel:1; {* was relocated pc relative already *}
  1508. // r_length:2; {* 0=byte, 1=word, 2=long, 3=quad *}
  1509. // r_extern:1; {* does not include value of sym referenced *}
  1510. // r_type:4; {* if not 0, machine specific relocation type *}
  1511. end;
  1512. { absolute relocation type for Mach-O files }
  1513. const
  1514. R_ABS = 0;
  1515. R_SCATTERED = $80000000; { mask to be applied to the r_address field }
  1516. { of a relocation_info structure to tell that }
  1517. { is is really a scattered_relocation_info }
  1518. { stucture }
  1519. {
  1520. * The r_address is not really the address as it's name indicates but an offset.
  1521. * In 4.3BSD a.out objects this offset is from the start of the "segment" for
  1522. * which relocation entry is for (text or data). For Mach-O object files it is
  1523. * also an offset but from the start of the "section" for which the relocation
  1524. * entry is for. See comments in <mach-o/loader.h> about the r_address feild
  1525. * in images for used with the dynamic linker.
  1526. *
  1527. * In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal
  1528. * for the segment the symbol being relocated is in. These ordinals are the
  1529. * symbol types N_TEXT, N_DATA, N_BSS or N_ABS. In Mach-O object files these
  1530. * ordinals refer to the sections in the object file in the order their section
  1531. * structures appear in the headers of the object file they are in. The first
  1532. * section has the ordinal 1, the second 2, and so on. This means that the
  1533. * same ordinal in two different object files could refer to two different
  1534. * sections. And further could have still different ordinals when combined
  1535. * by the link-editor. The value R_ABS is used for relocation entries for
  1536. * absolute symbols which need no further relocation.
  1537. }
  1538. {
  1539. * For RISC machines some of the references are split across two instructions
  1540. * and the instruction does not contain the complete value of the reference.
  1541. * In these cases a second, or paired relocation entry, follows each of these
  1542. * relocation entries, using a PAIR r_type, which contains the other part of the
  1543. * reference not contained in the instruction. This other part is stored in the
  1544. * pair's r_address field. The exact number of bits of the other part of the
  1545. * reference store in the r_address field is dependent on the particular
  1546. * relocation type for the particular architecture.
  1547. }
  1548. {
  1549. * To make scattered loading by the link editor work correctly "local"
  1550. * relocation entries can't be used when the item to be relocated is the value
  1551. * of a symbol plus an offset (where the resulting expresion is outside the
  1552. * block the link editor is moving, a blocks are divided at symbol addresses).
  1553. * In this case. where the item is a symbol value plus offset, the link editor
  1554. * needs to know more than just the section the symbol was defined. What is
  1555. * needed is the actual value of the symbol without the offset so it can do the
  1556. * relocation correctly based on where the value of the symbol got relocated to
  1557. * not the value of the expression (with the offset added to the symbol value).
  1558. * So for the NeXT 2.0 release no "local" relocation entries are ever used when
  1559. * there is a non-zero offset added to a symbol. The "external" and "local"
  1560. * relocation entries remain unchanged.
  1561. *
  1562. * The implemention is quite messy given the compatibility with the existing
  1563. * relocation entry format. The ASSUMPTION is that a section will never be
  1564. * bigger than 2**24 - 1 (0x00ffffff or 16,777,215) bytes. This assumption
  1565. * allows the r_address (which is really an offset) to fit in 24 bits and high
  1566. * bit of the r_address field in the relocation_info structure to indicate
  1567. * it is really a scattered_relocation_info structure. Since these are only
  1568. * used in places where "local" relocation entries are used and not where
  1569. * "external" relocation entries are used the r_extern field has been removed.
  1570. *
  1571. * For scattered loading to work on a RISC machine where some of the references
  1572. * are split across two instructions the link editor needs to be assured that
  1573. * each reference has a unique 32 bit reference (that more than one reference is
  1574. * NOT sharing the same high 16 bits for example) so it move each referenced
  1575. * item independent of each other. Some compilers guarantees this but the
  1576. * compilers don't so scattered loading can be done on those that do guarantee
  1577. * this.
  1578. }
  1579. {
  1580. * The reason for the ifdef's of __BIG_ENDIAN__ and __LITTLE_ENDIAN__ are that
  1581. * when stattered relocation entries were added the mistake of using a mask
  1582. * against a structure that is made up of bit fields was used. To make this
  1583. * design work this structure must be laid out in memory the same way so the
  1584. * mask can be applied can check the same bit each time (r_scattered).
  1585. }
  1586. type
  1587. scattered_relocation_info = record
  1588. {$ifdef ENDIAN_BIG}
  1589. r_info : longint; { r_scattered:1, /* 1=scattered, 0=non-scattered (see above) */
  1590. r_pcrel:1, /* was relocated pc relative already */
  1591. r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
  1592. r_type:4, /* if not 0, machine specific relocation type */
  1593. r_address:24; /* offset in the section to what is being relocated */}
  1594. r_value : int32_t; {* the value the item to be relocated is refering to (without any offset added) *}
  1595. {$else}
  1596. r_value : int32_t;
  1597. r_info : longint; {* r_address:24, /* offset in the section to what is being relocated */
  1598. r_type:4, /* if not 0, machine specific relocation type */
  1599. r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
  1600. r_pcrel:1, /* was relocated pc relative already */
  1601. r_scattered:1; /* 1=scattered, 0=non-scattered (see above) */ *}
  1602. {$endif}
  1603. end;
  1604. {
  1605. * Relocation types used in a generic implementation. Relocation entries for
  1606. * normal things use the generic relocation as discribed above and their r_type
  1607. * is GENERIC_RELOC_VANILLA (a value of zero).
  1608. *
  1609. * Another type of generic relocation, GENERIC_RELOC_SECTDIFF, is to support
  1610. * the difference of two symbols defined in different sections. That is the
  1611. * expression "symbol1 - symbol2 + constant" is a relocatable expression when
  1612. * both symbols are defined in some section. For this type of relocation the
  1613. * both relocations entries are scattered relocation entries. The value of
  1614. * symbol1 is stored in the first relocation entry's r_value field and the
  1615. * value of symbol2 is stored in the pair's r_value field.
  1616. *
  1617. * A special case for a prebound lazy pointer is needed to beable to set the
  1618. * value of the lazy pointer back to its non-prebound state. This is done
  1619. * using the GENERIC_RELOC_PB_LA_PTR r_type. This is a scattered relocation
  1620. * entry where the r_value feild is the value of the lazy pointer not prebound.
  1621. }
  1622. const
  1623. GENERIC_RELOC_VANILLA = 0; { generic relocation as discribed above }
  1624. GENERIC_RELOC_PAIR = 1; { Only follows a GENERIC_RELOC_SECTDIFF }
  1625. GENERIC_RELOC_SECTDIFF = 2;
  1626. GENERIC_RELOC_PB_LA_PTR = 3; { prebound lazy pointer }
  1627. GENERIC_RELOC_LOCAL_SECTDIFF = 4;
  1628. {*
  1629. * Relocations for x86_64 are a bit different than for other architectures in
  1630. * Mach-O: Scattered relocations are not used. Almost all relocations produced
  1631. * by the compiler are external relocations. An external relocation has the
  1632. * r_extern bit set to 1 and the r_symbolnum field contains the symbol table
  1633. * index of the target label.
  1634. *
  1635. * When the assembler is generating relocations, if the target label is a local
  1636. * label (begins with 'L'), then the previous non-local label in the same
  1637. * section is used as the target of the external relocation. An addend is used
  1638. * with the distance from that non-local label to the target label. Only when
  1639. * there is no previous non-local label in the section is an internal
  1640. * relocation used.
  1641. *
  1642. * The addend (i.e. the 4 in _foo+4) is encoded in the instruction (Mach-O does
  1643. * not have RELA relocations). For PC-relative relocations, the addend is
  1644. * stored directly in the instruction. This is different from other Mach-O
  1645. * architectures, which encode the addend minus the current section offset.
  1646. *
  1647. * The relocation types are:
  1648. *
  1649. * X86_64_RELOC_UNSIGNED // for absolute addresses
  1650. * X86_64_RELOC_SIGNED // for signed 32-bit displacement
  1651. * X86_64_RELOC_BRANCH // a CALL/JMP instruction with 32-bit displacement
  1652. * X86_64_RELOC_GOT_LOAD // a MOVQ load of a GOT entry
  1653. * X86_64_RELOC_GOT // other GOT references
  1654. * X86_64_RELOC_SUBTRACTOR // must be followed by a X86_64_RELOC_UNSIGNED
  1655. *
  1656. * The following are sample assembly instructions, followed by the relocation
  1657. * and section content they generate in an object file:
  1658. *
  1659. * call _foo
  1660. * r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1661. * E8 00 00 00 00
  1662. *
  1663. * call _foo+4
  1664. * r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1665. * E8 04 00 00 00
  1666. *
  1667. * movq _foo@GOTPCREL(%rip), %rax
  1668. * r_type=X86_64_RELOC_GOT_LOAD, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1669. * 48 8B 05 00 00 00 00
  1670. *
  1671. * pushq _foo@GOTPCREL(%rip)
  1672. * r_type=X86_64_RELOC_GOT, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1673. * FF 35 00 00 00 00
  1674. *
  1675. * movl _foo(%rip), %eax
  1676. * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1677. * 8B 05 00 00 00 00
  1678. *
  1679. * movl _foo+4(%rip), %eax
  1680. * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1681. * 8B 05 04 00 00 00
  1682. *
  1683. * movb $0x12, _foo(%rip)
  1684. * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1685. * C6 05 FF FF FF FF 12
  1686. *
  1687. * movl $0x12345678, _foo(%rip)
  1688. * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
  1689. * C7 05 FC FF FF FF 78 56 34 12
  1690. *
  1691. * .quad _foo
  1692. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1693. * 00 00 00 00 00 00 00 00
  1694. *
  1695. * .quad _foo+4
  1696. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1697. * 04 00 00 00 00 00 00 00
  1698. *
  1699. * .quad _foo - _bar
  1700. * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar
  1701. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1702. * 00 00 00 00 00 00 00 00
  1703. *
  1704. * .quad _foo - _bar + 4
  1705. * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar
  1706. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1707. * 04 00 00 00 00 00 00 00
  1708. *
  1709. * .long _foo - _bar
  1710. * r_type=X86_64_RELOC_SUBTRACTOR, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_bar
  1711. * r_type=X86_64_RELOC_UNSIGNED, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1712. * 00 00 00 00
  1713. *
  1714. * lea L1(%rip), %rax
  1715. * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_prev
  1716. * 48 8d 05 12 00 00 00
  1717. * // assumes _prev is the first non-local label 0x12 bytes before L1
  1718. *
  1719. * lea L0(%rip), %rax
  1720. * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=0, r_pcrel=1, r_symbolnum=3
  1721. * 48 8d 05 56 00 00 00
  1722. * // assumes L0 is in third section, has an address of 0x00000056 in .o
  1723. * // file, and there is no previous non-local label
  1724. *
  1725. * .quad L1
  1726. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
  1727. * 12 00 00 00 00 00 00 00
  1728. * // assumes _prev is the first non-local label 0x12 bytes before L1
  1729. *
  1730. * .quad L0
  1731. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=0, r_pcrel=0, r_symbolnum=3
  1732. * 56 00 00 00 00 00 00 00
  1733. * // assumes L0 is in third section, has an address of 0x00000056 in .o
  1734. * // file, and there is no previous non-local label
  1735. *
  1736. * .quad _foo - .
  1737. * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
  1738. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1739. * EE FF FF FF FF FF FF FF
  1740. * // assumes _prev is the first non-local label 0x12 bytes before this
  1741. * // .quad
  1742. *
  1743. * .quad _foo - L1
  1744. * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
  1745. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
  1746. * EE FF FF FF FF FF FF FF
  1747. * // assumes _prev is the first non-local label 0x12 bytes before L1
  1748. *
  1749. * .quad L1 - _prev
  1750. * // No relocations. This is an assembly time constant.
  1751. * 12 00 00 00 00 00 00 00
  1752. * // assumes _prev is the first non-local label 0x12 bytes before L1
  1753. *
  1754. *
  1755. *
  1756. * In final linked images, there are only two valid relocation kinds:
  1757. *
  1758. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=1, r_symbolnum=sym_index
  1759. * This tells dyld to add the address of a symbol to a pointer sized (8-byte)
  1760. * piece of data (i.e on disk the 8-byte piece of data contains the addend). The
  1761. * r_symbolnum contains the index into the symbol table of the target symbol.
  1762. *
  1763. * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=0, r_symbolnum=0
  1764. * This tells dyld to adjust the pointer sized (8-byte) piece of data by the amount
  1765. * the containing image was loaded from its base address (e.g. slide).
  1766. *
  1767. *}
  1768. const
  1769. X86_64_RELOC_UNSIGNED = 0; // for absolute addresses
  1770. X86_64_RELOC_SIGNED = 1; // for signed 32-bit displacement
  1771. X86_64_RELOC_BRANCH = 2; // a CALL/JMP instruction with 32-bit displacement
  1772. X86_64_RELOC_GOT_LOAD = 3; // a MOVQ load of a GOT entry
  1773. X86_64_RELOC_GOT = 4; // other GOT references
  1774. X86_64_RELOC_SUBTRACTOR = 5; // must be followed by a X86_64_RELOC_UNSIGNED
  1775. X86_64_RELOC_SIGNED_1 = 6; // for signed 32-bit displacement with a -1 addend
  1776. X86_64_RELOC_SIGNED_2 = 7; // for signed 32-bit displacement with a -2 addend
  1777. X86_64_RELOC_SIGNED_4 = 8; // for signed 32-bit displacement with a -4 addend
  1778. {* Relocation types used in the ppc implementation. Relocation entries for
  1779. * things other than instructions use the same generic relocation as discribed
  1780. * above and their r_type is RELOC_VANILLA. The rest of the relocation types
  1781. * are for instructions. Since they are for instructions the r_address field
  1782. * indicates the 32 bit instruction that the relocation is to be preformed on.
  1783. * The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types
  1784. * except for PPC_RELOC_BR14.
  1785. *
  1786. * For PPC_RELOC_BR14 if the r_length is the unused value 3, then the branch was
  1787. * statically predicted setting or clearing the Y-bit based on the sign of the
  1788. * displacement or the opcode. If this is the case the static linker must flip
  1789. * the value of the Y-bit if the sign of the displacement changes for non-branch
  1790. * always conditions.
  1791. }
  1792. const
  1793. PPC_RELOC_VANILLA = 0; { generic relocation as discribed above }
  1794. PPC_RELOC_PAIR = 1; { the second relocation entry of a pair }
  1795. PPC_RELOC_BR14 = 2; { 14 bit branch displacement (to a word address) }
  1796. PPC_RELOC_BR24 = 3; { 24 bit branch displacement (to a word address) }
  1797. PPC_RELOC_HI16 = 4; { a PAIR follows with the low half }
  1798. PPC_RELOC_LO16 = 5; { a PAIR follows with the high half }
  1799. PPC_RELOC_HA16 = 6; { Same as the RELOC_HI16 except the low 16 bits and the }
  1800. { * high 16 bits are added together with the low 16 bits }
  1801. { * sign extened first. This means if bit 15 of the low }
  1802. { * 16 bits is set the high 16 bits stored in the }
  1803. { * instruction will be adjusted. }
  1804. PPC_RELOC_LO14 = 7; { Same as the LO16 except that the low 2 bits are not }
  1805. { * stored in the instruction and are always zero. This }
  1806. { * is used in double word load/store instructions. }
  1807. PPC_RELOC_SECTDIFF = 8; { a PAIR follows with subtract symbol value }
  1808. PPC_RELOC_PB_LA_PTR = 9; { prebound lazy pointer }
  1809. PPC_RELOC_HI16_SECTDIFF = 10; { section difference forms of above. a PAIR }
  1810. PPC_RELOC_LO16_SECTDIFF = 11; { follows these with subtract symbol value }
  1811. PPC_RELOC_HA16_SECTDIFF = 12;
  1812. PPC_RELOC_JBSR = 13;
  1813. PPC_RELOC_LO14_SECTDIFF = 14;
  1814. PPC_RELOC_LOCAL_SECTDIFF = 15; { like PPC_RELOC_SECTDIFF, but the symbol referenced was local. }
  1815. {
  1816. * Symbolic debugger symbols. The comments give the conventional use for
  1817. *
  1818. * .stabs "n_name", n_type, n_sect, n_desc, n_value
  1819. *
  1820. * where n_type is the defined constant and not listed in the comment. Other
  1821. * fields not listed are zero. n_sect is the section ordinal the entry is
  1822. * refering to.
  1823. }
  1824. const
  1825. N_GSYM = $20; { global symbol: name,,NO_SECT,type,0 }
  1826. N_FNAME = $22; { procedure name (f77 kludge): name,,NO_SECT,0,0 }
  1827. N_FUN = $24; { procedure: name,,n_sect,linenumber,address }
  1828. N_STSYM = $26; { static symbol: name,,n_sect,type,address }
  1829. N_LCSYM = $28; { .lcomm symbol: name,,n_sect,type,address }
  1830. N_BNSYM = $2e; { begin nsect sym: 0,,n_sect,0,address }
  1831. N_OPT = $3c; { emitted with gcc2_compiled and in gcc source }
  1832. N_RSYM = $40; { register sym: name,,NO_SECT,type,register }
  1833. N_SLINE = $44; { src line: 0,,n_sect,linenumber,address }
  1834. N_ENSYM = $4e; { end nsect sym: 0,,n_sect,0,address }
  1835. N_SSYM = $60; { structure elt: name,,NO_SECT,type,struct_offset }
  1836. N_SO = $64; { source file name: name,,n_sect,0,address }
  1837. N_OSO = $66; { object file name: name,,0,0,st_mtime }
  1838. N_LSYM = $80; { local sym: name,,NO_SECT,type,offset }
  1839. N_BINCL = $82; { include file beginning: name,,NO_SECT,0,sum }
  1840. N_SOL = $84; { #included file name: name,,n_sect,0,address }
  1841. N_PARAMS = $86; { compiler parameters: name,,NO_SECT,0,0 }
  1842. N_VERSION = $88; { compiler version: name,,NO_SECT,0,0 }
  1843. N_OLEVEL = $8A; { compiler -O level: name,,NO_SECT,0,0 }
  1844. N_PSYM = $a0; { parameter: name,,NO_SECT,type,offset }
  1845. N_EINCL = $a2; { include file end: name,,NO_SECT,0,0 }
  1846. N_ENTRY = $a4; { alternate entry: name,,n_sect,linenumber,address }
  1847. N_LBRAC = $c0; { left bracket: 0,,NO_SECT,nesting level,address }
  1848. N_EXCL = $c2; { deleted include file: name,,NO_SECT,0,sum }
  1849. N_RBRAC = $e0; { right bracket: 0,,NO_SECT,nesting level,address }
  1850. N_BCOMM = $e2; { begin common: name,,NO_SECT,0,0 }
  1851. N_ECOMM = $e4; { end common: name,,n_sect,0,0 }
  1852. N_ECOML = $e8; { end common (local name): 0,,n_sect,0,address }
  1853. N_LENG = $fe; { second stab entry with length information }
  1854. { * for the berkeley pascal compiler, pc(1): }
  1855. N_PC = $30; { global pascal symbol: name,,NO_SECT,subtype,line }
  1856. implementation
  1857. end.