macho.pas 98 KB

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