1/**
2 * This file describes the format of Mach-O object files.
3 *
4 * D header file for `mach-o/loader.h` from the macOS 10.15 SDK.
5 *
6 * Copyright: Copyright Digital Mars 2010-2019.
7 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
8 * Authors: Jacob Carlborg
9 * Version: Initial created: Feb 20, 2010-2018
10 * Source: $(DRUNTIMESRC core/sys/darwin/mach/_loader.d)
11 */
12module core.sys.darwin.mach.loader;
13
14import core.stdc.config;
15
16version (CoreDdoc)
17{
18    /**
19     * The 32-bit mach header appears at the very beginning of the object file
20     * for 32-bit architectures.
21     */
22    struct mach_header
23    {
24        /// Mach magic number identifier.
25        uint magic;
26
27        /// Cpu specifier.
28        int cputype;
29
30        /// Machine specifier.
31        int cpusubtype;
32
33        /// Type of file.
34        uint filetype;
35
36        /// Number of load commands.
37        uint ncmds;
38
39        /// The size of all the load commands.
40        uint sizeofcmds;
41
42        /// Flags.
43        uint flags;
44    }
45
46    /// Constant for the magic field of the mach_header (32-bit architectures)
47    enum
48    {
49        /// The mach magic number
50        MH_MAGIC,
51
52        /// NXSwapInt(MH_MAGIC)
53        MH_CIGAM
54    }
55
56    /**
57     * The 64-bit mach header appears at the very beginning of object files for
58     * 64-bit architectures.
59     */
60    struct mach_header_64
61    {
62        /// Mach magic number identifier.
63        uint magic;
64
65        /// Cpu specifier.
66        int cputype;
67
68        /// Machine specifier.
69        int cpusubtype;
70
71        /// Type of file.
72        uint filetype;
73
74        /// Number of load commands.
75        uint ncmds;
76
77        /// The size of all the load commands.
78        uint sizeofcmds;
79
80        /// Flags.
81        uint flags;
82
83        /// Reserved.
84        uint reserved;
85    }
86
87    /// Constant for the magic field of the mach_header_64 (64-bit architectures)
88    enum
89    {
90        /// The 64-bit mach magic number.
91        MH_MAGIC_64,
92
93        /// NXSwapInt(MH_MAGIC_64).
94        MH_CIGAM_64
95    }
96
97    /**
98     * The layout of the file depends on the filetype. For all but the MH_OBJECT
99     * file type the segments are padded out and aligned on a segment alignment
100     * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB,
101     * MH_DYLIB, MH_DYLINKER and MH_BUNDLE file types also have the headers
102     * included as part of their first segment.
103     *
104     * The file type MH_OBJECT is a compact format intended as output of the
105     * assembler and input (and possibly output) of the link editor (the .o
106     * format). All sections are in one unnamed segment with no segment padding.
107     * This format is used as an executable format when the file is so small the
108     * segment padding greatly increases its size.
109     *
110     * The file type MH_PRELOAD is an executable format intended for things that
111     * are not executed under the kernel (proms, stand alones, kernels, etc).
112     * The format can be executed under the kernel but may demand paged it and
113     * not preload it before execution.
114     *
115     * A core file is in MH_CORE format and can be any in an arbitrary legal
116     * Mach-O file.
117     *
118     * Constants for the filetype field of the mach_header
119     */
120    enum
121    {
122        /// Relocatable object file.
123        MH_OBJECT,
124
125        /// Demand paged executable file.
126        MH_EXECUTE,
127
128        /// Fixed VM shared library file.
129        MH_FVMLIB,
130
131        /// Core file.
132        MH_CORE,
133
134        /// Preloaded executable file.
135        MH_PRELOAD,
136
137        /// Dynamically bound shared library.
138        MH_DYLIB,
139
140        /// Dynamic link editor.
141        MH_DYLINKER,
142
143        /// Dynamically bound bundle file.
144        MH_BUNDLE,
145
146        /// Shared library stub for static linking only, no section contents.
147        MH_DYLIB_STUB,
148
149        /// Companion file with only debug sections.
150        MH_DSYM,
151
152        /// X86_64 kexts.
153        MH_KEXT_BUNDLE
154    }
155
156
157    /// Constants for the flags field of the mach_header
158    enum
159    {
160        /// The object file has no undefined references.
161        MH_NOUNDEFS,
162
163        /**
164         * The object file is the output of an incremental link against a base
165         * file and can't be link edited again.
166         */
167        MH_INCRLINK,
168
169        /**
170         * The object file is input for the dynamic linker and can't be
171         * statically link edited again.
172         */
173        MH_DYLDLINK,
174
175        /**
176         * The object file's undefined references are bound by the dynamic
177         * linker when loaded.
178         */
179        MH_BINDATLOAD,
180
181        /// The file has its dynamic undefined references prebound.
182        MH_PREBOUND,
183
184        /// The file has its read-only and read-write segments split.
185        MH_SPLIT_SEGS,
186
187        /**
188         * The shared library init routine is to be run lazily via catching
189         * memory faults to its writeable segments (obsolete).
190         */
191        MH_LAZY_INIT,
192
193        /// The image is using two-level name space bindings.
194        MH_TWOLEVEL,
195
196        /// The executable is forcing all images to use flat name space bindings.
197        MH_FORCE_FLAT,
198
199        /**
200         * This umbrella guarantees no multiple definitions of symbols in its
201         * sub-images so the two-level namespace hints can always be used.
202         */
203        MH_NOMULTIDEFS,
204
205        /// Do not have dyld notify the prebinding agent about this executable.
206        MH_NOFIXPREBINDING,
207
208        /**
209         * The binary is not prebound but can have its prebinding redone. only
210         * used when MH_PREBOUND is not set.
211         */
212        MH_PREBINDABLE,
213
214        /**
215         * Indicates that this binary binds to all two-level namespace modules
216         * of its dependent libraries. only used when MH_PREBINDABLE and
217         * MH_TWOLEVEL are both set.
218         */
219        MH_ALLMODSBOUND,
220
221        /**
222         * Safe to divide up the sections into sub-sections via symbols for dead
223         * code stripping.
224         */
225        MH_SUBSECTIONS_VIA_SYMBOLS,
226
227        /// The binary has been canonicalized via the unprebind operation.
228        MH_CANONICAL,
229
230        /// The final linked image contains external weak symbols.
231        MH_WEAK_DEFINES,
232
233        /// The final linked image uses weak symbols.
234        MH_BINDS_TO_WEAK,
235
236
237
238        /**
239         * When this bit is set, all stacks in the task will be given stack
240         * execution privilege. Only used in MH_EXECUTE filetypes.
241         */
242        MH_ALLOW_STACK_EXECUTION,
243
244        /**
245         * When this bit is set, the binary declares it is safe for use in
246         * processes with uid zero.
247         */
248        MH_ROOT_SAFE,
249
250
251
252        /**
253         * When this bit is set, the binary declares it is safe for use in
254         * processes when issetugid() is true.
255         */
256        MH_SETUID_SAFE,
257
258
259
260        /**
261         * When this bit is set on a dylib, the static linker does not need to
262         * examine dependent dylibs to see if any are re-exported.
263         */
264        MH_NO_REEXPORTED_DYLIBS,
265
266        /**
267         * When this bit is set, the OS will load the main executable at a
268         * random address. Only used in MH_EXECUTE filetypes.
269         */
270        MH_PIE,
271
272        /**
273         * Only for use on dylibs. When linking against a dylib that has this
274         * bit set, the static linker will automatically not create a
275         * LC_LOAD_DYLIB load command to the dylib if no symbols are being
276         * referenced from the dylib..
277         */
278        MH_DEAD_STRIPPABLE_DYLIB,
279
280        /// Contains a section of type S_THREAD_LOCAL_VARIABLES.
281        MH_HAS_TLV_DESCRIPTORS,
282
283
284
285        /**
286         * When this bit is set, the OS will run the main executable with a
287         * non-executable heap even on platforms (e.g. i386) that don't require
288         * it. Only used in MH_EXECUTE filetypes.
289         */
290        MH_NO_HEAP_EXECUTION,
291
292
293
294        /// The code was linked for use in an application extension..
295        MH_APP_EXTENSION_SAFE,
296
297
298
299        /**
300         * The external symbols listed in the nlist symbol table do not include
301         * all the symbols listed in the dyld info.
302         */
303        MH_NLIST_OUTOFSYNC_WITH_DYLDINFO,
304
305        /**
306         * Allow LC_MIN_VERSION_MACOS and LC_BUILD_VERSION load commands with
307         * the platforms macOS, iOSMac, iOSSimulator, tvOSSimulator and
308         * watchOSSimulator.
309         */
310        MH_SIM_SUPPORT,
311
312        /**
313         * Only for use on dylibs. When this bit is set, the dylib is part of
314         * the dyld shared cache, rather than loose in the filesystem.
315         */
316        MH_DYLIB_IN_CACHE
317    }
318
319    /**
320     * The load commands directly follow the mach_header. The total size of all
321     * of the commands is given by the sizeofcmds field in the mach_header. All
322     * load commands must have as their first two fields cmd and cmdsize. The
323     * cmd field is filled in with a constant for that command type. Each
324     * command type has a structure specifically for it. The cmdsize field is
325     * the size in bytes of the particular load command structure plus anything
326     * that follows it that is a part of the load command
327     * (i.e. section structures, strings, etc.). To advance to the next load
328     * command the cmdsize can be added to the offset or pointer of the current
329     * load command. The cmdsize for 32-bit architectures MUST be a multiple of
330     * 4 bytes and for 64-bit architectures MUST be a multiple of 8 bytes
331     * (these are forever the maximum alignment of any load commands). The
332     * padded bytes must be zero. All tables in the object file must also
333     * follow these rules so the file can be memory mapped. Otherwise the
334     * pointers to these tables will not work well or at all on some machines.
335     * With all padding zeroed like objects will compare byte for byte.
336     */
337    struct load_command
338    {
339        /// Type of load command.
340        uint cmd;
341
342        /// Total size of command in bytes.
343        uint cmdsize;
344    }
345
346    /**
347     * After MacOS X 10.1 when a new load command is added that is required to
348     * be understood by the dynamic linker for the image to execute properly the
349     * LC_REQ_DYLD bit will be or'ed into the load command constant. If the
350     * dynamic linker sees such a load command it it does not understand will
351     * issue a "unknown load command required for execution" error and refuse to
352     * use the image. Other load commands without this bit that are not
353     * understood will simply be ignored.
354     */
355    enum LC_REQ_DYLD;
356
357    /// Constants for the cmd field of all load commands, the type.
358    enum
359    {
360        /// Segment of this file to be mapped.
361        LC_SEGMENT,
362
363        /// Link-edit stab symbol table info.
364        LC_SYMTAB,
365
366        /// Link-edit gdb symbol table info (obsolete).
367        LC_SYMSEG,
368
369        /// Thread.
370        LC_THREAD,
371
372        /// Unix thread (includes a stack).
373        LC_UNIXTHREAD,
374
375        /// Load a specified fixed VM shared library.
376        LC_LOADFVMLIB,
377
378        /// Fixed VM shared library identification.
379        LC_IDFVMLIB,
380
381        /// Object identification info (obsolete).
382        LC_IDENT,
383
384        /// Fixed VM file inclusion (internal use).
385        LC_FVMFILE,
386
387        /// Prepage command (internal use).
388        LC_PREPAGE,
389
390        /// Dynamic link-edit symbol table info.
391        LC_DYSYMTAB,
392
393        /// Load a dynamically linked shared library.
394        LC_LOAD_DYLIB,
395
396        /// Dynamically linked shared lib ident.
397        LC_ID_DYLIB,
398
399        /// Load a dynamic linker.
400        LC_LOAD_DYLINKER,
401
402        /// Dynamic linker identification.
403        LC_ID_DYLINKER,
404
405        /// Modules prebound for a dynamically linked shared library.
406        LC_PREBOUND_DYLIB,
407
408        /// Image routines.
409        LC_ROUTINES,
410
411        /// Sub framework.
412        LC_SUB_FRAMEWORK,
413
414        /// Sub umbrella.
415        LC_SUB_UMBRELLA,
416
417        /// Sub client.
418        LC_SUB_CLIENT,
419
420        /// Sub library.
421        LC_SUB_LIBRARY,
422
423        /// Two-level namespace lookup hints.
424        LC_TWOLEVEL_HINTS,
425
426        /// Prebind checksum.
427        LC_PREBIND_CKSUM
428    }
429
430
431    /**
432     * Load a dynamically linked shared library that is allowed to be missing
433     * (all symbols are weak imported).
434     */
435    ///
436    enum LC_LOAD_WEAK_DYLIB;
437
438    ///
439    enum
440    {
441        /// 64-bit segment of this file to be mapped.
442        LC_SEGMENT_64,
443
444        /// 64-bit image routines.
445        LC_ROUTINES_64,
446
447        /// The uuid.
448        LC_UUID,
449
450        /// Runpath additions.
451        LC_RPATH,
452
453        /// Local of code signature.
454        LC_CODE_SIGNATURE,
455
456        /// Local of info to split segments.
457        LC_SEGMENT_SPLIT_INFO,
458
459        /// Load and re-export dylib.
460        LC_REEXPORT_DYLIB,
461
462        /// Delay load of dylib until first use.
463        LC_LAZY_LOAD_DYLIB,
464
465        /// Encrypted segment information.
466        LC_ENCRYPTION_INFO,
467
468        /// Compressed dyld information.
469        LC_DYLD_INFO,
470
471        /// Compressed dyld information only.
472        LC_DYLD_INFO_ONLY,
473
474        /// Load upward dylib.
475        LC_LOAD_UPWARD_DYLIB,
476
477        /// Build for MacOSX min OS version.
478        LC_VERSION_MIN_MACOSX,
479
480        /// Build for iPhoneOS min OS version.
481        LC_VERSION_MIN_IPHONEOS,
482
483        /// Compressed table of function start addresses.
484        LC_FUNCTION_STARTS,
485
486        /// String for dyld to treat like environment variable.
487        LC_DYLD_ENVIRONMENT,
488
489        /// Replacement for LC_UNIXTHREAD.
490        LC_MAIN,
491
492        /// Table of non-instructions in __text.
493        LC_DATA_IN_CODE,
494
495        /// Source version used to build binary.
496        LC_SOURCE_VERSION,
497
498        /// Code signing DRs copied from linked dylibs.
499        LC_DYLIB_CODE_SIGN_DRS,
500
501        /// 64-bit encrypted segment information.
502        LC_ENCRYPTION_INFO_64,
503
504        /// Linker options in MH_OBJECT files.
505        LC_LINKER_OPTION,
506
507        /// Optimization hints in MH_OBJECT files.
508        LC_LINKER_OPTIMIZATION_HINT,
509
510        /// Build for AppleTV min OS version.
511        LC_VERSION_MIN_TVOS,
512
513        /// Build for Watch min OS version.
514        LC_VERSION_MIN_WATCHOS,
515
516        /// Arbitrary data included within a Mach-O file.
517        LC_NOTE,
518
519        /// Build for platform min OS version.
520        LC_BUILD_VERSION,
521
522        /// Used with linkedit_data_command, payload is trie.
523        LC_DYLD_EXPORTS_TRIE,
524
525        /// Used with linkedit_data_command.
526        LC_DYLD_CHAINED_FIXUPS
527    }
528
529
530    /**
531     * A variable length string in a load command is represented by an lc_str
532     * union. The strings are stored just after the load command structure and
533     * the offset is from the start of the load command structure. The size
534     * of the string is reflected in the cmdsize field of the load command.
535     * Once again any padded bytes to bring the cmdsize field to a multiple
536     * of 4 bytes must be zero.
537     */
538    union lc_str
539    {
540        /// Offset to the string.
541        uint offset;
542
543        /// Pointer to the string (only available on non 64 bit platforms).
544        char* ptr;
545    }
546
547    /**
548     * The segment load command indicates that a part of this file is to be
549     * mapped into the task's address space. The size of this segment in memory,
550     * vmsize, maybe equal to or larger than the amount to map from this file,
551     * filesize. The file is mapped starting at fileoff to the beginning of
552     * the segment in memory, vmaddr. The rest of the memory of the segment,
553     * if any, is allocated zero fill on demand. The segment's maximum virtual
554     * memory protection and initial virtual memory protection are specified
555     * by the maxprot and initprot fields. If the segment has sections then the
556     * section structures directly follow the segment command and their size is
557     * reflected in cmdsize.
558     */
559    struct segment_command
560    {
561        /// LC_SEGMENT.
562        uint cmd;
563
564        /// Includes sizeof section structs.
565        uint cmdsize;
566
567        /// Segment name.
568        char[16] segname;
569
570        /// Memory address of this segment.
571        uint vmaddr;
572
573        /// Memory size of this segment.
574        uint vmsize;
575
576        /// File offset of this segment.
577        uint fileoff;
578
579        /// Amount to map from the file.
580        uint filesize;
581
582        /// Maximum VM protection.
583        int maxprot;
584
585        /// Initial VM protection.
586        int initprot;
587
588        /// Number of sections in segment.
589        uint nsects;
590
591        /// Flags.
592        uint flags;
593    }
594
595    /*
596     * The 64-bit segment load command indicates that a part of this file is to
597     * be mapped into a 64-bit task's address space. If the 64-bit segment has
598     * sections then section_64 structures directly follow the 64-bit segment
599     * command and their size is reflected in cmdsize.
600     */
601    struct segment_command_64
602    {
603        /// LC_SEGMENT_64.
604        uint cmd;
605
606        /// Includes sizeof section_64 structs.
607        uint cmdsize;
608
609        /// Segment name.
610        char[16] segname;
611
612        /// Memory address of this segment.
613        ulong vmaddr;
614
615        /// Memory size of this segment.
616        ulong vmsize;
617
618        /// File offset of this segment.
619        ulong fileoff;
620
621        /// Amount to map from the file.
622        ulong filesize;
623
624        /// Maximum VM protection.
625        int maxprot;
626
627        /// Initial VM protection.
628        int initprot;
629
630        /// Number of sections in segment.
631        uint nsects;
632
633        /// Flags.
634        uint flags;
635    }
636
637    /// Constants for the flags field of the segment_command.
638    enum
639    {
640        /**
641         * The file contents for this segment is for the high part of the VM
642         * space, the low part is zero filled (for stacks in core files).
643         */
644        SG_HIGHVM,
645
646        /**
647         * This segment is the VM that is allocated by a fixed VM library,
648         * for overlap checking in the link editor.
649         */
650        SG_FVMLIB,
651
652        /**
653         * This segment has nothing that was relocated in it and nothing
654         * relocated to it, that is it maybe safely replaced without relocation.
655         */
656        SG_NORELOC,
657
658        /**
659         * This segment is protected.
660         *
661         * If the segment starts at file offset 0, the first page of the segment
662         * is not protected. All other pages of the segment are protected.
663         */
664        SG_PROTECTED_VERSION_1,
665
666        /// This segment is made read-only after fixups.
667        SG_READ_ONLY
668    }
669
670
671    /**
672     * A segment is made up of zero or more sections. Non-MH_OBJECT files have
673     * all of their segments with the proper sections in each, and padded to the
674     * specified segment alignment when produced by the link editor. The first
675     * segment of a MH_EXECUTE and MH_FVMLIB format file contains the
676     * mach_header and load commands of the object file before its first
677     * section. The zero fill sections are always last in their segment
678     * (in all formats). This allows the zeroroed segment padding to be mapped
679     * into memory where zero fill sections might be. The gigabyte zero fill
680     * sections, those with the section type S_GB_ZEROFILL, can only be in a
681     * segment with sections of this type. These segments are then placed after
682     * all other segments.
683     *
684     * The MH_OBJECT format has all of its sections in one segment for
685     * compactness. There is no padding to a specified segment boundary and the
686     * mach_header and load commands are not part of the segment.
687     *
688     * Sections with the same section name, sectname, going into the same
689     * segment, segname, are combined by the link editor. The resulting section,
690     * is aligned to the maximum alignment of the combined sections and is the
691     * new section's alignment. The combined sections are aligned to their
692     * original alignment in the combined section. Any padded bytes to get the
693     * specified alignment are zeroed.
694     *
695     * The format of the relocation entries referenced by the reloff and nreloc
696     * fields of the section structure for mach object files is described in the
697     * header file <reloc.h>.
698     */
699    struct section
700    {
701        /// Name of this section.
702        char[16] sectname;
703
704        /// Segment this section goes in.
705        char[16] segname;
706
707        /// Memory address of this section.
708        uint addr;
709
710        /// Size in bytes of this section.
711        uint size;
712
713        /// File offset of this section.
714        uint offset;
715
716        /// Section alignment (power of 2).
717        uint align_;
718
719        /// File offset of relocation entries.
720        uint reloff;
721
722        /// Number of relocation entries.
723        uint nreloc;
724
725        /// Flags (section type and attributes).
726        uint flags;
727
728        /// Reserved (for offset or index).
729        uint reserved1;
730
731        /// Reserved (for count or sizeof).
732        uint reserved2;
733    }
734
735    ///
736    struct section_64
737    {
738        /// Name of this section.
739        char[16] sectname;
740
741        /// Segment this section goes in.
742        char[16] segname;
743
744        /// Memory address of this section.
745        ulong addr;
746
747        /// Size in bytes of this section.
748        ulong size;
749
750        /// File offset of this section.
751        uint offset;
752
753        /// Section alignment (power of 2).
754        uint align_;
755
756        /// File offset of relocation entries.
757        uint reloff;
758
759        /// Number of relocation entries.
760        uint nreloc;
761
762        /// Flags (section type and attributes).
763        uint flags;
764
765        /// Reserved (for offset or index).
766        uint reserved1;
767
768        /// Reserved (for count or sizeof).
769        uint reserved2;
770
771        /// Reserved.
772        uint reserved3;
773    }
774
775    /**
776     * The flags field of a section structure is separated into two parts a section
777     * type and section attributes. The section types are mutually exclusive (it
778     * can only have one type) but the section attributes are not (it may have more
779     * than one attribute).
780     */
781    enum
782    {
783        /// 256 section types.
784        SECTION_TYPE,
785
786        /// 24 section attributes.
787        SECTION_ATTRIBUTES
788    }
789
790    /// Constants for the type of a section.
791    enum
792    {
793        /// Regular section.
794        S_REGULAR,
795
796        /// Zero fill on demand section.
797        S_ZEROFILL,
798
799        /// Section with only literal C strings.
800        S_CSTRING_LITERALS,
801
802        /// Section with only 4 byte literals.
803        S_4BYTE_LITERALS,
804
805        /// Section with only 8 byte literals.
806        S_8BYTE_LITERALS,
807
808        /// Section with only pointers to literals.
809        S_LITERAL_POINTERS,
810
811        /**
812         * Section with only non-lazy symbol pointers.
813         *
814         * For the two types of symbol pointers sections and the symbol stubs
815         * section they have indirect symbol table entries. For each of the
816         * entries in the section the indirect symbol table entries, in
817         * corresponding order in the indirect symbol table, start at the index
818         * stored in the reserved1 field of the section structure. Since the
819         * indirect symbol table entries correspond to the entries in the
820         * section the number of indirect symbol table entries is inferred from
821         * the size of the section divided by the size of the entries in the
822         * section. For symbol pointers sections the size of the entries in the
823         * section is 4 bytes and for symbol stubs sections the byte size of the
824         * stubs is stored in the reserved2 field of the section structure.
825         */
826        S_NON_LAZY_SYMBOL_POINTERS,
827
828        /// Section with only lazy symbol pointers.
829        S_LAZY_SYMBOL_POINTERS,
830
831        /// Section with only symbol stubs, byte size of stub in the reserved2 field.
832        S_SYMBOL_STUBS,
833
834        /// Section with only function pointers for initialization.
835        S_MOD_INIT_FUNC_POINTERS,
836
837        /// Section with only function pointers for termination.
838        S_MOD_TERM_FUNC_POINTERS,
839
840        /// Section contains symbols that are to be coalesced.
841        S_COALESCED,
842
843        /// Zero fill on demand section (that can be larger than 4 gigabytes).
844        S_GB_ZEROFILL,
845
846        /// Section with only pairs of function pointers for interposing.
847        S_INTERPOSING,
848
849        /// Section with only 16 byte literals.
850        S_16BYTE_LITERALS,
851
852        /// Section contains DTrace Object Format.
853        S_DTRACE_DOF,
854
855        /// Section with only lazy symbol pointers to lazy loaded dylibs.
856        S_LAZY_DYLIB_SYMBOL_POINTERS,
857
858
859
860        // Section types to support thread local variables.
861
862        /// Template of initial values for TLVs.
863        S_THREAD_LOCAL_REGULAR,
864
865        /// Template of initial values for TLVs.
866        S_THREAD_LOCAL_ZEROFILL,
867
868        /// TLV descriptors.
869        S_THREAD_LOCAL_VARIABLES,
870
871        /// Pointers to TLV descriptors.
872        S_THREAD_LOCAL_VARIABLE_POINTERS,
873
874        /// Functions to call to initialize TLV values.
875        S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
876
877        /// 32-bit offsets to initializers.
878        S_INIT_FUNC_OFFSETS
879    }
880
881    /**
882     * Constants for the section attributes part of the flags field of a section
883     * structure.
884     */
885    enum
886    {
887        /// User setable attributes.
888        SECTION_ATTRIBUTES_USR,
889
890        /// Section contains only true machine instructions.
891        S_ATTR_PURE_INSTRUCTIONS,
892
893        /// Section contains coalesced symbols that are not to be in a ranlib table of contents.
894        S_ATTR_NO_TOC,
895
896        /// Ok to strip static symbols in this section in files with the MH_DYLDLINK flag.
897        S_ATTR_STRIP_STATIC_SYMS,
898
899        /// No dead stripping.
900        S_ATTR_NO_DEAD_STRIP,
901
902        /// Blocks are live if they reference live blocks.
903        S_ATTR_LIVE_SUPPORT,
904
905        /// Used with i386 code stubs written on by dyld.
906        S_ATTR_SELF_MODIFYING_CODE,
907
908        /**
909         * A debug section.
910         *
911         * If a segment contains any sections marked with S_ATTR_DEBUG then all
912         * sections in that segment must have this attribute. No section other
913         * than a section marked with this attribute may reference the contents
914         * of this section. A section with this attribute may contain no symbols
915         * and must have a section type S_REGULAR. The static linker will not
916         * copy section contents from sections with this attribute into its
917         * output file. These sections generally contain DWARF debugging info.
918         */
919        S_ATTR_DEBUG,
920
921        /// System setable attributes.
922        SECTION_ATTRIBUTES_SYS,
923
924        /// Section contains some machine instructions.
925        S_ATTR_SOME_INSTRUCTIONS,
926
927        /// Section has external relocation entries.
928        S_ATTR_EXT_RELOC,
929
930        /// Section has local relocation entries.
931        S_ATTR_LOC_RELOC
932    }
933
934    /**
935     * The names of segments and sections in them are mostly meaningless to the
936     * link-editor. But there are few things to support traditional UNIX
937     * executables that require the link-editor and assembler to use some names
938     * agreed upon by convention.
939     *
940     * The initial protection of the "__TEXT" segment has write protection
941     * turned off (not writeable).
942     *
943     * The link-editor will allocate common symbols at the end of the "__common"
944     * section in the "__DATA" segment. It will create the section and segment
945     * if needed.
946     *
947     * The currently known segment names and the section names in those segments.
948     */
949    enum
950    {
951        /**
952         * The pagezero segment which has no protections and catches NULL
953         * references for MH_EXECUTE files.
954         */
955        SEG_PAGEZERO,
956
957
958
959        /// The tradition UNIX text segment.
960        SEG_TEXT,
961
962        /// The real text part of the text section no headers, and no padding.
963        SECT_TEXT,
964
965        /// The fvmlib initialization section.
966        SECT_FVMLIB_INIT0,
967
968        /// The section following the fvmlib initialization section.
969        SECT_FVMLIB_INIT1,
970
971
972
973        /// The tradition UNIX data segment.
974        SEG_DATA,
975
976        /// The real initialized data section no padding, no bss overlap.
977        SECT_DATA,
978
979        /// The real uninitialized data section no padding.
980        SECT_BSS,
981
982        /// The section common symbols are allocated in by the link editor.
983        SECT_COMMON,
984
985
986
987        /// Objective-C runtime segment.
988        SEG_OBJC,
989
990        /// Symbol table.
991        SECT_OBJC_SYMBOLS,
992
993        /// Module information.
994        SECT_OBJC_MODULES,
995
996        /// String table.
997        SECT_OBJC_STRINGS,
998
999        /// String table.
1000        SECT_OBJC_REFS,
1001
1002
1003
1004        /// The icon segment.
1005        SEG_ICON,
1006
1007        /// The icon headers.
1008        SECT_ICON_HEADER,
1009
1010        /// The icons in tiff format.
1011        SECT_ICON_TIFF,
1012
1013
1014
1015        /**
1016         * The segment containing all structs created and maintained by the link
1017         * editor. Created with -seglinkedit option to ld(1) for MH_EXECUTE and
1018         * FVMLIB file types only.
1019         */
1020        SEG_LINKEDIT,
1021
1022
1023        /// The unix stack segment.
1024        SEG_UNIXSTACK,
1025
1026
1027        /**
1028         * The segment for the self (dyld) modifing code stubs that has read,
1029         * write and execute permissions.
1030         */
1031        SEG_IMPORT
1032    }
1033
1034    /**
1035     * Fixed virtual memory shared libraries are identified by two things. The
1036     * target pathname (the name of the library as found for execution), and the
1037     * minor version number. The address of where the headers are loaded is in
1038     * header_addr. (THIS IS OBSOLETE and no longer supported).
1039     */
1040    struct fvmlib
1041    {
1042        /// Library's target pathname.
1043        lc_str name;
1044
1045        /// Library's minor version number.
1046        uint minor_version;
1047
1048        /// Library's header address.
1049        uint header_addr;
1050    }
1051
1052    /**
1053     * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
1054     * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library.
1055     * An object that uses a fixed virtual shared library also contains a
1056     * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses.
1057     * (THIS IS OBSOLETE and no longer supported).
1058     */
1059    struct fvmlib_command
1060    {
1061        /// LC_IDFVMLIB or LC_LOADFVMLIB.
1062        uint cmd;
1063
1064        /// Includes pathname string.
1065        uint cmdsize;
1066
1067        /// The library identification.
1068        fvmlib fvmlib_;
1069    }
1070
1071    /**
1072     * Dynamically linked shared libraries are identified by two things. The
1073     * pathname (the name of the library as found for execution), and the
1074     * compatibility version number. The pathname must match and the
1075     * compatibility number in the user of the library must be greater than or
1076     * equal to the library being used. The time stamp is used to record the
1077     * time a library was built and copied into user so it can be use to
1078     * determined if the library used at runtime is exactly the same as used to
1079     * built the program.
1080     */
1081    struct dylib
1082    {
1083        /// Library's path name.
1084        lc_str name;
1085
1086        /// Library's build time stamp.
1087        uint timestamp;
1088
1089        /// Library's current version number.
1090        uint current_version;
1091
1092        /// Library's compatibility version number.
1093        uint compatibility_version;
1094    }
1095
1096    /**
1097     * A dynamically linked shared library
1098     * (filetype == MH_DYLIB in the mach header) contains a dylib_command
1099     * (cmd == LC_ID_DYLIB) to identify the library. An object that uses a
1100     * dynamically linked shared library also contains a dylib_command
1101     * (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or LC_REEXPORT_DYLIB) for each
1102     * library it uses.
1103     */
1104    struct dylib_command
1105    {
1106        /// LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB, LC_REEXPORT_DYLIB.
1107        uint cmd;
1108
1109        /// Includes pathname string.
1110        uint cmdsize;
1111
1112        /// The library identification.
1113        dylib dylib_;
1114    }
1115
1116    /**
1117     * A dynamically linked shared library may be a subframework of an umbrella
1118     * framework. If so it will be linked with "-umbrella umbrella_name" where
1119     * Where "umbrella_name" is the name of the umbrella framework. A
1120     * subframework can only be linked against by its umbrella framework or
1121     * other subframeworks that are part of the same umbrella framework.
1122     * Otherwise the static link editor produces an error and states to link
1123     * against the umbrella framework. The name of the umbrella framework for
1124     * subframeworks is recorded in the following structure.
1125     */
1126    struct sub_framework_command
1127    {
1128        /// LC_SUB_FRAMEWORK.
1129        uint cmd;
1130
1131        /// Includes umbrella string.
1132        uint cmdsize;
1133
1134        /// The umbrella framework name.
1135        lc_str umbrella;
1136    }
1137
1138    /**
1139     * For dynamically linked shared libraries that are subframework of an
1140     * umbrella framework they can allow clients other than the umbrella
1141     * framework or other subframeworks in the same umbrella framework. To do
1142     * this the subframework is built with "-allowable_client client_name" and
1143     * an LC_SUB_CLIENT load command is created for each -allowable_client flag.
1144     * The client_name is usually a framework name. It can also be a name used
1145     * for bundles clients where the bundle is built with
1146     * "-client_name client_name".
1147     */
1148    struct sub_client_command
1149    {
1150        /// LC_SUB_CLIENT.
1151        uint cmd;
1152
1153        /// Includes client string.
1154        uint cmdsize;
1155
1156        /// The client name.
1157        lc_str client;
1158    }
1159
1160    /**
1161     * A dynamically linked shared library may be a sub_umbrella of an umbrella
1162     * framework. If so it will be linked with "-sub_umbrella umbrella_name"
1163     * where "umbrella_name" is the name of the sub_umbrella framework. When
1164     * statically linking when -twolevel_namespace is in effect a twolevel
1165     * namespace umbrella framework will only cause its subframeworks and those
1166     * frameworks listed as sub_umbrella frameworks to be implicited linked in.
1167     * Any other dependent dynamic libraries will not be linked it when
1168     * -twolevel_namespace is in effect. The primary library recorded by the
1169     * static linker when resolving a symbol in these libraries will be the
1170     * umbrella framework. Zero or more sub_umbrella frameworks may be use by an
1171     * umbrella framework. The name of a sub_umbrella framework is recorded in
1172     * the following structure.
1173     */
1174    struct sub_umbrella_command
1175    {
1176        /// LC_SUB_UMBRELLA.
1177        uint cmd;
1178
1179        /// Includes sub_umbrella string.
1180        uint cmdsize;
1181
1182        /// The sub_umbrella framework name.
1183        lc_str sub_umbrella;
1184    }
1185
1186    /**
1187     * A dynamically linked shared library may be a sub_library of another
1188     * shared library. If so it will be linked with "-sub_library library_name"
1189     * where "library_name" is the name of the sub_library shared library. When
1190     * statically linking when -twolevel_namespace is in effect a twolevel
1191     * namespace shared library will only cause its subframeworks and those
1192     * frameworks listed as sub_umbrella frameworks and libraries listed as
1193     * sub_libraries to be implicited linked in. Any other dependent dynamic
1194     * libraries will not be linked it when -twolevel_namespace is in effect.
1195     * The primary library recorded by the static linker when resolving a symbol
1196     * in these libraries will be the umbrella framework (or dynamic library).
1197     * Zero or more sub_library shared libraries may be use by an umbrella
1198     * framework or (or dynamic library). The name of a sub_library framework is
1199     * recorded in the following structure. For example
1200     * /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".
1201     */
1202    struct sub_library_command
1203    {
1204        /// LC_SUB_LIBRARY.
1205        uint cmd;
1206
1207        /// Includes sub_library string.
1208        uint cmdsize;
1209
1210        /// The sub_library name.
1211        lc_str sub_library;
1212    }
1213
1214    /**
1215     * A program (filetype == MH_EXECUTE) that is
1216     * prebound to its dynamic libraries has one of these for each library that
1217     * the static linker used in prebinding. It contains a bit vector for the
1218     * modules in the library. The bits indicate which modules are bound (1) and
1219     * which are not (0) from the library. The bit for module 0 is the low bit
1220     * of the first byte. So the bit for the Nth module is:
1221     * (linked_modules[N/8] >> N%8) & 1
1222     */
1223    struct prebound_dylib_command
1224    {
1225        /// LC_PREBOUND_DYLIB.
1226        uint cmd;
1227
1228        /// Includes strings.
1229        uint cmdsize;
1230
1231        /// Library's path name.
1232        lc_str name;
1233
1234        /// Number of modules in library.
1235        uint nmodules;
1236
1237        /// Bit vector of linked modules.
1238        lc_str linked_modules;
1239    }
1240
1241    /**
1242     * A program that uses a dynamic linker contains a dylinker_command to
1243     * identify the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic
1244     * linker contains a dylinker_command to identify the dynamic linker
1245     * (LC_ID_DYLINKER). A file can have at most one of these.
1246     * This struct is also used for the LC_DYLD_ENVIRONMENT load command and
1247     * contains string for dyld to treat like environment variable.
1248     */
1249    struct dylinker_command
1250    {
1251        /// LC_ID_DYLINKER, LC_LOAD_DYLINKER or LC_DYLD_ENVIRONMENT.
1252        uint cmd;
1253
1254        /// Includes pathname string.
1255        uint cmdsize;
1256
1257        /// Dynamic linker's path name.
1258        lc_str name;
1259    }
1260
1261    /**
1262     * Thread commands contain machine-specific data structures suitable for
1263     * use in the thread state primitives. The machine specific data structures
1264     * follow the struct thread_command as follows.
1265     * Each flavor of machine specific data structure is preceded by an uint32_t
1266     * constant for the flavor of that data structure, an uint32_t that is the
1267     * count of uint32_t's of the size of the state data structure and then
1268     * the state data structure follows. This triple may be repeated for many
1269     * flavors. The constants for the flavors, counts and state data structure
1270     * definitions are expected to be in the header file <machine/thread_status.h>.
1271     * These machine specific data structures sizes must be multiples of
1272     * 4 bytes. The cmdsize reflects the total size of the thread_command
1273     * and all of the sizes of the constants for the flavors, counts and state
1274     * data structures.
1275     *
1276     * For executable objects that are unix processes there will be one
1277     * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.
1278     * This is the same as a LC_THREAD, except that a stack is automatically
1279     * created (based on the shell's limit for the stack size). Command
1280     * arguments and environment variables are copied onto that stack.
1281     */
1282    struct thread_command
1283    {
1284        /// LC_THREAD or  LC_UNIXTHREAD.
1285        uint cmd;
1286
1287        /// Total size of this command.
1288        uint cmdsize;
1289    }
1290
1291    /**
1292     * The routines command contains the address of the dynamic shared library
1293     * initialization routine and an index into the module table for the module
1294     * that defines the routine. Before any modules are used from the library
1295     * the dynamic linker fully binds the module that defines the initialization
1296     * routine and then calls it. This gets called before any module
1297     * initialization routines (used for C++ static constructors) in the library.
1298     */
1299    struct routines_command
1300    {
1301        /// LC_ROUTINES.
1302        uint cmd;
1303
1304        /// Total size of this command.
1305        uint cmdsize;
1306
1307        /// Address of initialization routine.
1308        uint init_address;
1309
1310        /// Index into the module table that.
1311        uint init_module;
1312
1313        // the init routine is defined in
1314
1315        ///
1316        uint reserved1;
1317
1318        ///
1319        uint reserved2;
1320
1321        ///
1322        uint reserved3;
1323
1324        ///
1325        uint reserved4;
1326
1327        ///
1328        uint reserved5;
1329
1330        ///
1331        uint reserved6;
1332    }
1333
1334    /// The 64-bit routines command. Same use as above.
1335    struct routines_command_64
1336    {
1337        /// LC_ROUTINES_64.
1338        uint cmd;
1339
1340        /// Total size of this command.
1341        uint cmdsize;
1342
1343        /// Address of initialization routine.
1344        ulong init_address;
1345
1346        /// Index into the module table that.
1347        ulong init_module;
1348
1349        /*  the init routine is defined in */
1350
1351        ///
1352        ulong reserved1;
1353
1354        ///
1355        ulong reserved2;
1356
1357        ///
1358        ulong reserved3;
1359
1360        ///
1361        ulong reserved4;
1362
1363        ///
1364        ulong reserved5;
1365
1366        ///
1367        ulong reserved6;
1368    }
1369
1370    /**
1371     * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD
1372     * "stab" style symbol table information as described in the header files
1373     * <nlist.h> and <stab.h>.
1374     */
1375    struct symtab_command
1376    {
1377        /// LC_SYMTAB.
1378        uint cmd;
1379
1380        /// Sizeof(struct symtab_command).
1381        uint cmdsize;
1382
1383        /// Symbol table offset.
1384        uint symoff;
1385
1386        /// Number of symbol table entries.
1387        uint nsyms;
1388
1389        /// String table offset.
1390        uint stroff;
1391
1392        /// String table size in bytes.
1393        uint strsize;
1394    }
1395
1396    /**
1397     * This is the second set of the symbolic information which is used to
1398     * support the data structures for the dynamically link editor.
1399     *
1400     * The original set of symbolic information in the symtab_command which contains
1401     * the symbol and string tables must also be present when this load command is
1402     * present. When this load command is present the symbol table is organized
1403     * into three groups of symbols:
1404     * * local symbols (static and debugging symbols) - grouped by module
1405     * * defined external symbols - grouped by module (sorted by name if not lib)
1406     * * undefined external symbols (sorted by name if MH_BINDATLOAD is not set,
1407     *      and in order the were seen by the static
1408     *      linker if MH_BINDATLOAD is set)
1409     *
1410     * In this load command there are offsets and counts to each of the three
1411     * groups of symbols.
1412     *
1413     * This load command contains a the offsets and sizes of the following new
1414     * symbolic information tables:
1415     * * table of contents
1416     * * module table
1417     * * reference symbol table
1418     * * indirect symbol table
1419     *
1420     * The first three tables above (the table of contents, module table and
1421     * reference symbol table) are only present if the file is a dynamically
1422     * linked shared library. For executable and object modules, which are files
1423     * containing only one module, the information that would be in these three
1424     * tables is determined as follows:
1425     * * table of contents - the defined external symbols are sorted by name
1426     * * module table - the file contains only one module so everything in the
1427     *      file is part of the module.
1428     * * reference symbol table - is the defined and undefined external symbols
1429     *
1430     * For dynamically linked shared library files this load command also
1431     * contains offsets and sizes to the pool of relocation entries for all
1432     * sections separated into two groups:
1433     * * external relocation entries
1434     * * local relocation entries
1435     *
1436     * For executable and object modules the relocation entries continue to hang
1437     * off the section structures.
1438     */
1439    struct dysymtab_command
1440    {
1441        /// LC_DYSYMTAB.
1442        uint cmd;
1443
1444        /// sizeof(struct dysymtab_command).
1445        uint cmdsize;
1446
1447        /**
1448         * Index to local symbols.
1449         *
1450         * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
1451         * are grouped into the following three groups:
1452         * * local symbols (further grouped by the module they are from)
1453         * * defined external symbols (further grouped by the module they are from)
1454         * * undefined symbols
1455         *
1456         * The local symbols are used only for debugging. The dynamic binding
1457         * process may have to use them to indicate to the debugger the local
1458         * symbols for a module that is being bound.
1459         *
1460         * The last two groups are used by the dynamic binding process to do the
1461         * binding (indirectly through the module table and the reference symbol
1462         * table when this is a dynamically linked shared library file).
1463         */
1464        uint ilocalsym;
1465
1466        /// Number of local symbols.
1467        uint nlocalsym;
1468
1469
1470
1471        /// Index to externally defined symbols.
1472        uint iextdefsym;
1473
1474        /// Number of externally defined symbols.
1475        uint nextdefsym;
1476
1477
1478
1479        /// Index to undefined symbols.
1480        uint iundefsym;
1481
1482        /// Number of undefined symbols.
1483        uint nundefsym;
1484
1485        /**
1486         * File offset to table of contents.
1487         *
1488         * For the for the dynamic binding process to find which module a symbol
1489         * is defined in the table of contents is used (analogous to the ranlib
1490         * structure in an archive) which maps defined external symbols to
1491         * modules they are defined in. This exists only in a dynamically linked
1492         * shared library file. For executable and object modules the defined
1493         * external symbols are sorted by name and is use as the table of
1494         * contents.
1495         */
1496        uint tocoff;
1497
1498        /// Number of entries in table of contents.
1499        uint ntoc;
1500
1501        /**
1502         * File offset to module table.
1503         *
1504         * To support dynamic binding of "modules" (whole object files) the
1505         * symbol table must reflect the modules that the file was created from.
1506         * This is done by having a module table that has indexes and counts
1507         * into the merged tables for each module. The module structure that
1508         * these two entries refer to is described below. This exists only in a
1509         * dynamically linked shared library file. For executable and object
1510         * modules the file only contains one module so everything in the file
1511         * belongs to the module.
1512         */
1513        uint modtaboff;
1514
1515        /// Number of module table entries.
1516        uint nmodtab;
1517
1518        /**
1519         * Offset to referenced symbol table.
1520         *
1521         * To support dynamic module binding the module structure for each
1522         * module indicates the external references (defined and undefined) each
1523         * module makes. For each module there is an offset and a count into the
1524         * reference symbol table for the symbols that the module references.
1525         * This exists only in a dynamically linked shared library file. For
1526         * executable and object modules the defined external symbols and the
1527         * undefined external symbols indicates the external references.
1528         */
1529        uint extrefsymoff;
1530
1531        /// Number of referenced symbol table entries.
1532        uint nextrefsyms;
1533
1534        /**
1535         * File offset to the indirect symbol table.
1536         *
1537         * The sections that contain "symbol pointers" and "routine stubs" have
1538         * indexes and (implied counts based on the size of the section and
1539         * fixed size of the entry) into the "indirect symbol" table for each
1540         * pointer and stub. For every section of these two types the index into
1541         * the indirect symbol table is stored in the section header in the
1542         * field reserved1. An indirect symbol table entry is simply a 32bit
1543         * index into the symbol table to the symbol that the pointer or stub is
1544         * referring to. The indirect symbol table is ordered to match the
1545         * entries in the section.
1546         */
1547        uint indirectsymoff;
1548
1549        /// Number of indirect symbol table entries.
1550        uint nindirectsyms;
1551
1552        /**
1553         * Offset to external relocation entries-
1554         *
1555         * To support relocating an individual module in a library file quickly
1556         * the external relocation entries for each module in the library need
1557         * to be accessed efficiently. Since the relocation entries can't be
1558         * accessed through the section headers for a library file they are
1559         * separated into groups of local and external entries further grouped
1560         * by module. In this case the presents of this load command who's
1561         * extreloff, nextrel, locreloff and nlocrel fields are non-zero
1562         * indicates that the relocation entries of non-merged sections are not
1563         * referenced through the section structures (and the reloff and nreloc
1564         * fields in the section headers are set to zero).
1565         *
1566         * Since the relocation entries are not accessed through the section
1567         * headers this requires the r_address field to be something other than
1568         * a section offset to identify the item to be relocated. In this case
1569         * r_address is set to the offset from the vmaddr of the first
1570         * LC_SEGMENT command. For MH_SPLIT_SEGS images r_address is set to the
1571         * offset from thevmaddr of the first read-write LC_SEGMENT command.
1572         *
1573         * The relocation entries are grouped by module and the module table
1574         * entries have indexes and counts into them for the group of external
1575         * relocation entries for that the module.
1576         *
1577         * For sections that are merged across modules there must not be any
1578         * remaining external relocation entries for them (for merged sections
1579         * remaining relocation entries must be local).
1580         */
1581        uint extreloff;
1582
1583        /// Number of external relocation entries.
1584        uint nextrel;
1585
1586        /**
1587         * Offset to local relocation entries.
1588         *
1589         * All the local relocation entries are grouped together (they are not
1590         * grouped by their module since they are only used if the object is
1591         * moved from it statically link edited address).
1592         */
1593        uint locreloff;
1594
1595        /// Number of local relocation entries.
1596        uint nlocrel;
1597    }
1598
1599    /**
1600     * An indirect symbol table entry is simply a 32bit index into the symbol
1601     * table to the symbol that the pointer or stub is referring to. Unless it
1602     * is for a non-lazy symbol pointer section for a defined symbol which
1603     * strip(1) as removed. In which case it has the value
1604     * INDIRECT_SYMBOL_LOCAL. If the symbol was also absolute
1605     * INDIRECT_SYMBOL_ABS is or'ed with that.
1606     */
1607    enum
1608    {
1609        ///
1610        INDIRECT_SYMBOL_LOCAL,
1611
1612        ///
1613        INDIRECT_SYMBOL_ABS
1614    }
1615
1616    /// A table of contents entry.
1617    struct dylib_table_of_contents
1618    {
1619        /// The defined external symbol (index into the symbol table).
1620        uint symbol_index;
1621
1622        /// Index into the module table this symbol is defined in.
1623        uint module_index;
1624    }
1625
1626    /// A module table entry.
1627    struct dylib_module
1628    {
1629        /// The module name (index into string table).
1630        uint module_name;
1631
1632
1633
1634        /// Index into externally defined symbols.
1635        uint iextdefsym;
1636
1637        /// Number of externally defined symbols.
1638        uint nextdefsym;
1639
1640        /// Index into reference symbol table.
1641        uint irefsym;
1642
1643        /// Number of reference symbol table entries.
1644        uint nrefsym;
1645
1646        /// Index into symbols for local symbols.
1647        uint ilocalsym;
1648
1649        /// Number of local symbols.
1650        uint nlocalsym;
1651
1652
1653
1654        /// Index into external relocation entries.
1655        uint iextrel;
1656
1657        /// Number of external relocation entries.
1658        uint nextrel;
1659
1660
1661
1662        /**
1663         * Low 16 bits are the index into the init section, high 16 bits are the
1664         * index into the term section.
1665         */
1666        uint iinit_iterm;
1667
1668        /**
1669         * Low 16 bits are the number of init section entries, high 16 bits are
1670         * the number of term section entries.
1671         */
1672        uint ninit_nterm;
1673
1674
1675
1676        /**
1677         * The (__OBJC,__module_info) section.
1678         *
1679         * For this module address of the start of.
1680         */
1681        uint objc_module_info_addr;
1682
1683        /**
1684         * The (__OBJC,__module_info) section.
1685         *
1686         * For this module size of.
1687         */
1688        uint objc_module_info_size;
1689    }
1690
1691    /// A 64-bit module table entry.
1692    struct dylib_module_64
1693    {
1694        /// The module name (index into string table).
1695        uint module_name;
1696
1697
1698
1699        /// Index into externally defined symbols.
1700        uint iextdefsym;
1701
1702        /// Number of externally defined symbols.
1703        uint nextdefsym;
1704
1705        /// Index into reference symbol table.
1706        uint irefsym;
1707
1708        /// Number of reference symbol table entries.
1709        uint nrefsym;
1710
1711        /// Index into symbols for local symbols.
1712        uint ilocalsym;
1713
1714        /// Number of local symbols.
1715        uint nlocalsym;
1716
1717
1718
1719        /// Index into external relocation entries.
1720        uint iextrel;
1721
1722        /// Number of external relocation entries.
1723        uint nextrel;
1724
1725
1726
1727        /**
1728         * Low 16 bits are the index into the init section, high 16 bits are the
1729         * index into the term section.
1730         */
1731        uint iinit_iterm;
1732
1733        /**
1734         * Low 16 bits are the number of init section entries, high 16 bits are
1735         * the number of term section entries.
1736         */
1737        uint ninit_nterm;
1738
1739
1740
1741        /**
1742         * The (__OBJC,__module_info) section.
1743         *
1744         * For this module size of.
1745         */
1746        uint objc_module_info_size;
1747
1748        /**
1749         * The (__OBJC,__module_info) section.
1750         *
1751         * For this module address of the start of.
1752         */
1753        ulong objc_module_info_addr;
1754    }
1755
1756    /**
1757     * The entries in the reference symbol table are used when loading the
1758     * module (both by the static and dynamic link editors) and if the module is
1759     * unloaded or replaced. Therefore all external symbols
1760     * (defined and undefined) are listed in the module's reference table. The
1761     * flags describe the type of reference that is being made. The constants
1762     * for the flags are defined in <mach-o/nlist.h> as they are also used for
1763     * symbol table entries.
1764     */
1765    struct dylib_reference
1766    {
1767        /// Index into the symbol table.
1768        @property uint isym() const pure nothrow @nogc @safe;
1769
1770        /// ditto
1771        @property void isym(uint v) @safe pure nothrow @nogc;
1772
1773        /// Flags to indicate the type of reference.
1774        @property uint flags() const pure nothrow @nogc @safe;
1775
1776        /// ditto
1777        @property void flags(uint v) pure nothrow @nogc @safe;
1778    }
1779
1780    /**
1781     * The twolevel_hints_command contains the offset and number of hints in the
1782     * two-level namespace lookup hints table.
1783     */
1784    struct twolevel_hints_command
1785    {
1786        /// LC_TWOLEVEL_HINTS.
1787        uint cmd;
1788
1789        /// Sizeof(struct twolevel_hints_command).
1790        uint cmdsize;
1791
1792        /// Offset to the hint table.
1793        uint offset;
1794
1795        /// Number of hints in the hint table.
1796        uint nhints;
1797    }
1798
1799    /**
1800     * The entries in the two-level namespace lookup hints table are
1801     * twolevel_hint structs. These provide hints to the dynamic link editor
1802     * where to start looking for an undefined symbol in a two-level namespace
1803     * image. The isub_image field is an index into the sub-images
1804     * (sub-frameworks and sub-umbrellas list) that made up the two-level image
1805     * that the undefined symbol was found in when it was built by the static
1806     * link editor. If isub-image is 0 the the symbol is expected to be defined
1807     * in library and not in the sub-images. If isub-image is non-zero it is an
1808     * index into the array of sub-images for the umbrella with the first index
1809     * in the sub-images being 1. The array of sub-images is the ordered list of
1810     * sub-images of the umbrella that would be searched for a symbol that has
1811     * the umbrella recorded as its primary library. The table of contents index
1812     * is an index into the library's table of contents. This is used as the
1813     * starting point of the binary search or a directed linear search.
1814     */
1815    struct twolevel_hint
1816    {
1817        /// Index into the sub images.
1818        @property uint isub_image() const pure nothrow @nogc @safe;
1819
1820        /// ditto
1821        @property void isub_image(uint v) pure nothrow @nogc @safe;
1822
1823        /// Index into the table of contents.
1824        @property uint itoc() const pure nothrow @nogc @safe;
1825
1826        /// ditto
1827        @property void itoc(uint v) pure nothrow @nogc @safe;
1828    }
1829
1830    /**
1831     * The prebind_cksum_command contains the value of the original check sum
1832     * for prebound files or zero. When a prebound file is first created or
1833     * modified for other than updating its prebinding information the value of
1834     * the check sum is set to zero. When the file has it prebinding re-done and
1835     * if the value of the check sum is zero the original check sum is
1836     * calculated and stored in cksum field of this load command in the output
1837     * file. If when the prebinding is re-done and the cksum field is non-zero
1838     * it is left unchanged from the input file.
1839     */
1840    struct prebind_cksum_command
1841    {
1842        /// LC_PREBIND_CKSUM.
1843        uint cmd;
1844
1845        /// Sizeof(struct prebind_cksum_command).
1846        uint cmdsize;
1847
1848        /// The check sum or zero.
1849        uint cksum;
1850    }
1851
1852    /**
1853     * The uuid load command contains a single 128-bit unique random number that
1854     * identifies an object produced by the static link editor.
1855     */
1856    struct uuid_command
1857    {
1858        /// LC_UUID.
1859        uint cmd;
1860
1861        /// Sizeof(struct uuid_command).
1862        uint cmdsize;
1863
1864        /// The 128-bit uuid.
1865        ubyte[16] uuid;
1866    }
1867
1868    /**
1869     * The rpath_command contains a path which at runtime should be added to
1870     * the current run path used to find @rpath prefixed dylibs.
1871     */
1872    struct rpath_command
1873    {
1874        /// LC_RPATH.
1875        uint cmd;
1876
1877        /// Includes string.
1878        uint cmdsize;
1879
1880        /// Path to add to run path.
1881        lc_str path;
1882    }
1883
1884    /**
1885     * The linkedit_data_command contains the offsets and sizes of a blob
1886     * of data in the __LINKEDIT segment.
1887     */
1888    struct linkedit_data_command
1889    {
1890        /**
1891         * LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS,
1892         * LC_DATA_IN_CODE, LC_DYLIB_CODE_SIGN_DRS,
1893         * LC_LINKER_OPTIMIZATION_HINT, LC_DYLD_EXPORTS_TRIE or
1894         * LC_DYLD_CHAINED_FIXUPS.
1895         */
1896        uint cmd;
1897
1898        /// Sizeof(struct linkedit_data_command).
1899        uint cmdsize;
1900
1901        /// File offset of data in __LINKEDIT segment.
1902        uint dataoff;
1903
1904        /// File size of data in __LINKEDIT segment.
1905        uint datasize;
1906
1907    }
1908
1909    /**
1910     * The encryption_info_command contains the file offset and size of an
1911     * of an encrypted segment.
1912     */
1913    struct encryption_info_command
1914    {
1915        /// LC_ENCRYPTION_INFO.
1916        uint cmd;
1917
1918        /// Sizeof(struct encryption_info_command).
1919        uint cmdsize;
1920
1921        /// File offset of encrypted range.
1922        uint cryptoff;
1923
1924        /// File size of encrypted range.
1925        uint cryptsize;
1926
1927        /// Which encryption system, 0 means not-encrypted yet.
1928        uint cryptid;
1929    }
1930
1931    /**
1932     * The encryption_info_command_64 contains the file offset and size of an
1933     * of an encrypted segment (for use in x86_64 targets).
1934     */
1935    struct encryption_info_command_64
1936    {
1937        /// LC_ENCRYPTION_INFO_64.
1938        uint cmd;
1939
1940        /// Sizeof(struct encryption_info_command_64).
1941        uint cmdsize;
1942
1943        /// File offset of encrypted range.
1944        uint cryptoff;
1945
1946        /// File size of encrypted range.
1947        uint cryptsize;
1948
1949        /// Which encryption system, 0 means not-encrypted yet.
1950        uint cryptid;
1951
1952        /// Padding to make this struct's size a multiple of 8 bytes.
1953        uint pad;
1954    }
1955
1956    /**
1957     * The version_min_command contains the min OS version on which this
1958     * binary was built to run.
1959     */
1960    struct version_min_command
1961    {
1962        /**
1963         * LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS or
1964         * LC_VERSION_MIN_WATCHOS or LC_VERSION_MIN_TVOS.
1965         */
1966        uint cmd;
1967
1968        /// Sizeof(struct min_version_command).
1969        uint cmdsize;
1970
1971        /// X.Y.Z is encoded in nibbles xxxx.yy.zz.
1972        uint version_;
1973
1974        /// X.Y.Z is encoded in nibbles xxxx.yy.zz.
1975        uint sdk;
1976    }
1977
1978    /**
1979     * The build_version_command contains the min OS version on which this
1980     * binary was built to run for its platform. The list of known platforms and
1981     * tool values following it.
1982     */
1983    struct build_version_command
1984    {
1985        /// LC_BUILD_VERSION.
1986        uint cmd;
1987
1988        /**
1989         * Sizeof(struct build_version_command) plus ntools
1990         * sizeof(struct build_tool_version).
1991         */
1992        uint cmdsize;
1993
1994        /// Platform.
1995        uint platform;
1996
1997        /// X.Y.Z is encoded in nibbles xxxx.yy.zz.
1998        uint minos;
1999
2000        /// X.Y.Z is encoded in nibbles xxxx.yy.zz.
2001        uint sdk;
2002
2003        /// Number of tool entries following this.
2004        uint ntools;
2005
2006    }
2007
2008    ///
2009    struct build_tool_version
2010    {
2011        /// Enum for the tool.
2012        uint tool;
2013
2014        /// Version number of the tool.
2015        uint version_;
2016    }
2017
2018    /// Known values for the platform field above.
2019    enum
2020    {
2021        ///
2022        PLATFORM_MACOS,
2023
2024        ///
2025        PLATFORM_IOS,
2026
2027        ///
2028        PLATFORM_TVOS,
2029
2030        ///
2031        PLATFORM_WATCHOS,
2032
2033        ///
2034        PLATFORM_BRIDGEOS,
2035
2036        ///
2037        PLATFORM_UIKITFORMAC,
2038
2039        ///
2040        PLATFORM_IOSSIMULATOR,
2041
2042        ///
2043        PLATFORM_TVOSSIMULATOR,
2044
2045        ///
2046        PLATFORM_WATCHOSSIMULATOR,
2047
2048        ///
2049        PLATFORM_DRIVERKIT
2050    }
2051
2052
2053    /// Known values for the tool field above.
2054    enum
2055    {
2056        ///
2057        TOOL_CLANG,
2058
2059        ///
2060        TOOL_SWIFT,
2061
2062        ///
2063        TOOL_LD
2064    }
2065
2066    /**
2067     * The dyld_info_command contains the file offsets and sizes of
2068     * the new compressed form of the information dyld needs to
2069     * load the image. This information is used by dyld on Mac OS X
2070     * 10.6 and later. All information pointed to by this command
2071     * is encoded using byte streams, so no endian swapping is needed
2072     * to interpret it.
2073     */
2074    struct dyld_info_command
2075    {
2076        /// LC_DYLD_INFO or LC_DYLD_INFO_ONLY.
2077        uint cmd;
2078
2079        /// Sizeof(struct dyld_info_command).
2080        uint cmdsize;
2081
2082
2083
2084        /**
2085         * File offset to rebase info.
2086         *
2087         * Dyld rebases an image whenever dyld loads it at an address different
2088         * from its preferred address. The rebase information is a stream
2089         * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_.
2090         * Conceptually the rebase information is a table of tuples:
2091         *    <seg-index, seg-offset, type>
2092         * The opcodes are a compressed way to encode the table by only
2093         * encoding when a column changes. In addition simple patterns
2094         * like "every n'th offset for m times" can be encoded in a few
2095         * bytes.
2096         */
2097        uint rebase_off;
2098
2099        /// Size of rebase info.
2100        uint rebase_size;
2101
2102
2103
2104        /**
2105         * File offset to binding info.
2106         *
2107         * Dyld binds an image during the loading process, if the image
2108         * requires any pointers to be initialized to symbols in other images.
2109         * The bind information is a stream of byte sized
2110         * opcodes whose symbolic names start with BIND_OPCODE_.
2111         * Conceptually the bind information is a table of tuples:
2112         *    <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
2113         * The opcodes are a compressed way to encode the table by only
2114         * encoding when a column changes. In addition simple patterns
2115         * like for runs of pointers initialzed to the same value can be
2116         * encoded in a few bytes.
2117         */
2118        uint bind_off;
2119
2120        /// Size of binding info.
2121        uint bind_size;
2122
2123
2124
2125        /**
2126         * File offset to weak binding info.
2127         *
2128         * Some C++ programs require dyld to unique symbols so that all
2129         * images in the process use the same copy of some code/data.
2130         * This step is done after binding. The content of the weak_bind
2131         * info is an opcode stream like the bind_info. But it is sorted
2132         * alphabetically by symbol name. This enable dyld to walk
2133         * all images with weak binding information in order and look
2134         * for collisions. If there are no collisions, dyld does
2135         * no updating. That means that some fixups are also encoded
2136         * in the bind_info. For instance, all calls to "operator new"
2137         * are first bound to libstdc++.dylib using the information
2138         * in bind_info. Then if some image overrides operator new
2139         * that is detected when the weak_bind information is processed
2140         * and the call to operator new is then rebound.
2141         */
2142        uint weak_bind_off;
2143
2144        /// Size of weak binding info.
2145        uint weak_bind_size;
2146
2147
2148
2149        /**
2150         * File offset to lazy binding info.
2151         *
2152         * Some uses of external symbols do not need to be bound immediately.
2153         * Instead they can be lazily bound on first use. The lazy_bind
2154         * are contains a stream of BIND opcodes to bind all lazy symbols.
2155         * Normal use is that dyld ignores the lazy_bind section when
2156         * loading an image. Instead the static linker arranged for the
2157         * lazy pointer to initially point to a helper function which
2158         * pushes the offset into the lazy_bind area for the symbol
2159         * needing to be bound, then jumps to dyld which simply adds
2160         * the offset to lazy_bind_off to get the information on what
2161         * to bind.
2162         */
2163        uint lazy_bind_off;
2164
2165        /// Size of lazy binding infs.
2166        uint lazy_bind_size;
2167
2168
2169
2170        /**
2171         * File offset to lazy binding info.
2172         *
2173         * The symbols exported by a dylib are encoded in a trie. This
2174         * is a compact representation that factors out common prefixes.
2175         * It also reduces LINKEDIT pages in RAM because it encodes all
2176         * information (name, address, flags) in one small, contiguous range.
2177         * The export area is a stream of nodes. The first node sequentially
2178         * is the start node for the trie.
2179         *
2180         * Nodes for a symbol start with a uleb128 that is the length of
2181         * the exported symbol information for the string so far.
2182         * If there is no exported symbol, the node starts with a zero byte.
2183         * If there is exported info, it follows the length.
2184         *
2185         * First is a uleb128 containing flags. Normally, it is followed by
2186         * a uleb128 encoded offset which is location of the content named
2187         * by the symbol from the mach_header for the image. If the flags
2188         * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is
2189         * a uleb128 encoded library ordinal, then a zero terminated
2190         * UTF8 string. If the string is zero length, then the symbol
2191         * is re-export from the specified dylib with the same name.
2192         * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following
2193         * the flags is two uleb128s: the stub offset and the resolver offset.
2194         * The stub is used by non-lazy pointers. The resolver is used
2195         * by lazy pointers and must be called to get the actual address to use.
2196         *
2197         * After the optional exported symbol information is a byte of
2198         * how many edges (0-255) that this node has leaving it,
2199         * followed by each edge.
2200         * Each edge is a zero terminated UTF8 of the addition chars
2201         * in the symbol, followed by a uleb128 offset for the node that
2202         * edge points to.
2203         *
2204         */
2205        uint export_off;
2206
2207        /// Size of lazy binding infs.
2208        uint export_size;
2209    }
2210
2211    /// The following are used to encode rebasing information.
2212    enum
2213    {
2214        ///
2215        REBASE_TYPE_POINTER,
2216
2217        ///
2218        REBASE_TYPE_TEXT_ABSOLUTE32,
2219
2220        ///
2221        REBASE_TYPE_TEXT_PCREL32,
2222
2223
2224
2225        ///
2226        REBASE_OPCODE_MASK,
2227
2228        ///
2229        REBASE_IMMEDIATE_MASK,
2230
2231        ///
2232        REBASE_OPCODE_DONE,
2233
2234        ///
2235        REBASE_OPCODE_SET_TYPE_IMM,
2236
2237        ///
2238        REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB,
2239
2240        ///
2241        REBASE_OPCODE_ADD_ADDR_ULEB,
2242
2243        ///
2244        REBASE_OPCODE_ADD_ADDR_IMM_SCALED,
2245
2246        ///
2247        REBASE_OPCODE_DO_REBASE_IMM_TIMES,
2248
2249        ///
2250        REBASE_OPCODE_DO_REBASE_ULEB_TIMES,
2251
2252        ///
2253        REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB,
2254
2255        ///
2256        REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
2257    }
2258
2259
2260    /// The following are used to encode binding information.
2261    enum
2262    {
2263        ///
2264        BIND_TYPE_POINTER,
2265
2266        ///
2267        BIND_TYPE_TEXT_ABSOLUTE32,
2268
2269        ///
2270        BIND_TYPE_TEXT_PCREL32,
2271
2272
2273
2274        ///
2275        BIND_SPECIAL_DYLIB_SELF,
2276
2277        ///
2278        BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE,
2279
2280        ///
2281        BIND_SPECIAL_DYLIB_FLAT_LOOKUP,
2282
2283        ///
2284        BIND_SPECIAL_DYLIB_WEAK_LOOKUP,
2285
2286
2287
2288        ///
2289        BIND_SYMBOL_FLAGS_WEAK_IMPORT,
2290
2291        ///
2292        BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION,
2293
2294
2295
2296        ///
2297        BIND_OPCODE_MASK,
2298
2299        ///
2300        BIND_IMMEDIATE_MASK,
2301
2302        ///
2303        BIND_OPCODE_DONE,
2304
2305        ///
2306        BIND_OPCODE_SET_DYLIB_ORDINAL_IMM,
2307
2308        ///
2309        BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB,
2310
2311        ///
2312        BIND_OPCODE_SET_DYLIB_SPECIAL_IMM,
2313
2314        ///
2315        BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM,
2316
2317        ///
2318        BIND_OPCODE_SET_TYPE_IMM,
2319
2320        ///
2321        BIND_OPCODE_SET_ADDEND_SLEB,
2322
2323        ///
2324        BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB,
2325
2326        ///
2327        BIND_OPCODE_ADD_ADDR_ULEB,
2328
2329        ///
2330        BIND_OPCODE_DO_BIND,
2331
2332        ///
2333        BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB,
2334
2335        ///
2336        BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED,
2337
2338        ///
2339        BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB,
2340
2341        ///
2342        BIND_OPCODE_THREADED,
2343
2344        ///
2345        BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB,
2346
2347        ///
2348        BIND_SUBOPCODE_THREADED_APPLY
2349    }
2350
2351    /**
2352     * The following are used on the flags byte of a terminal node
2353     * in the export information.
2354     */
2355    enum
2356    {
2357
2358        ///
2359        EXPORT_SYMBOL_FLAGS_KIND_MASK,
2360
2361        ///
2362        EXPORT_SYMBOL_FLAGS_KIND_REGULAR,
2363
2364        ///
2365        EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL,
2366
2367        ///
2368        EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE,
2369
2370        ///
2371        EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION,
2372
2373        ///
2374        EXPORT_SYMBOL_FLAGS_REEXPORT,
2375
2376        ///
2377        EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER,
2378
2379    }
2380
2381
2382    /*
2383     * The linker_option_command contains linker options embedded in object files.
2384     */
2385    struct linker_option_command
2386    {
2387        /// LC_LINKER_OPTION only used in MH_OBJECT filetypes.
2388        uint cmd;
2389
2390        ///
2391        uint cmdsize;
2392
2393        /**
2394         * Number of strings concatenation of zero terminated UTF8 strings.
2395         * Zero filled at end to align.
2396         */
2397        uint count;
2398    }
2399
2400    /**
2401     * The symseg_command contains the offset and size of the GNU style
2402     * symbol table information as described in the header file <symseg.h>.
2403     * The symbol roots of the symbol segments must also be aligned properly
2404     * in the file. So the requirement of keeping the offsets aligned to a
2405     * multiple of a 4 bytes translates to the length field of the symbol
2406     * roots also being a multiple of a long. Also the padding must again be
2407     * zeroed. (THIS IS OBSOLETE and no longer supported).
2408     */
2409    struct symseg_command
2410    {
2411        /// LC_SYMSEG.
2412        uint cmd;
2413
2414        /// Sizeof(struct symseg_command).
2415        uint cmdsize;
2416
2417        /// Symbol segment offset.
2418        uint offset;
2419
2420        /// Symbol segment size in bytes.
2421        uint size;
2422    }
2423
2424    /**
2425     * The ident_command contains a free format string table following the
2426     * ident_command structure. The strings are null terminated and the size of
2427     * the command is padded out with zero bytes to a multiple of 4 bytes/
2428     * (THIS IS OBSOLETE and no longer supported).
2429     */
2430    struct ident_command
2431    {
2432        /// LC_IDENT.
2433        uint cmd;
2434
2435        /// Strings that follow this command.
2436        uint cmdsize;
2437    }
2438
2439    /**
2440     * The fvmfile_command contains a reference to a file to be loaded at the
2441     * specified virtual address. (Presently, this command is reserved for
2442     * internal use. The kernel ignores this command when loading a program into
2443     * memory).
2444     */
2445    struct fvmfile_command
2446    {
2447        /// LC_FVMFILE.
2448        uint cmd;
2449
2450        /// Includes pathname string.
2451        uint cmdsize;
2452
2453        /// Files pathname.
2454        lc_str name;
2455
2456        /// Files virtual address.
2457        uint header_addr;
2458    }
2459
2460    /**
2461     * The entry_point_command is a replacement for thread_command.
2462     * It is used for main executables to specify the location (file offset)
2463     * of main(). If -stack_size was used at link time, the stacksize
2464     * field will contain the stack size need for the main thread.
2465     */
2466    struct entry_point_command
2467    {
2468        /// LC_MAIN only used in MH_EXECUTE filetypes.
2469        uint cmd;
2470
2471        /// 24.
2472        uint cmdsize;
2473
2474        /// File (__TEXT) offset of main().
2475        ulong entryoff;
2476
2477        /// If not zero, initial stack size.
2478        ulong stacksize;
2479    }
2480
2481    /**
2482     * The source_version_command is an optional load command containing
2483     * the version of the sources used to build the binary.
2484     */
2485    struct source_version_command
2486    {
2487        /// LC_SOURCE_VERSION.
2488        uint cmd;
2489
2490        /// 16.
2491        uint cmdsize;
2492
2493        /// A.B.C.D.E packed as a24.b10.c10.d10.e10.
2494        ulong version_;
2495    }
2496
2497    /**
2498     * The LC_DATA_IN_CODE load commands uses a linkedit_data_command
2499     * to point to an array of data_in_code_entry entries. Each entry
2500     * describes a range of data in a code section.
2501     */
2502    struct data_in_code_entry
2503    {
2504        /// From mach_header to start of data range.
2505        uint offset;
2506
2507        /// Number of bytes in data range.
2508        ushort length;
2509
2510        /// A DICE_KIND_* value.
2511        ushort kind;
2512    }
2513
2514    ///
2515    enum
2516    {
2517        ///
2518        DICE_KIND_DATA,
2519
2520        ///
2521        DICE_KIND_JUMP_TABLE8,
2522
2523        ///
2524        DICE_KIND_JUMP_TABLE16,
2525
2526        ///
2527        DICE_KIND_JUMP_TABLE32,
2528
2529        ///
2530        DICE_KIND_ABS_JUMP_TABLE32
2531    }
2532
2533    /**
2534     * Sections of type S_THREAD_LOCAL_VARIABLES contain an array
2535     * of tlv_descriptor structures.
2536     */
2537    struct tlv_descriptor
2538    {
2539        ///
2540        void* function (tlv_descriptor*) thunk;
2541
2542        ///
2543        c_ulong key;
2544
2545        ///
2546        c_ulong offset;
2547    }
2548
2549    /**
2550     * LC_NOTE commands describe a region of arbitrary data included in a Mach-O
2551     * file. Its initial use is to record extra data in MH_CORE files.
2552     */
2553    struct note_command
2554    {
2555        /// LC_NOTE.
2556        uint cmd;
2557
2558        /// Sizeof(struct note_command).
2559        uint cmdsize;
2560
2561        /// Owner name for this LC_NOTE.
2562        char[16] data_owner;
2563
2564        /// File offset of this data.
2565        ulong offset;
2566
2567        /// Length of data region.
2568        ulong size;
2569    }
2570}
2571else
2572    version = Darwin;
2573
2574version (Darwin):
2575extern (C):
2576
2577struct mach_header
2578{
2579    uint magic;
2580    int cputype;
2581    int cpusubtype;
2582    uint filetype;
2583    uint ncmds;
2584    uint sizeofcmds;
2585    uint flags;
2586}
2587
2588enum
2589{
2590    MH_MAGIC = 0xfeedface,
2591    MH_CIGAM = 0xcefaedfe
2592}
2593
2594struct mach_header_64
2595{
2596    uint magic;
2597    int cputype;
2598    int cpusubtype;
2599    uint filetype;
2600    uint ncmds;
2601    uint sizeofcmds;
2602    uint flags;
2603    uint reserved;
2604}
2605
2606enum
2607{
2608    MH_MAGIC_64 = 0xfeedfacf,
2609    MH_CIGAM_64 = 0xcffaedfe
2610}
2611
2612enum
2613{
2614    MH_OBJECT = 0x1,
2615    MH_EXECUTE = 0x2,
2616    MH_FVMLIB = 0x3,
2617    MH_CORE = 0x4,
2618    MH_PRELOAD = 0x5,
2619    MH_DYLIB = 0x6,
2620    MH_DYLINKER = 0x7,
2621    MH_BUNDLE = 0x8,
2622    MH_DYLIB_STUB = 0x9,
2623    MH_DSYM = 0xa,
2624    MH_KEXT_BUNDLE = 0xb
2625}
2626
2627enum
2628{
2629    MH_NOUNDEFS = 0x1,
2630    MH_INCRLINK = 0x2,
2631    MH_DYLDLINK = 0x4,
2632    MH_BINDATLOAD = 0x8,
2633    MH_PREBOUND = 0x10,
2634    MH_SPLIT_SEGS = 0x20,
2635    MH_LAZY_INIT = 0x40,
2636    MH_TWOLEVEL = 0x80,
2637    MH_FORCE_FLAT = 0x100,
2638    MH_NOMULTIDEFS = 0x200,
2639    MH_NOFIXPREBINDING = 0x400,
2640    MH_PREBINDABLE = 0x800,
2641    MH_ALLMODSBOUND = 0x1000,
2642    MH_SUBSECTIONS_VIA_SYMBOLS = 0x2000,
2643    MH_CANONICAL = 0x4000,
2644    MH_WEAK_DEFINES = 0x8000,
2645    MH_BINDS_TO_WEAK = 0x10000,
2646
2647    MH_ALLOW_STACK_EXECUTION = 0x20000,
2648    MH_ROOT_SAFE = 0x40000,
2649
2650    MH_SETUID_SAFE = 0x80000,
2651    MH_NO_REEXPORTED_DYLIBS = 0x100000,
2652    MH_PIE = 0x200000,
2653    MH_DEAD_STRIPPABLE_DYLIB = 0x400000,
2654    MH_HAS_TLV_DESCRIPTORS = 0x800000,
2655
2656    MH_NO_HEAP_EXECUTION = 0x1000000,
2657
2658    MH_APP_EXTENSION_SAFE = 0x02000000,
2659
2660    MH_NLIST_OUTOFSYNC_WITH_DYLDINFO = 0x04000000,
2661
2662    MH_SIM_SUPPORT = 0x08000000,
2663
2664    MH_DYLIB_IN_CACHE = 0x80000000
2665}
2666
2667struct load_command
2668{
2669    uint cmd;
2670    uint cmdsize;
2671}
2672
2673enum LC_REQ_DYLD = 0x80000000;
2674
2675enum
2676{
2677    LC_SEGMENT = 0x1,
2678    LC_SYMTAB = 0x2,
2679    LC_SYMSEG = 0x3,
2680    LC_THREAD = 0x4,
2681    LC_UNIXTHREAD = 0x5,
2682    LC_LOADFVMLIB = 0x6,
2683    LC_IDFVMLIB = 0x7,
2684    LC_IDENT = 0x8,
2685    LC_FVMFILE = 0x9,
2686    LC_PREPAGE = 0xa,
2687    LC_DYSYMTAB = 0xb,
2688    LC_LOAD_DYLIB = 0xc,
2689    LC_ID_DYLIB = 0xd,
2690    LC_LOAD_DYLINKER = 0xe,
2691    LC_ID_DYLINKER = 0xf,
2692    LC_PREBOUND_DYLIB = 0x10,
2693    LC_ROUTINES = 0x11,
2694    LC_SUB_FRAMEWORK = 0x12,
2695    LC_SUB_UMBRELLA = 0x13,
2696    LC_SUB_CLIENT = 0x14,
2697    LC_SUB_LIBRARY = 0x15,
2698    LC_TWOLEVEL_HINTS = 0x16,
2699    LC_PREBIND_CKSUM = 0x17
2700}
2701
2702enum LC_LOAD_WEAK_DYLIB = 0x18 | LC_REQ_DYLD;
2703
2704enum
2705{
2706    LC_SEGMENT_64 = 0x19,
2707    LC_ROUTINES_64 = 0x1a,
2708    LC_UUID = 0x1b,
2709    LC_RPATH = 0x1c | LC_REQ_DYLD,
2710    LC_CODE_SIGNATURE = 0x1d,
2711    LC_SEGMENT_SPLIT_INFO = 0x1e,
2712    LC_REEXPORT_DYLIB = 0x1f | LC_REQ_DYLD,
2713    LC_LAZY_LOAD_DYLIB = 0x20,
2714    LC_ENCRYPTION_INFO = 0x21,
2715    LC_DYLD_INFO = 0x22,
2716    LC_DYLD_INFO_ONLY = 0x22 | LC_REQ_DYLD,
2717    LC_LOAD_UPWARD_DYLIB = 0x23 | LC_REQ_DYLD,
2718    LC_VERSION_MIN_MACOSX = 0x24,
2719    LC_VERSION_MIN_IPHONEOS = 0x25,
2720    LC_FUNCTION_STARTS = 0x26,
2721    LC_DYLD_ENVIRONMENT = 0x27,
2722    LC_MAIN = 0x28 | LC_REQ_DYLD,
2723    LC_DATA_IN_CODE = 0x29,
2724    LC_SOURCE_VERSION = 0x2A,
2725    LC_DYLIB_CODE_SIGN_DRS = 0x2B,
2726    LC_ENCRYPTION_INFO_64 = 0x2C,
2727    LC_LINKER_OPTION = 0x2D,
2728    LC_LINKER_OPTIMIZATION_HINT = 0x2E,
2729    LC_VERSION_MIN_TVOS = 0x2F,
2730    LC_VERSION_MIN_WATCHOS = 0x30,
2731    LC_NOTE = 0x31,
2732    LC_BUILD_VERSION = 0x32,
2733    LC_DYLD_EXPORTS_TRIE = 0x33 | LC_REQ_DYLD,
2734    LC_DYLD_CHAINED_FIXUPS = 0x34 | LC_REQ_DYLD
2735}
2736
2737union lc_str
2738{
2739    uint offset;
2740
2741    version (D_LP64) {}
2742    else
2743        char* ptr;
2744}
2745
2746struct segment_command
2747{
2748    uint cmd;
2749    uint cmdsize;
2750    char[16] segname = 0;
2751    uint vmaddr;
2752    uint vmsize;
2753    uint fileoff;
2754    uint filesize;
2755    int maxprot;
2756    int initprot;
2757    uint nsects;
2758    uint flags;
2759}
2760
2761struct segment_command_64
2762{
2763    uint cmd;
2764    uint cmdsize;
2765    char[16] segname = 0;
2766    ulong vmaddr;
2767    ulong vmsize;
2768    ulong fileoff;
2769    ulong filesize;
2770    int maxprot;
2771    int initprot;
2772    uint nsects;
2773    uint flags;
2774}
2775
2776enum
2777{
2778    SG_HIGHVM = 0x1,
2779    SG_FVMLIB = 0x2,
2780    SG_NORELOC = 0x4,
2781    SG_PROTECTED_VERSION_1 = 0x8,
2782    SG_READ_ONLY = 0x10
2783}
2784
2785struct section
2786{
2787    char[16] sectname = 0;
2788    char[16] segname = 0;
2789    uint addr;
2790    uint size;
2791    uint offset;
2792    uint align_;
2793    uint reloff;
2794    uint nreloc;
2795    uint flags;
2796    uint reserved1;
2797    uint reserved2;
2798}
2799
2800struct section_64
2801{
2802    char[16] sectname = 0;
2803    char[16] segname = 0;
2804    ulong addr;
2805    ulong size;
2806    uint offset;
2807    uint align_;
2808    uint reloff;
2809    uint nreloc;
2810    uint flags;
2811    uint reserved1;
2812    uint reserved2;
2813    uint reserved3;
2814}
2815
2816
2817enum
2818{
2819    SECTION_TYPE = 0x000000ff,
2820    SECTION_ATTRIBUTES = 0xffffff00
2821}
2822
2823enum
2824{
2825    S_REGULAR = 0x0,
2826    S_ZEROFILL = 0x1,
2827    S_CSTRING_LITERALS = 0x2,
2828    S_4BYTE_LITERALS = 0x3,
2829    S_8BYTE_LITERALS = 0x4,
2830    S_LITERAL_POINTERS = 0x5,
2831    S_NON_LAZY_SYMBOL_POINTERS = 0x6,
2832    S_LAZY_SYMBOL_POINTERS = 0x7,
2833    S_SYMBOL_STUBS = 0x8,
2834    S_MOD_INIT_FUNC_POINTERS = 0x9,
2835    S_MOD_TERM_FUNC_POINTERS = 0xa,
2836    S_COALESCED = 0xb,
2837    S_GB_ZEROFILL = 0xc,
2838    S_INTERPOSING = 0xd,
2839    S_16BYTE_LITERALS = 0xe,
2840    S_DTRACE_DOF = 0xf,
2841    S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10,
2842
2843    S_THREAD_LOCAL_REGULAR = 0x11,
2844    S_THREAD_LOCAL_ZEROFILL = 0x12,
2845    S_THREAD_LOCAL_VARIABLES = 0x13,
2846    S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14,
2847    S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15,
2848    S_INIT_FUNC_OFFSETS = 0x16
2849}
2850
2851enum
2852{
2853    SECTION_ATTRIBUTES_USR = 0xff000000,
2854    S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
2855    S_ATTR_NO_TOC = 0x40000000,
2856    S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
2857    S_ATTR_NO_DEAD_STRIP = 0x10000000,
2858    S_ATTR_LIVE_SUPPORT = 0x08000000,
2859    S_ATTR_SELF_MODIFYING_CODE = 0x04000000,
2860    S_ATTR_DEBUG = 0x02000000,
2861    SECTION_ATTRIBUTES_SYS = 0x00ffff00,
2862    S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
2863    S_ATTR_EXT_RELOC = 0x00000200,
2864    S_ATTR_LOC_RELOC = 0x00000100
2865}
2866
2867enum
2868{
2869    SEG_PAGEZERO = "__PAGEZERO",
2870
2871    SEG_TEXT = "__TEXT",
2872    SECT_TEXT = "__text",
2873    SECT_FVMLIB_INIT0 = "__fvmlib_init0",
2874    SECT_FVMLIB_INIT1 = "__fvmlib_init1",
2875
2876    SEG_DATA = "__DATA",
2877    SECT_DATA = "__data",
2878    SECT_BSS = "__bss",
2879    SECT_COMMON = "__common",
2880
2881    SEG_OBJC = "__OBJC",
2882    SECT_OBJC_SYMBOLS = "__symbol_table",
2883    SECT_OBJC_MODULES = "__module_info",
2884    SECT_OBJC_STRINGS = "__selector_strs",
2885    SECT_OBJC_REFS = "__selector_refs",
2886
2887    SEG_ICON = "__ICON",
2888    SECT_ICON_HEADER = "__header",
2889    SECT_ICON_TIFF = "__tiff",
2890
2891    SEG_LINKEDIT = "__LINKEDIT",
2892
2893    SEG_UNIXSTACK = "__UNIXSTACK",
2894
2895    SEG_IMPORT = "__IMPORT"
2896}
2897
2898struct fvmlib
2899{
2900    lc_str name;
2901    uint minor_version;
2902    uint header_addr;
2903}
2904
2905struct fvmlib_command
2906{
2907    uint cmd;
2908    uint cmdsize;
2909    fvmlib fvmlib_;
2910}
2911
2912struct dylib
2913{
2914    lc_str name;
2915    uint timestamp;
2916    uint current_version;
2917    uint compatibility_version;
2918}
2919
2920struct dylib_command
2921{
2922    uint cmd;
2923    uint cmdsize;
2924    dylib dylib_;
2925}
2926
2927struct sub_framework_command
2928{
2929    uint cmd;
2930    uint cmdsize;
2931    lc_str umbrella;
2932}
2933
2934struct sub_client_command
2935{
2936    uint cmd;
2937    uint cmdsize;
2938    lc_str client;
2939}
2940
2941struct sub_umbrella_command
2942{
2943    uint cmd;
2944    uint cmdsize;
2945    lc_str sub_umbrella;
2946}
2947
2948struct sub_library_command
2949{
2950    uint cmd;
2951    uint cmdsize;
2952    lc_str sub_library;
2953}
2954
2955struct prebound_dylib_command
2956{
2957    uint cmd;
2958    uint cmdsize;
2959    lc_str name;
2960    uint nmodules;
2961    lc_str linked_modules;
2962}
2963
2964struct dylinker_command
2965{
2966    uint cmd;
2967    uint cmdsize;
2968    lc_str name;
2969}
2970
2971struct thread_command
2972{
2973    uint cmd;
2974    uint cmdsize;
2975}
2976
2977struct routines_command
2978{
2979    uint cmd;
2980    uint cmdsize;
2981    uint init_address;
2982    uint init_module;
2983    uint reserved1;
2984    uint reserved2;
2985    uint reserved3;
2986    uint reserved4;
2987    uint reserved5;
2988    uint reserved6;
2989}
2990
2991struct routines_command_64
2992{
2993    uint cmd;
2994    uint cmdsize;
2995    ulong init_address;
2996    ulong init_module;
2997    ulong reserved1;
2998    ulong reserved2;
2999    ulong reserved3;
3000    ulong reserved4;
3001    ulong reserved5;
3002    ulong reserved6;
3003}
3004
3005struct symtab_command
3006{
3007    uint cmd;
3008    uint cmdsize;
3009    uint symoff;
3010    uint nsyms;
3011    uint stroff;
3012    uint strsize;
3013}
3014
3015struct dysymtab_command
3016{
3017    uint cmd;
3018    uint cmdsize;
3019
3020    uint ilocalsym;
3021    uint nlocalsym;
3022
3023    uint iextdefsym;
3024    uint nextdefsym;
3025
3026    uint iundefsym;
3027    uint nundefsym;
3028
3029    uint tocoff;
3030    uint ntoc;
3031
3032    uint modtaboff;
3033    uint nmodtab;
3034
3035    uint extrefsymoff;
3036    uint nextrefsyms;
3037
3038    uint indirectsymoff;
3039    uint nindirectsyms;
3040
3041    uint extreloff;
3042    uint nextrel;
3043
3044    uint locreloff;
3045    uint nlocrel;
3046}
3047
3048enum
3049{
3050    INDIRECT_SYMBOL_LOCAL = 0x80000000,
3051    INDIRECT_SYMBOL_ABS = 0x40000000
3052}
3053
3054struct dylib_table_of_contents
3055{
3056    uint symbol_index;
3057    uint module_index;
3058}
3059
3060struct dylib_module
3061{
3062    uint module_name;
3063
3064    uint iextdefsym;
3065    uint nextdefsym;
3066    uint irefsym;
3067    uint nrefsym;
3068    uint ilocalsym;
3069    uint nlocalsym;
3070
3071    uint iextrel;
3072    uint nextrel;
3073
3074    uint iinit_iterm;
3075    uint ninit_nterm;
3076
3077    uint objc_module_info_addr;
3078    uint objc_module_info_size;
3079}
3080
3081struct dylib_module_64
3082{
3083    uint module_name;
3084
3085    uint iextdefsym;
3086    uint nextdefsym;
3087    uint irefsym;
3088    uint nrefsym;
3089    uint ilocalsym;
3090    uint nlocalsym;
3091
3092    uint iextrel;
3093    uint nextrel;
3094
3095    uint iinit_iterm;
3096    uint ninit_nterm;
3097
3098    uint objc_module_info_size;
3099    ulong objc_module_info_addr;
3100}
3101
3102struct dylib_reference
3103{
3104    private uint storage;
3105
3106    @property uint isym()() const pure nothrow @nogc @safe
3107    {
3108        return cast(uint) ((storage & 16777215U) >> 0U);
3109    }
3110
3111    @property void isym()(uint v) @safe pure nothrow @nogc
3112    in(v >= 0U, "Value is smaller than the minimum value of bitfield 'isym'")
3113    in(v <= 16777215U, "Value is greater than the maximum value of bitfield 'isym'")
3114    {
3115        storage = cast(uint) ((storage & (-1 - cast(uint) 16777215U)) |
3116            ((cast(uint) v << 0U) & 16777215U));
3117    }
3118
3119    @property uint flags()() const pure nothrow @nogc @safe
3120    {
3121        return cast(uint) ((storage & 4278190080U) >> 24U);
3122    }
3123
3124    @property void flags()(uint v) pure nothrow @nogc @safe
3125    in(v >= 0U, "Value is smaller than the minimum value of bitfield 'flags'")
3126    in(v <= 255U, "Value is greater than the maximum value of bitfield 'flags'")
3127    {
3128        storage = cast(uint) ((storage & (-1 - cast(uint) 4278190080U)) |
3129            ((cast(uint) v << 24U) & 4278190080U));
3130    }
3131}
3132
3133struct twolevel_hints_command
3134{
3135    uint cmd;
3136    uint cmdsize;
3137    uint offset;
3138    uint nhints;
3139}
3140
3141struct twolevel_hint
3142{
3143    private uint storage;
3144
3145    @property uint isub_image()() const pure nothrow @nogc @safe
3146    {
3147        return cast(uint) ((storage & 255U) >>0U);
3148    }
3149
3150    @property void isub_image()(uint v) pure nothrow @nogc @safe
3151    in(v >= 0U, "Value is smaller than the minimum value of bitfield 'isub_image'")
3152    in(v <= 255U, "Value is greater than the maximum value of bitfield 'isub_image'")
3153    {
3154        storage = cast(uint) ((storage & (-1-cast(uint)255U)) |
3155            ((cast(uint) v << 0U) & 255U));
3156    }
3157
3158    @property uint itoc()() const pure nothrow @nogc @safe
3159    {
3160        return cast(uint) ((storage & 4294967040U) >>8U);
3161    }
3162
3163    @property void itoc()(uint v) pure nothrow @nogc @safe
3164    in(v >= 0U, "Value is smaller than the minimum value of bitfield 'itoc'")
3165    in(v <= 16777215U, "Value is greater than the maximum value of bitfield 'itoc'")
3166    {
3167        storage = cast(uint) ((storage & (-1-cast(uint)4294967040U)) |
3168            ((cast(uint) v << 8U) & 4294967040U));
3169    }
3170}
3171
3172struct prebind_cksum_command
3173{
3174    uint cmd;
3175    uint cmdsize;
3176    uint cksum;
3177}
3178
3179struct uuid_command
3180{
3181    uint cmd;
3182    uint cmdsize;
3183    ubyte[16] uuid;
3184}
3185
3186struct rpath_command
3187{
3188    uint cmd;
3189    uint cmdsize;
3190    lc_str path;
3191}
3192
3193struct linkedit_data_command
3194{
3195    uint cmd;
3196    uint cmdsize;
3197    uint dataoff;
3198    uint datasize;
3199}
3200
3201struct encryption_info_command
3202{
3203    uint cmd;
3204    uint cmdsize;
3205    uint cryptoff;
3206    uint cryptsize;
3207    uint cryptid;
3208}
3209
3210struct encryption_info_command_64
3211{
3212    uint cmd;
3213    uint cmdsize;
3214    uint cryptoff;
3215    uint cryptsize;
3216    uint cryptid;
3217    uint pad;
3218}
3219
3220struct version_min_command
3221{
3222    uint cmd;
3223    uint cmdsize;
3224    uint version_;
3225    uint sdk;
3226}
3227
3228struct build_version_command
3229{
3230    uint cmd;
3231    uint cmdsize;
3232
3233    uint platform;
3234    uint minos;
3235    uint sdk;
3236    uint ntools;
3237}
3238
3239struct build_tool_version
3240{
3241    uint tool;
3242    uint version_;
3243}
3244
3245enum
3246{
3247    PLATFORM_MACOS = 1,
3248    PLATFORM_IOS = 2,
3249    PLATFORM_TVOS = 3,
3250    PLATFORM_WATCHOS = 4,
3251    PLATFORM_BRIDGEOS = 5,
3252    PLATFORM_UIKITFORMAC = 6,
3253    PLATFORM_IOSSIMULATOR = 7,
3254    PLATFORM_TVOSSIMULATOR = 8,
3255    PLATFORM_WATCHOSSIMULATOR = 9,
3256    PLATFORM_DRIVERKIT = 10
3257}
3258
3259enum
3260{
3261    TOOL_CLANG = 1,
3262    TOOL_SWIFT = 2,
3263    TOOL_LD = 3
3264}
3265
3266struct dyld_info_command
3267{
3268    uint cmd;
3269    uint cmdsize;
3270
3271    uint rebase_off;
3272    uint rebase_size;
3273
3274    uint bind_off;
3275    uint bind_size;
3276
3277    uint weak_bind_off;
3278    uint weak_bind_size;
3279
3280    uint lazy_bind_off;
3281    uint lazy_bind_size;
3282
3283    uint export_off;
3284    uint export_size;
3285}
3286
3287enum
3288{
3289    REBASE_TYPE_POINTER = 1,
3290    REBASE_TYPE_TEXT_ABSOLUTE32 = 2,
3291    REBASE_TYPE_TEXT_PCREL32 = 3,
3292
3293    REBASE_OPCODE_MASK = 0xF0,
3294    REBASE_IMMEDIATE_MASK = 0x0F,
3295    REBASE_OPCODE_DONE = 0x00,
3296    REBASE_OPCODE_SET_TYPE_IMM = 0x10,
3297    REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x20,
3298    REBASE_OPCODE_ADD_ADDR_ULEB = 0x30,
3299    REBASE_OPCODE_ADD_ADDR_IMM_SCALED = 0x40,
3300    REBASE_OPCODE_DO_REBASE_IMM_TIMES = 0x50,
3301    REBASE_OPCODE_DO_REBASE_ULEB_TIMES = 0x60,
3302    REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB = 0x70,
3303    REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80
3304}
3305
3306enum
3307{
3308    BIND_TYPE_POINTER = 1,
3309    BIND_TYPE_TEXT_ABSOLUTE32 = 2,
3310    BIND_TYPE_TEXT_PCREL32 = 3,
3311
3312    BIND_SPECIAL_DYLIB_SELF = 0,
3313    BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE = -1,
3314    BIND_SPECIAL_DYLIB_FLAT_LOOKUP = -2,
3315    BIND_SPECIAL_DYLIB_WEAK_LOOKUP = -3,
3316
3317    BIND_SYMBOL_FLAGS_WEAK_IMPORT = 0x1,
3318    BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8,
3319
3320    BIND_OPCODE_MASK = 0xF0,
3321    BIND_IMMEDIATE_MASK = 0x0F,
3322    BIND_OPCODE_DONE = 0x00,
3323    BIND_OPCODE_SET_DYLIB_ORDINAL_IMM = 0x10,
3324    BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB = 0x20,
3325    BIND_OPCODE_SET_DYLIB_SPECIAL_IMM = 0x30,
3326    BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40,
3327    BIND_OPCODE_SET_TYPE_IMM = 0x50,
3328    BIND_OPCODE_SET_ADDEND_SLEB = 0x60,
3329    BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x70,
3330    BIND_OPCODE_ADD_ADDR_ULEB = 0x80,
3331    BIND_OPCODE_DO_BIND = 0x90,
3332    BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB = 0xA0,
3333    BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0,
3334    BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0,
3335    BIND_OPCODE_THREADED = 0xD0,
3336    BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0x00,
3337    BIND_SUBOPCODE_THREADED_APPLY = 0x01
3338}
3339
3340enum
3341{
3342    EXPORT_SYMBOL_FLAGS_KIND_MASK = 0x03,
3343    EXPORT_SYMBOL_FLAGS_KIND_REGULAR = 0x00,
3344    EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL = 0x01,
3345    EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE = 0x02,
3346    EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION = 0x04,
3347    EXPORT_SYMBOL_FLAGS_REEXPORT = 0x08,
3348    EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER = 0x10
3349}
3350
3351struct linker_option_command
3352{
3353    uint cmd;
3354    uint cmdsize;
3355    uint count;
3356}
3357
3358struct symseg_command
3359{
3360    uint cmd;
3361    uint cmdsize;
3362    uint offset;
3363    uint size;
3364}
3365
3366struct ident_command
3367{
3368    uint cmd;
3369    uint cmdsize;
3370}
3371
3372struct fvmfile_command
3373{
3374    uint cmd;
3375    uint cmdsize;
3376    lc_str name;
3377    uint header_addr;
3378}
3379
3380struct entry_point_command
3381{
3382    uint cmd;
3383    uint cmdsize;
3384    ulong entryoff;
3385    ulong stacksize;
3386}
3387
3388struct source_version_command
3389{
3390    uint cmd;
3391    uint cmdsize;
3392    ulong version_;
3393}
3394
3395struct data_in_code_entry
3396{
3397    uint offset;
3398    ushort length;
3399    ushort kind;
3400}
3401
3402enum
3403{
3404    DICE_KIND_DATA = 0x0001,
3405    DICE_KIND_JUMP_TABLE8 = 0x0002,
3406    DICE_KIND_JUMP_TABLE16 = 0x0003,
3407    DICE_KIND_JUMP_TABLE32 = 0x0004,
3408    DICE_KIND_ABS_JUMP_TABLE32 = 0x0005,
3409}
3410
3411struct tlv_descriptor
3412{
3413    void* function(tlv_descriptor*) thunk;
3414    c_ulong key;
3415    c_ulong offset;
3416}
3417
3418struct note_command
3419{
3420    uint cmd;
3421    uint cmdsize;
3422    char[16] data_owner = 0;
3423    ulong offset;
3424    ulong size;
3425}
3426