1*4d9fdb46SRobert Mustacchi /*  This is a cut-down version of loader.h from cctools-895,
2*4d9fdb46SRobert Mustacchi     shrunk to eliminate aspects unwanted in libdwarf and to avoid
3*4d9fdb46SRobert Mustacchi     #include entirely.  All tab characters replaced with 4 spaces
4*4d9fdb46SRobert Mustacchi     so various things no line up as they used to.
5*4d9fdb46SRobert Mustacchi     cctools-895  in its original form
6*4d9fdb46SRobert Mustacchi     is available from https://opensource.apple.com/
7*4d9fdb46SRobert Mustacchi     see Developer Tools version 8.2.1. cctools-895/include/loader.h */
8*4d9fdb46SRobert Mustacchi /*
9*4d9fdb46SRobert Mustacchi * Copyright (c) 1999-2010 Apple Inc.  All Rights Reserved.
10*4d9fdb46SRobert Mustacchi *
11*4d9fdb46SRobert Mustacchi * @APPLE_LICENSE_HEADER_START@
12*4d9fdb46SRobert Mustacchi *
13*4d9fdb46SRobert Mustacchi * This file contains Original Code and/or Modifications of Original Code
14*4d9fdb46SRobert Mustacchi * as defined in and that are subject to the Apple Public Source License
15*4d9fdb46SRobert Mustacchi * Version 2.0 (the 'License'). You may not use this file except in
16*4d9fdb46SRobert Mustacchi * compliance with the License. Please obtain a copy of the License at
17*4d9fdb46SRobert Mustacchi * http://www.opensource.apple.com/apsl/ and read it before using this
18*4d9fdb46SRobert Mustacchi * file.
19*4d9fdb46SRobert Mustacchi *
20*4d9fdb46SRobert Mustacchi * The Original Code and all software distributed under the License are
21*4d9fdb46SRobert Mustacchi * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
25*4d9fdb46SRobert Mustacchi * Please see the License for the specific language governing rights and
26*4d9fdb46SRobert Mustacchi * limitations under the License.
27*4d9fdb46SRobert Mustacchi *
28*4d9fdb46SRobert Mustacchi * @APPLE_LICENSE_HEADER_END@
29*4d9fdb46SRobert Mustacchi */
30*4d9fdb46SRobert Mustacchi #ifndef MACHO_LOADER_H
31*4d9fdb46SRobert Mustacchi #define MACHO_LOADER_H
32*4d9fdb46SRobert Mustacchi 
33*4d9fdb46SRobert Mustacchi #ifdef __cplusplus
34*4d9fdb46SRobert Mustacchi extern "C" {
35*4d9fdb46SRobert Mustacchi #endif /* __cplusplus */
36*4d9fdb46SRobert Mustacchi 
37*4d9fdb46SRobert Mustacchi 
38*4d9fdb46SRobert Mustacchi #if 0 /* Not used here. DavidA. September 2018 */
39*4d9fdb46SRobert Mustacchi /*
40*4d9fdb46SRobert Mustacchi * This file describes the format of mach object files.
41*4d9fdb46SRobert Mustacchi */
42*4d9fdb46SRobert Mustacchi #include <stdint.h>
43*4d9fdb46SRobert Mustacchi 
44*4d9fdb46SRobert Mustacchi /*
45*4d9fdb46SRobert Mustacchi * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types
46*4d9fdb46SRobert Mustacchi * and contains the constants for the possible values of these types.
47*4d9fdb46SRobert Mustacchi */
48*4d9fdb46SRobert Mustacchi #include <mach/machine.h>
49*4d9fdb46SRobert Mustacchi 
50*4d9fdb46SRobert Mustacchi /*
51*4d9fdb46SRobert Mustacchi * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the
52*4d9fdb46SRobert Mustacchi * constants that are or'ed together for the possible values of this type.
53*4d9fdb46SRobert Mustacchi */
54*4d9fdb46SRobert Mustacchi #include <mach/vm_prot.h>
55*4d9fdb46SRobert Mustacchi 
56*4d9fdb46SRobert Mustacchi /*
57*4d9fdb46SRobert Mustacchi * <machine/thread_status.h> is expected to define the flavors of the thread
58*4d9fdb46SRobert Mustacchi * states and the structures of those flavors for each machine.
59*4d9fdb46SRobert Mustacchi */
60*4d9fdb46SRobert Mustacchi #include <mach/machine/thread_status.h>
61*4d9fdb46SRobert Mustacchi #include <architecture/byte_order.h>
62*4d9fdb46SRobert Mustacchi #endif /* 0 */
63*4d9fdb46SRobert Mustacchi 
64*4d9fdb46SRobert Mustacchi #ifndef TYP
65*4d9fdb46SRobert Mustacchi #define TYP(n,l) char n[l]
66*4d9fdb46SRobert Mustacchi #endif /* TYP */
67*4d9fdb46SRobert Mustacchi 
68*4d9fdb46SRobert Mustacchi /*
69*4d9fdb46SRobert Mustacchi * The 32-bit mach header appears at the very beginning of the object file for
70*4d9fdb46SRobert Mustacchi * 32-bit architectures.
71*4d9fdb46SRobert Mustacchi */
72*4d9fdb46SRobert Mustacchi struct mach_header {
73*4d9fdb46SRobert Mustacchi     TYP(magic,4); /* mach magic number identifier */
74*4d9fdb46SRobert Mustacchi     TYP(cputype,4); /* cpu specifier */
75*4d9fdb46SRobert Mustacchi     TYP(cpusubtype,4); /* machine specifier */
76*4d9fdb46SRobert Mustacchi     TYP(filetype,4); /* type of file */
77*4d9fdb46SRobert Mustacchi     TYP(ncmds,4); /* number of load commands */
78*4d9fdb46SRobert Mustacchi     TYP(sizeofcmds,4); /* the size of all the load commands */
79*4d9fdb46SRobert Mustacchi     TYP(flags,4); /* flags */
80*4d9fdb46SRobert Mustacchi };
81*4d9fdb46SRobert Mustacchi 
82*4d9fdb46SRobert Mustacchi /*  Constant for the magic field of the
83*4d9fdb46SRobert Mustacchi     mach_header (32-bit architectures)
84*4d9fdb46SRobert Mustacchi     MH_MAGIC MH_MAGIC_64 appear in big-endian objects
85*4d9fdb46SRobert Mustacchi     MH_CIGAM MH_CIGAM_64 appear in little-endian objects */
86*4d9fdb46SRobert Mustacchi #define    MH_MAGIC    0xfeedface    /* the mach magic number */
87*4d9fdb46SRobert Mustacchi #define MH_CIGAM    0xcefaedfe    /* NXSwapInt(MH_MAGIC) */
88*4d9fdb46SRobert Mustacchi 
89*4d9fdb46SRobert Mustacchi /*
90*4d9fdb46SRobert Mustacchi * The 64-bit mach header appears at the very beginning of object files for
91*4d9fdb46SRobert Mustacchi * 64-bit architectures.
92*4d9fdb46SRobert Mustacchi */
93*4d9fdb46SRobert Mustacchi struct mach_header_64 {
94*4d9fdb46SRobert Mustacchi     TYP(magic,4); /* mach magic number identifier */
95*4d9fdb46SRobert Mustacchi     TYP(cputype,4); /* cpu specifier */
96*4d9fdb46SRobert Mustacchi     TYP(cpusubtype,4); /* machine specifier */
97*4d9fdb46SRobert Mustacchi     TYP(filetype,4); /* type of file */
98*4d9fdb46SRobert Mustacchi     TYP(ncmds,4); /* number of load commands */
99*4d9fdb46SRobert Mustacchi     TYP(sizeofcmds,4); /* the size of all the load commands */
100*4d9fdb46SRobert Mustacchi     TYP(flags,4); /* flags */
101*4d9fdb46SRobert Mustacchi     TYP(reserved,4); /* reserved */
102*4d9fdb46SRobert Mustacchi };
103*4d9fdb46SRobert Mustacchi 
104*4d9fdb46SRobert Mustacchi /* Constant for the magic field of the mach_header_64 (64-bit architectures) */
105*4d9fdb46SRobert Mustacchi #define MH_MAGIC_64 0xfeedfacf /* the 64-bit mach magic number */
106*4d9fdb46SRobert Mustacchi #define MH_CIGAM_64 0xcffaedfe /* NXSwapInt(MH_MAGIC_64) */
107*4d9fdb46SRobert Mustacchi 
108*4d9fdb46SRobert Mustacchi /*
109*4d9fdb46SRobert Mustacchi * The layout of the file depends on the filetype.  For all but the MH_OBJECT
110*4d9fdb46SRobert Mustacchi * file type the segments are padded out and aligned on a segment alignment
111*4d9fdb46SRobert Mustacchi * boundary for efficient demand pageing.  The MH_EXECUTE, MH_FVMLIB, MH_DYLIB,
112*4d9fdb46SRobert Mustacchi * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part
113*4d9fdb46SRobert Mustacchi * of their first segment.
114*4d9fdb46SRobert Mustacchi *
115*4d9fdb46SRobert Mustacchi * The file type MH_OBJECT is a compact format intended as output of the
116*4d9fdb46SRobert Mustacchi * assembler and input (and possibly output) of the link editor (the .o
117*4d9fdb46SRobert Mustacchi * format).  All sections are in one unnamed segment with no segment padding.
118*4d9fdb46SRobert Mustacchi * This format is used as an executable format when the file is so small the
119*4d9fdb46SRobert Mustacchi * segment padding greatly increases its size.
120*4d9fdb46SRobert Mustacchi *
121*4d9fdb46SRobert Mustacchi * The file type MH_PRELOAD is an executable format intended for things that
122*4d9fdb46SRobert Mustacchi * are not executed under the kernel (proms, stand alones, kernels, etc).  The
123*4d9fdb46SRobert Mustacchi * format can be executed under the kernel but may demand paged it and not
124*4d9fdb46SRobert Mustacchi * preload it before execution.
125*4d9fdb46SRobert Mustacchi *
126*4d9fdb46SRobert Mustacchi * A core file is in MH_CORE format and can be any in an arbritray legal
127*4d9fdb46SRobert Mustacchi * Mach-O file.
128*4d9fdb46SRobert Mustacchi *
129*4d9fdb46SRobert Mustacchi * Constants for the filetype field of the mach_header
130*4d9fdb46SRobert Mustacchi */
131*4d9fdb46SRobert Mustacchi #define    MH_OBJECT    0x1        /* relocatable object file */
132*4d9fdb46SRobert Mustacchi #define    MH_EXECUTE    0x2        /* demand paged executable file */
133*4d9fdb46SRobert Mustacchi #define    MH_FVMLIB    0x3        /* fixed VM shared library file */
134*4d9fdb46SRobert Mustacchi #define    MH_CORE        0x4        /* core file */
135*4d9fdb46SRobert Mustacchi #define    MH_PRELOAD    0x5        /* preloaded executable file */
136*4d9fdb46SRobert Mustacchi #define    MH_DYLIB    0x6        /* dynamically bound shared library */
137*4d9fdb46SRobert Mustacchi #define    MH_DYLINKER    0x7        /* dynamic link editor */
138*4d9fdb46SRobert Mustacchi #define    MH_BUNDLE    0x8        /* dynamically bound bundle file */
139*4d9fdb46SRobert Mustacchi #define    MH_DYLIB_STUB    0x9        /* shared library stub for static */
140*4d9fdb46SRobert Mustacchi     /*  linking only, no section contents */
141*4d9fdb46SRobert Mustacchi #define    MH_DSYM        0xa        /* companion file with only debug */
142*4d9fdb46SRobert Mustacchi     /*  sections */
143*4d9fdb46SRobert Mustacchi #define    MH_KEXT_BUNDLE    0xb        /* x86_64 kexts */
144*4d9fdb46SRobert Mustacchi 
145*4d9fdb46SRobert Mustacchi /* Constants for the flags field of the mach_header */
146*4d9fdb46SRobert Mustacchi #define    MH_NOUNDEFS    0x1        /* the object file has no undefined
147*4d9fdb46SRobert Mustacchi     references */
148*4d9fdb46SRobert Mustacchi #define    MH_INCRLINK    0x2        /* the object file is the output of an
149*4d9fdb46SRobert Mustacchi     incremental link against a base file
150*4d9fdb46SRobert Mustacchi     and can't be link edited again */
151*4d9fdb46SRobert Mustacchi #define MH_DYLDLINK    0x4        /* the object file is input for the
152*4d9fdb46SRobert Mustacchi     dynamic linker and can't be staticly
153*4d9fdb46SRobert Mustacchi     link edited again */
154*4d9fdb46SRobert Mustacchi #define MH_BINDATLOAD    0x8        /* the object file's undefined
155*4d9fdb46SRobert Mustacchi     references are bound by the dynamic
156*4d9fdb46SRobert Mustacchi     linker when loaded. */
157*4d9fdb46SRobert Mustacchi #define MH_PREBOUND    0x10        /* the file has its dynamic undefined
158*4d9fdb46SRobert Mustacchi     references prebound. */
159*4d9fdb46SRobert Mustacchi #define MH_SPLIT_SEGS    0x20        /* the file has its read-only and
160*4d9fdb46SRobert Mustacchi     read-write segments split */
161*4d9fdb46SRobert Mustacchi #define MH_LAZY_INIT    0x40        /* the shared library init routine is
162*4d9fdb46SRobert Mustacchi     to be run lazily via catching memory
163*4d9fdb46SRobert Mustacchi     faults to its writeable segments
164*4d9fdb46SRobert Mustacchi     (obsolete) */
165*4d9fdb46SRobert Mustacchi #define MH_TWOLEVEL    0x80        /* the image is using two-level name
166*4d9fdb46SRobert Mustacchi     space bindings */
167*4d9fdb46SRobert Mustacchi #define MH_FORCE_FLAT    0x100        /* the executable is forcing all images
168*4d9fdb46SRobert Mustacchi     to use flat name space bindings */
169*4d9fdb46SRobert Mustacchi #define MH_NOMULTIDEFS    0x200        /* this umbrella guarantees no multiple
170*4d9fdb46SRobert Mustacchi     defintions of symbols in its
171*4d9fdb46SRobert Mustacchi     sub-images so the two-level namespace
172*4d9fdb46SRobert Mustacchi     hints can always be used. */
173*4d9fdb46SRobert Mustacchi #define MH_NOFIXPREBINDING 0x400    /* do not have dyld notify the
174*4d9fdb46SRobert Mustacchi     prebinding agent about this
175*4d9fdb46SRobert Mustacchi     executable */
176*4d9fdb46SRobert Mustacchi #define MH_PREBINDABLE  0x800           /* the binary is not prebound but can
177*4d9fdb46SRobert Mustacchi     have its prebinding redone. only used
178*4d9fdb46SRobert Mustacchi     when MH_PREBOUND is not set. */
179*4d9fdb46SRobert Mustacchi #define MH_ALLMODSBOUND 0x1000        /* indicates that this binary binds to
180*4d9fdb46SRobert Mustacchi     all two-level namespace modules of
181*4d9fdb46SRobert Mustacchi     its dependent libraries. only used
182*4d9fdb46SRobert Mustacchi     when MH_PREBINDABLE and MH_TWOLEVEL
183*4d9fdb46SRobert Mustacchi     are both set. */
184*4d9fdb46SRobert Mustacchi #define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into
185*4d9fdb46SRobert Mustacchi     sub-sections via symbols for dead
186*4d9fdb46SRobert Mustacchi     code stripping */
187*4d9fdb46SRobert Mustacchi #define MH_CANONICAL    0x4000        /* the binary has been canonicalized
188*4d9fdb46SRobert Mustacchi     via the unprebind operation */
189*4d9fdb46SRobert Mustacchi #define MH_WEAK_DEFINES    0x8000        /* the final linked image contains
190*4d9fdb46SRobert Mustacchi     external weak symbols */
191*4d9fdb46SRobert Mustacchi #define MH_BINDS_TO_WEAK 0x10000    /* the final linked image uses
192*4d9fdb46SRobert Mustacchi     weak symbols */
193*4d9fdb46SRobert Mustacchi 
194*4d9fdb46SRobert Mustacchi #define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks
195*4d9fdb46SRobert Mustacchi     in the task will be given stack
196*4d9fdb46SRobert Mustacchi     execution privilege.  Only used in
197*4d9fdb46SRobert Mustacchi     MH_EXECUTE filetypes. */
198*4d9fdb46SRobert Mustacchi #define MH_ROOT_SAFE 0x40000           /* When this bit is set, the binary
199*4d9fdb46SRobert Mustacchi     declares it is safe for use in
200*4d9fdb46SRobert Mustacchi     processes with uid zero */
201*4d9fdb46SRobert Mustacchi 
202*4d9fdb46SRobert Mustacchi #define MH_SETUID_SAFE 0x80000         /* When this bit is set, the binary
203*4d9fdb46SRobert Mustacchi     declares it is safe for use in
204*4d9fdb46SRobert Mustacchi     processes when issetugid() is true */
205*4d9fdb46SRobert Mustacchi 
206*4d9fdb46SRobert Mustacchi #define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib,
207*4d9fdb46SRobert Mustacchi     the static linker does not need to
208*4d9fdb46SRobert Mustacchi     examine dependent dylibs to see
209*4d9fdb46SRobert Mustacchi     if any are re-exported */
210*4d9fdb46SRobert Mustacchi #define    MH_PIE 0x200000            /* When this bit is set, the OS will
211*4d9fdb46SRobert Mustacchi     load the main executable at a
212*4d9fdb46SRobert Mustacchi     random address.  Only used in
213*4d9fdb46SRobert Mustacchi     MH_EXECUTE filetypes. */
214*4d9fdb46SRobert Mustacchi #define    MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs.  When
215*4d9fdb46SRobert Mustacchi     linking against a dylib that
216*4d9fdb46SRobert Mustacchi     has this bit set, the static linker
217*4d9fdb46SRobert Mustacchi     will automatically not create a
218*4d9fdb46SRobert Mustacchi     LC_LOAD_DYLIB load command to the
219*4d9fdb46SRobert Mustacchi     dylib if no symbols are being
220*4d9fdb46SRobert Mustacchi     referenced from the dylib. */
221*4d9fdb46SRobert Mustacchi #define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type
222*4d9fdb46SRobert Mustacchi     S_THREAD_LOCAL_VARIABLES */
223*4d9fdb46SRobert Mustacchi 
224*4d9fdb46SRobert Mustacchi #define MH_NO_HEAP_EXECUTION 0x1000000    /* When this bit is set, the OS will
225*4d9fdb46SRobert Mustacchi     run the main executable with
226*4d9fdb46SRobert Mustacchi     a non-executable heap even on
227*4d9fdb46SRobert Mustacchi     platforms (e.g. i386) that don't
228*4d9fdb46SRobert Mustacchi     require it. Only used in MH_EXECUTE
229*4d9fdb46SRobert Mustacchi     filetypes. */
230*4d9fdb46SRobert Mustacchi 
231*4d9fdb46SRobert Mustacchi #define MH_APP_EXTENSION_SAFE 0x02000000 /* The code was linked for use in an
232*4d9fdb46SRobert Mustacchi     application extension. */
233*4d9fdb46SRobert Mustacchi 
234*4d9fdb46SRobert Mustacchi /*
235*4d9fdb46SRobert Mustacchi * The load commands directly follow the mach_header.  The total size of all
236*4d9fdb46SRobert Mustacchi * of the commands is given by the sizeofcmds field in the mach_header.  All
237*4d9fdb46SRobert Mustacchi * load commands must have as their first two fields cmd and cmdsize.  The cmd
238*4d9fdb46SRobert Mustacchi * field is filled in with a constant for that command type.  Each command type
239*4d9fdb46SRobert Mustacchi * has a structure specifically for it.  The cmdsize field is the size in bytes
240*4d9fdb46SRobert Mustacchi * of the particular load command structure plus anything that follows it that
241*4d9fdb46SRobert Mustacchi * is a part of the load command (i.e. section structures, strings, etc.).  To
242*4d9fdb46SRobert Mustacchi * advance to the next load command the cmdsize can be added to the offset or
243*4d9fdb46SRobert Mustacchi * pointer of the current load command.  The cmdsize for 32-bit architectures
244*4d9fdb46SRobert Mustacchi * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple
245*4d9fdb46SRobert Mustacchi * of 8 bytes (these are forever the maximum alignment of any load commands).
246*4d9fdb46SRobert Mustacchi * The padded bytes must be zero.  All tables in the object file must also
247*4d9fdb46SRobert Mustacchi * follow these rules so the file can be memory mapped.  Otherwise the pointers
248*4d9fdb46SRobert Mustacchi * to these tables will not work well or at all on some machines.  With all
249*4d9fdb46SRobert Mustacchi * padding zeroed like objects will compare byte for byte.
250*4d9fdb46SRobert Mustacchi */
251*4d9fdb46SRobert Mustacchi struct load_command {
252*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* type of load command */
253*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* total size of command in bytes */
254*4d9fdb46SRobert Mustacchi };
255*4d9fdb46SRobert Mustacchi 
256*4d9fdb46SRobert Mustacchi /*
257*4d9fdb46SRobert Mustacchi * After MacOS X 10.1 when a new load command is added that is required to be
258*4d9fdb46SRobert Mustacchi * understood by the dynamic linker for the image to execute properly the
259*4d9fdb46SRobert Mustacchi * LC_REQ_DYLD bit will be or'ed into the load command constant.  If the dynamic
260*4d9fdb46SRobert Mustacchi * linker sees such a load command it it does not understand will issue a
261*4d9fdb46SRobert Mustacchi * "unknown load command required for execution" error and refuse to use the
262*4d9fdb46SRobert Mustacchi * image.  Other load commands without this bit that are not understood will
263*4d9fdb46SRobert Mustacchi * simply be ignored.
264*4d9fdb46SRobert Mustacchi */
265*4d9fdb46SRobert Mustacchi #define LC_REQ_DYLD 0x80000000
266*4d9fdb46SRobert Mustacchi 
267*4d9fdb46SRobert Mustacchi /* Constants for the cmd field of all load commands, the type */
268*4d9fdb46SRobert Mustacchi #define    LC_SEGMENT    0x1    /* segment of this file to be mapped */
269*4d9fdb46SRobert Mustacchi #define    LC_SYMTAB    0x2    /* link-edit stab symbol table info */
270*4d9fdb46SRobert Mustacchi #define    LC_SYMSEG    0x3    /* link-edit gdb symbol table info (obsolete) */
271*4d9fdb46SRobert Mustacchi #define    LC_THREAD    0x4    /* thread */
272*4d9fdb46SRobert Mustacchi #define    LC_UNIXTHREAD    0x5    /* unix thread (includes a stack) */
273*4d9fdb46SRobert Mustacchi #define    LC_LOADFVMLIB    0x6    /* load a specified fixed VM shared library */
274*4d9fdb46SRobert Mustacchi #define    LC_IDFVMLIB    0x7    /* fixed VM shared library identification */
275*4d9fdb46SRobert Mustacchi #define    LC_IDENT    0x8    /* object identification info (obsolete) */
276*4d9fdb46SRobert Mustacchi #define LC_FVMFILE    0x9    /* fixed VM file inclusion (internal use) */
277*4d9fdb46SRobert Mustacchi #define LC_PREPAGE      0xa     /* prepage command (internal use) */
278*4d9fdb46SRobert Mustacchi #define    LC_DYSYMTAB    0xb    /* dynamic link-edit symbol table info */
279*4d9fdb46SRobert Mustacchi #define    LC_LOAD_DYLIB    0xc    /* load a dynamically linked shared library */
280*4d9fdb46SRobert Mustacchi #define    LC_ID_DYLIB    0xd    /* dynamically linked shared lib ident */
281*4d9fdb46SRobert Mustacchi #define LC_LOAD_DYLINKER 0xe    /* load a dynamic linker */
282*4d9fdb46SRobert Mustacchi #define LC_ID_DYLINKER    0xf    /* dynamic linker identification */
283*4d9fdb46SRobert Mustacchi #define    LC_PREBOUND_DYLIB 0x10    /* modules prebound for a dynamically */
284*4d9fdb46SRobert Mustacchi     /*  linked shared library */
285*4d9fdb46SRobert Mustacchi #define    LC_ROUTINES    0x11    /* image routines */
286*4d9fdb46SRobert Mustacchi #define    LC_SUB_FRAMEWORK 0x12    /* sub framework */
287*4d9fdb46SRobert Mustacchi #define    LC_SUB_UMBRELLA 0x13    /* sub umbrella */
288*4d9fdb46SRobert Mustacchi #define    LC_SUB_CLIENT    0x14    /* sub client */
289*4d9fdb46SRobert Mustacchi #define    LC_SUB_LIBRARY  0x15    /* sub library */
290*4d9fdb46SRobert Mustacchi #define    LC_TWOLEVEL_HINTS 0x16    /* two-level namespace lookup hints */
291*4d9fdb46SRobert Mustacchi #define    LC_PREBIND_CKSUM  0x17    /* prebind checksum */
292*4d9fdb46SRobert Mustacchi 
293*4d9fdb46SRobert Mustacchi /*
294*4d9fdb46SRobert Mustacchi * load a dynamically linked shared library that is allowed to be missing
295*4d9fdb46SRobert Mustacchi * (all symbols are weak imported).
296*4d9fdb46SRobert Mustacchi */
297*4d9fdb46SRobert Mustacchi #define    LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
298*4d9fdb46SRobert Mustacchi 
299*4d9fdb46SRobert Mustacchi #define    LC_SEGMENT_64    0x19    /* 64-bit segment of this file to be
300*4d9fdb46SRobert Mustacchi     mapped */
301*4d9fdb46SRobert Mustacchi #define    LC_ROUTINES_64    0x1a    /* 64-bit image routines */
302*4d9fdb46SRobert Mustacchi #define LC_UUID        0x1b    /* the uuid */
303*4d9fdb46SRobert Mustacchi #define LC_RPATH       (0x1c | LC_REQ_DYLD)    /* runpath additions */
304*4d9fdb46SRobert Mustacchi #define LC_CODE_SIGNATURE 0x1d    /* local of code signature */
305*4d9fdb46SRobert Mustacchi #define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */
306*4d9fdb46SRobert Mustacchi #define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */
307*4d9fdb46SRobert Mustacchi #define    LC_LAZY_LOAD_DYLIB 0x20    /* delay load of dylib until first use */
308*4d9fdb46SRobert Mustacchi #define    LC_ENCRYPTION_INFO 0x21    /* encrypted segment information */
309*4d9fdb46SRobert Mustacchi #define    LC_DYLD_INFO     0x22    /* compressed dyld information */
310*4d9fdb46SRobert Mustacchi #define    LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD)    /* compressed dyld information only */
311*4d9fdb46SRobert Mustacchi #define    LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */
312*4d9fdb46SRobert Mustacchi #define LC_VERSION_MIN_MACOSX 0x24   /* build for MacOSX min OS version */
313*4d9fdb46SRobert Mustacchi #define LC_VERSION_MIN_IPHONEOS 0x25 /* build for iPhoneOS min OS version */
314*4d9fdb46SRobert Mustacchi #define LC_FUNCTION_STARTS 0x26 /* compressed table of function start addresses */
315*4d9fdb46SRobert Mustacchi #define LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat
316*4d9fdb46SRobert Mustacchi                     like environment variable */
317*4d9fdb46SRobert Mustacchi #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
318*4d9fdb46SRobert Mustacchi #define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
319*4d9fdb46SRobert Mustacchi #define LC_SOURCE_VERSION 0x2A /* source version used to build binary */
320*4d9fdb46SRobert Mustacchi #define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */
321*4d9fdb46SRobert Mustacchi #define    LC_ENCRYPTION_INFO_64 0x2C /* 64-bit encrypted segment information */
322*4d9fdb46SRobert Mustacchi #define LC_LINKER_OPTION 0x2D /* linker options in MH_OBJECT files */
323*4d9fdb46SRobert Mustacchi #define LC_LINKER_OPTIMIZATION_HINT 0x2E /* optimization hints in MH_OBJECT files */
324*4d9fdb46SRobert Mustacchi #define LC_VERSION_MIN_TVOS 0x2F /* build for AppleTV min OS version */
325*4d9fdb46SRobert Mustacchi #define LC_VERSION_MIN_WATCHOS 0x30 /* build for Watch min OS version */
326*4d9fdb46SRobert Mustacchi 
327*4d9fdb46SRobert Mustacchi /*
328*4d9fdb46SRobert Mustacchi * A variable length string in a load command is represented by an lc_str
329*4d9fdb46SRobert Mustacchi * union.  The strings are stored just after the load command structure and
330*4d9fdb46SRobert Mustacchi * the offset is from the start of the load command structure.  The size
331*4d9fdb46SRobert Mustacchi * of the string is reflected in the cmdsize field of the load command.
332*4d9fdb46SRobert Mustacchi * Once again any padded bytes to bring the cmdsize field to a multiple
333*4d9fdb46SRobert Mustacchi * of 4 bytes must be zero.
334*4d9fdb46SRobert Mustacchi */
335*4d9fdb46SRobert Mustacchi union lc_str {
336*4d9fdb46SRobert Mustacchi     TYP(offset,4); /* offset to the string */
337*4d9fdb46SRobert Mustacchi #ifndef __LP64__
338*4d9fdb46SRobert Mustacchi     char        *ptr;    /* pointer to the string */
339*4d9fdb46SRobert Mustacchi #endif
340*4d9fdb46SRobert Mustacchi };
341*4d9fdb46SRobert Mustacchi 
342*4d9fdb46SRobert Mustacchi /*
343*4d9fdb46SRobert Mustacchi * The segment load command indicates that a part of this file is to be
344*4d9fdb46SRobert Mustacchi * mapped into the task's address space.  The size of this segment in memory,
345*4d9fdb46SRobert Mustacchi * vmsize, maybe equal to or larger than the amount to map from this file,
346*4d9fdb46SRobert Mustacchi * filesize.  The file is mapped starting at fileoff to the beginning of
347*4d9fdb46SRobert Mustacchi * the segment in memory, vmaddr.  The rest of the memory of the segment,
348*4d9fdb46SRobert Mustacchi * if any, is allocated zero fill on demand.  The segment's maximum virtual
349*4d9fdb46SRobert Mustacchi * memory protection and initial virtual memory protection are specified
350*4d9fdb46SRobert Mustacchi * by the maxprot and initprot fields.  If the segment has sections then the
351*4d9fdb46SRobert Mustacchi * section structures directly follow the segment command and their size is
352*4d9fdb46SRobert Mustacchi * reflected in cmdsize.
353*4d9fdb46SRobert Mustacchi */
354*4d9fdb46SRobert Mustacchi struct segment_command { /* for 32-bit architectures */
355*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SEGMENT */
356*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes sizeof section structs */
357*4d9fdb46SRobert Mustacchi     char        segname[16];    /* segment name */
358*4d9fdb46SRobert Mustacchi     TYP(vmaddr,4); /* memory address of this segment */
359*4d9fdb46SRobert Mustacchi     TYP(vmsize,4); /* memory size of this segment */
360*4d9fdb46SRobert Mustacchi     TYP(fileoff,4); /* file offset of this segment */
361*4d9fdb46SRobert Mustacchi     TYP(filesize,4); /* amount to map from the file */
362*4d9fdb46SRobert Mustacchi     TYP(maxprot,4); /* maximum VM protection */
363*4d9fdb46SRobert Mustacchi     TYP(initprot,4); /* initial VM protection */
364*4d9fdb46SRobert Mustacchi     TYP(nsects,4); /* number of sections in segment */
365*4d9fdb46SRobert Mustacchi     TYP(flags,4); /* flags */
366*4d9fdb46SRobert Mustacchi };
367*4d9fdb46SRobert Mustacchi 
368*4d9fdb46SRobert Mustacchi /*
369*4d9fdb46SRobert Mustacchi * The 64-bit segment load command indicates that a part of this file is to be
370*4d9fdb46SRobert Mustacchi * mapped into a 64-bit task's address space.  If the 64-bit segment has
371*4d9fdb46SRobert Mustacchi * sections then section_64 structures directly follow the 64-bit segment
372*4d9fdb46SRobert Mustacchi * command and their size is reflected in cmdsize.
373*4d9fdb46SRobert Mustacchi */
374*4d9fdb46SRobert Mustacchi struct segment_command_64 { /* for 64-bit architectures */
375*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SEGMENT_64 */
376*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes sizeof section_64 structs */
377*4d9fdb46SRobert Mustacchi     char        segname[16];    /* segment name */
378*4d9fdb46SRobert Mustacchi     TYP(vmaddr,8); /* memory address of this segment */
379*4d9fdb46SRobert Mustacchi     TYP(vmsize,8); /* memory size of this segment */
380*4d9fdb46SRobert Mustacchi     TYP(fileoff,8); /* file offset of this segment */
381*4d9fdb46SRobert Mustacchi     TYP(filesize,8); /* amount to map from the file */
382*4d9fdb46SRobert Mustacchi     TYP(maxprot,4); /* maximum VM protection */
383*4d9fdb46SRobert Mustacchi     TYP(initprot,4); /* initial VM protection */
384*4d9fdb46SRobert Mustacchi     TYP(nsects,4); /* number of sections in segment */
385*4d9fdb46SRobert Mustacchi     TYP(flags,4); /* flags */
386*4d9fdb46SRobert Mustacchi };
387*4d9fdb46SRobert Mustacchi 
388*4d9fdb46SRobert Mustacchi /* Constants for the flags field of the segment_command */
389*4d9fdb46SRobert Mustacchi #define    SG_HIGHVM    0x1    /* the file contents for this segment is for
390*4d9fdb46SRobert Mustacchi     the high part of the VM space, the low part
391*4d9fdb46SRobert Mustacchi     is zero filled (for stacks in core files) */
392*4d9fdb46SRobert Mustacchi #define    SG_FVMLIB    0x2    /* this segment is the VM that is allocated by
393*4d9fdb46SRobert Mustacchi     a fixed VM library, for overlap checking in
394*4d9fdb46SRobert Mustacchi     the link editor */
395*4d9fdb46SRobert Mustacchi #define    SG_NORELOC    0x4    /* this segment has nothing that was relocated
396*4d9fdb46SRobert Mustacchi     in it and nothing relocated to it, that is
397*4d9fdb46SRobert Mustacchi     it maybe safely replaced without relocation*/
398*4d9fdb46SRobert Mustacchi #define SG_PROTECTED_VERSION_1    0x8 /* This segment is protected.  If the
399*4d9fdb46SRobert Mustacchi     segment starts at file offset 0, the
400*4d9fdb46SRobert Mustacchi     first page of the segment is not
401*4d9fdb46SRobert Mustacchi     protected.  All other pages of the
402*4d9fdb46SRobert Mustacchi     segment are protected. */
403*4d9fdb46SRobert Mustacchi 
404*4d9fdb46SRobert Mustacchi /*
405*4d9fdb46SRobert Mustacchi * A segment is made up of zero or more sections.  Non-MH_OBJECT files have
406*4d9fdb46SRobert Mustacchi * all of their segments with the proper sections in each, and padded to the
407*4d9fdb46SRobert Mustacchi * specified segment alignment when produced by the link editor.  The first
408*4d9fdb46SRobert Mustacchi * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header
409*4d9fdb46SRobert Mustacchi * and load commands of the object file before its first section.  The zero
410*4d9fdb46SRobert Mustacchi * fill sections are always last in their segment (in all formats).  This
411*4d9fdb46SRobert Mustacchi * allows the zeroed segment padding to be mapped into memory where zero fill
412*4d9fdb46SRobert Mustacchi * sections might be. The gigabyte zero fill sections, those with the section
413*4d9fdb46SRobert Mustacchi * type S_GB_ZEROFILL, can only be in a segment with sections of this type.
414*4d9fdb46SRobert Mustacchi * These segments are then placed after all other segments.
415*4d9fdb46SRobert Mustacchi *
416*4d9fdb46SRobert Mustacchi * The MH_OBJECT format has all of its sections in one segment for
417*4d9fdb46SRobert Mustacchi * compactness.  There is no padding to a specified segment boundary and the
418*4d9fdb46SRobert Mustacchi * mach_header and load commands are not part of the segment.
419*4d9fdb46SRobert Mustacchi *
420*4d9fdb46SRobert Mustacchi * Sections with the same section name, sectname, going into the same segment,
421*4d9fdb46SRobert Mustacchi * segname, are combined by the link editor.  The resulting section is aligned
422*4d9fdb46SRobert Mustacchi * to the maximum alignment of the combined sections and is the new section's
423*4d9fdb46SRobert Mustacchi * alignment.  The combined sections are aligned to their original alignment in
424*4d9fdb46SRobert Mustacchi * the combined section.  Any padded bytes to get the specified alignment are
425*4d9fdb46SRobert Mustacchi * zeroed.
426*4d9fdb46SRobert Mustacchi *
427*4d9fdb46SRobert Mustacchi * The format of the relocation entries referenced by the reloff and nreloc
428*4d9fdb46SRobert Mustacchi * fields of the section structure for mach object files is described in the
429*4d9fdb46SRobert Mustacchi * header file <reloc.h>.
430*4d9fdb46SRobert Mustacchi */
431*4d9fdb46SRobert Mustacchi struct section { /* for 32-bit architectures */
432*4d9fdb46SRobert Mustacchi     char        sectname[16];    /* name of this section */
433*4d9fdb46SRobert Mustacchi     char        segname[16];    /* segment this section goes in */
434*4d9fdb46SRobert Mustacchi     TYP(addr,4); /* memory address of this section */
435*4d9fdb46SRobert Mustacchi     TYP(size,4); /* size in bytes of this section */
436*4d9fdb46SRobert Mustacchi     TYP(offset,4); /* file offset of this section */
437*4d9fdb46SRobert Mustacchi     TYP(align,4); /* section alignment (power of 2) */
438*4d9fdb46SRobert Mustacchi     TYP(reloff,4); /* file offset of relocation entries */
439*4d9fdb46SRobert Mustacchi     TYP(nreloc,4); /* number of relocation entries */
440*4d9fdb46SRobert Mustacchi     TYP(flags,4); /* flags (section type and attributes)*/
441*4d9fdb46SRobert Mustacchi     TYP(reserved1,4); /* reserved (for offset or index) */
442*4d9fdb46SRobert Mustacchi     TYP(reserved2,4); /* reserved (for count or sizeof) */
443*4d9fdb46SRobert Mustacchi };
444*4d9fdb46SRobert Mustacchi 
445*4d9fdb46SRobert Mustacchi struct section_64 { /* for 64-bit architectures */
446*4d9fdb46SRobert Mustacchi     char        sectname[16];    /* name of this section */
447*4d9fdb46SRobert Mustacchi     char        segname[16];    /* segment this section goes in */
448*4d9fdb46SRobert Mustacchi     TYP(addr,8); /* memory address of this section */
449*4d9fdb46SRobert Mustacchi     TYP(size,8); /* size in bytes of this section */
450*4d9fdb46SRobert Mustacchi     TYP(offset,4); /* file offset of this section */
451*4d9fdb46SRobert Mustacchi     TYP(align,4); /* section alignment (power of 2) */
452*4d9fdb46SRobert Mustacchi     TYP(reloff,4); /* file offset of relocation entries */
453*4d9fdb46SRobert Mustacchi     TYP(nreloc,4); /* number of relocation entries */
454*4d9fdb46SRobert Mustacchi     TYP(flags,4); /* flags (section type and attributes)*/
455*4d9fdb46SRobert Mustacchi     TYP(reserved1,4); /* reserved (for offset or index) */
456*4d9fdb46SRobert Mustacchi     TYP(reserved2,4); /* reserved (for count or sizeof) */
457*4d9fdb46SRobert Mustacchi     TYP(reserved3,4); /* reserved */
458*4d9fdb46SRobert Mustacchi };
459*4d9fdb46SRobert Mustacchi 
460*4d9fdb46SRobert Mustacchi /*
461*4d9fdb46SRobert Mustacchi * The flags field of a section structure is separated into two parts a section
462*4d9fdb46SRobert Mustacchi * type and section attributes.  The section types are mutually exclusive (it
463*4d9fdb46SRobert Mustacchi * can only have one type) but the section attributes are not (it may have more
464*4d9fdb46SRobert Mustacchi * than one attribute).
465*4d9fdb46SRobert Mustacchi */
466*4d9fdb46SRobert Mustacchi #define SECTION_TYPE         0x000000ff    /* 256 section types */
467*4d9fdb46SRobert Mustacchi #define SECTION_ATTRIBUTES     0xffffff00    /*  24 section attributes */
468*4d9fdb46SRobert Mustacchi 
469*4d9fdb46SRobert Mustacchi /* Constants for the type of a section */
470*4d9fdb46SRobert Mustacchi #define    S_REGULAR        0x0    /* regular section */
471*4d9fdb46SRobert Mustacchi #define    S_ZEROFILL        0x1    /* zero fill on demand section */
472*4d9fdb46SRobert Mustacchi #define    S_CSTRING_LITERALS    0x2    /* section with only literal C strings*/
473*4d9fdb46SRobert Mustacchi #define    S_4BYTE_LITERALS    0x3    /* section with only 4 byte literals */
474*4d9fdb46SRobert Mustacchi #define    S_8BYTE_LITERALS    0x4    /* section with only 8 byte literals */
475*4d9fdb46SRobert Mustacchi #define    S_LITERAL_POINTERS    0x5    /* section with only pointers to */
476*4d9fdb46SRobert Mustacchi     /*  literals */
477*4d9fdb46SRobert Mustacchi /*
478*4d9fdb46SRobert Mustacchi * For the two types of symbol pointers sections and the symbol stubs section
479*4d9fdb46SRobert Mustacchi * they have indirect symbol table entries.  For each of the entries in the
480*4d9fdb46SRobert Mustacchi * section the indirect symbol table entries, in corresponding order in the
481*4d9fdb46SRobert Mustacchi * indirect symbol table, start at the index stored in the reserved1 field
482*4d9fdb46SRobert Mustacchi * of the section structure.  Since the indirect symbol table entries
483*4d9fdb46SRobert Mustacchi * correspond to the entries in the section the number of indirect symbol table
484*4d9fdb46SRobert Mustacchi * entries is inferred from the size of the section divided by the size of the
485*4d9fdb46SRobert Mustacchi * entries in the section.  For symbol pointers sections the size of the entries
486*4d9fdb46SRobert Mustacchi * in the section is 4 bytes and for symbol stubs sections the byte size of the
487*4d9fdb46SRobert Mustacchi * stubs is stored in the reserved2 field of the section structure.
488*4d9fdb46SRobert Mustacchi */
489*4d9fdb46SRobert Mustacchi #define    S_NON_LAZY_SYMBOL_POINTERS    0x6    /* section with only non-lazy
490*4d9fdb46SRobert Mustacchi     symbol pointers */
491*4d9fdb46SRobert Mustacchi #define    S_LAZY_SYMBOL_POINTERS        0x7    /* section with only lazy symbol
492*4d9fdb46SRobert Mustacchi     pointers */
493*4d9fdb46SRobert Mustacchi #define    S_SYMBOL_STUBS            0x8    /* section with only symbol
494*4d9fdb46SRobert Mustacchi     stubs, byte size of stub in
495*4d9fdb46SRobert Mustacchi     the reserved2 field */
496*4d9fdb46SRobert Mustacchi #define    S_MOD_INIT_FUNC_POINTERS    0x9    /* section with only function
497*4d9fdb46SRobert Mustacchi     pointers for initialization*/
498*4d9fdb46SRobert Mustacchi #define    S_MOD_TERM_FUNC_POINTERS    0xa    /* section with only function
499*4d9fdb46SRobert Mustacchi     pointers for termination */
500*4d9fdb46SRobert Mustacchi #define    S_COALESCED            0xb    /* section contains symbols that
501*4d9fdb46SRobert Mustacchi     are to be coalesced */
502*4d9fdb46SRobert Mustacchi #define    S_GB_ZEROFILL            0xc    /* zero fill on demand section
503*4d9fdb46SRobert Mustacchi     (that can be larger than 4
504*4d9fdb46SRobert Mustacchi     gigabytes) */
505*4d9fdb46SRobert Mustacchi #define    S_INTERPOSING            0xd    /* section with only pairs of
506*4d9fdb46SRobert Mustacchi     function pointers for
507*4d9fdb46SRobert Mustacchi     interposing */
508*4d9fdb46SRobert Mustacchi #define    S_16BYTE_LITERALS        0xe    /* section with only 16 byte
509*4d9fdb46SRobert Mustacchi     literals */
510*4d9fdb46SRobert Mustacchi #define    S_DTRACE_DOF            0xf    /* section contains
511*4d9fdb46SRobert Mustacchi     DTrace Object Format */
512*4d9fdb46SRobert Mustacchi #define    S_LAZY_DYLIB_SYMBOL_POINTERS    0x10    /* section with only lazy
513*4d9fdb46SRobert Mustacchi     symbol pointers to lazy
514*4d9fdb46SRobert Mustacchi     loaded dylibs */
515*4d9fdb46SRobert Mustacchi /*
516*4d9fdb46SRobert Mustacchi * Section types to support thread local variables
517*4d9fdb46SRobert Mustacchi */
518*4d9fdb46SRobert Mustacchi #define S_THREAD_LOCAL_REGULAR                   0x11  /* template of initial
519*4d9fdb46SRobert Mustacchi     values for TLVs */
520*4d9fdb46SRobert Mustacchi #define S_THREAD_LOCAL_ZEROFILL                  0x12  /* template of initial
521*4d9fdb46SRobert Mustacchi     values for TLVs */
522*4d9fdb46SRobert Mustacchi #define S_THREAD_LOCAL_VARIABLES                 0x13  /* TLV descriptors */
523*4d9fdb46SRobert Mustacchi #define S_THREAD_LOCAL_VARIABLE_POINTERS         0x14  /* pointers to TLV
524*4d9fdb46SRobert Mustacchi     descriptors */
525*4d9fdb46SRobert Mustacchi #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS    0x15  /* functions to call
526*4d9fdb46SRobert Mustacchi     to initialize TLV
527*4d9fdb46SRobert Mustacchi     values */
528*4d9fdb46SRobert Mustacchi 
529*4d9fdb46SRobert Mustacchi /*
530*4d9fdb46SRobert Mustacchi * Constants for the section attributes part of the flags field of a section
531*4d9fdb46SRobert Mustacchi * structure.
532*4d9fdb46SRobert Mustacchi */
533*4d9fdb46SRobert Mustacchi #define SECTION_ATTRIBUTES_USR     0xff000000    /* User setable attributes */
534*4d9fdb46SRobert Mustacchi #define S_ATTR_PURE_INSTRUCTIONS 0x80000000    /* section contains only true
535*4d9fdb46SRobert Mustacchi     machine instructions */
536*4d9fdb46SRobert Mustacchi #define S_ATTR_NO_TOC          0x40000000    /* section contains coalesced
537*4d9fdb46SRobert Mustacchi     symbols that are not to be
538*4d9fdb46SRobert Mustacchi     in a ranlib table of
539*4d9fdb46SRobert Mustacchi     contents */
540*4d9fdb46SRobert Mustacchi #define S_ATTR_STRIP_STATIC_SYMS 0x20000000    /* ok to strip static symbols
541*4d9fdb46SRobert Mustacchi     in this section in files
542*4d9fdb46SRobert Mustacchi     with the MH_DYLDLINK flag */
543*4d9fdb46SRobert Mustacchi #define S_ATTR_NO_DEAD_STRIP     0x10000000    /* no dead stripping */
544*4d9fdb46SRobert Mustacchi #define S_ATTR_LIVE_SUPPORT     0x08000000    /* blocks are live if they
545*4d9fdb46SRobert Mustacchi     reference live blocks */
546*4d9fdb46SRobert Mustacchi #define S_ATTR_SELF_MODIFYING_CODE 0x04000000    /* Used with i386 code stubs
547*4d9fdb46SRobert Mustacchi     written on by dyld */
548*4d9fdb46SRobert Mustacchi /*
549*4d9fdb46SRobert Mustacchi * If a segment contains any sections marked with S_ATTR_DEBUG then all
550*4d9fdb46SRobert Mustacchi * sections in that segment must have this attribute.  No section other than
551*4d9fdb46SRobert Mustacchi * a section marked with this attribute may reference the contents of this
552*4d9fdb46SRobert Mustacchi * section.  A section with this attribute may contain no symbols and must have
553*4d9fdb46SRobert Mustacchi * a section type S_REGULAR.  The static linker will not copy section contents
554*4d9fdb46SRobert Mustacchi * from sections with this attribute into its output file.  These sections
555*4d9fdb46SRobert Mustacchi * generally contain DWARF debugging info.
556*4d9fdb46SRobert Mustacchi */
557*4d9fdb46SRobert Mustacchi #define    S_ATTR_DEBUG         0x02000000    /* a debug section */
558*4d9fdb46SRobert Mustacchi #define SECTION_ATTRIBUTES_SYS     0x00ffff00    /* system setable attributes */
559*4d9fdb46SRobert Mustacchi #define S_ATTR_SOME_INSTRUCTIONS 0x00000400    /* section contains some
560*4d9fdb46SRobert Mustacchi     machine instructions */
561*4d9fdb46SRobert Mustacchi #define S_ATTR_EXT_RELOC     0x00000200    /* section has external
562*4d9fdb46SRobert Mustacchi     relocation entries */
563*4d9fdb46SRobert Mustacchi #define S_ATTR_LOC_RELOC     0x00000100    /* section has local
564*4d9fdb46SRobert Mustacchi     relocation entries */
565*4d9fdb46SRobert Mustacchi 
566*4d9fdb46SRobert Mustacchi 
567*4d9fdb46SRobert Mustacchi /*
568*4d9fdb46SRobert Mustacchi * The names of segments and sections in them are mostly meaningless to the
569*4d9fdb46SRobert Mustacchi * link-editor.  But there are few things to support traditional UNIX
570*4d9fdb46SRobert Mustacchi * executables that require the link-editor and assembler to use some names
571*4d9fdb46SRobert Mustacchi * agreed upon by convention.
572*4d9fdb46SRobert Mustacchi *
573*4d9fdb46SRobert Mustacchi * The initial protection of the "__TEXT" segment has write protection turned
574*4d9fdb46SRobert Mustacchi * off (not writeable).
575*4d9fdb46SRobert Mustacchi *
576*4d9fdb46SRobert Mustacchi * The link-editor will allocate common symbols at the end of the "__common"
577*4d9fdb46SRobert Mustacchi * section in the "__DATA" segment.  It will create the section and segment
578*4d9fdb46SRobert Mustacchi * if needed.
579*4d9fdb46SRobert Mustacchi */
580*4d9fdb46SRobert Mustacchi 
581*4d9fdb46SRobert Mustacchi /* The currently known segment names and the section names in those segments */
582*4d9fdb46SRobert Mustacchi 
583*4d9fdb46SRobert Mustacchi #define    SEG_PAGEZERO    "__PAGEZERO"    /* the pagezero segment which has no */
584*4d9fdb46SRobert Mustacchi                     /* protections and catches NULL */
585*4d9fdb46SRobert Mustacchi                     /* references for MH_EXECUTE files */
586*4d9fdb46SRobert Mustacchi 
587*4d9fdb46SRobert Mustacchi 
588*4d9fdb46SRobert Mustacchi #define    SEG_TEXT    "__TEXT"    /* the tradition UNIX text segment */
589*4d9fdb46SRobert Mustacchi #define    SECT_TEXT    "__text"    /* the real text part of the text */
590*4d9fdb46SRobert Mustacchi                     /* section no headers, and no padding */
591*4d9fdb46SRobert Mustacchi #define SECT_FVMLIB_INIT0 "__fvmlib_init0"    /* the fvmlib initialization */
592*4d9fdb46SRobert Mustacchi                         /*  section */
593*4d9fdb46SRobert Mustacchi #define SECT_FVMLIB_INIT1 "__fvmlib_init1"    /* the section following the */
594*4d9fdb46SRobert Mustacchi                             /*  fvmlib initialization */
595*4d9fdb46SRobert Mustacchi                         /*  section */
596*4d9fdb46SRobert Mustacchi 
597*4d9fdb46SRobert Mustacchi #define    SEG_DATA    "__DATA"    /* the tradition UNIX data segment */
598*4d9fdb46SRobert Mustacchi #define    SECT_DATA    "__data"    /* the real initialized data section */
599*4d9fdb46SRobert Mustacchi                     /* no padding, no bss overlap */
600*4d9fdb46SRobert Mustacchi #define    SECT_BSS    "__bss"        /* the real uninitialized data section*/
601*4d9fdb46SRobert Mustacchi                     /* no padding */
602*4d9fdb46SRobert Mustacchi #define SECT_COMMON    "__common"    /* the section common symbols are */
603*4d9fdb46SRobert Mustacchi                     /* allocated in by the link editor */
604*4d9fdb46SRobert Mustacchi 
605*4d9fdb46SRobert Mustacchi #define    SEG_OBJC    "__OBJC"    /* objective-C runtime segment */
606*4d9fdb46SRobert Mustacchi #define SECT_OBJC_SYMBOLS "__symbol_table"    /* symbol table */
607*4d9fdb46SRobert Mustacchi #define SECT_OBJC_MODULES "__module_info"    /* module information */
608*4d9fdb46SRobert Mustacchi #define SECT_OBJC_STRINGS "__selector_strs"    /* string table */
609*4d9fdb46SRobert Mustacchi #define SECT_OBJC_REFS "__selector_refs"    /* string table */
610*4d9fdb46SRobert Mustacchi 
611*4d9fdb46SRobert Mustacchi #define    SEG_ICON     "__ICON"    /* the icon segment */
612*4d9fdb46SRobert Mustacchi #define    SECT_ICON_HEADER "__header"    /* the icon headers */
613*4d9fdb46SRobert Mustacchi #define    SECT_ICON_TIFF   "__tiff"    /* the icons in tiff format */
614*4d9fdb46SRobert Mustacchi 
615*4d9fdb46SRobert Mustacchi #define    SEG_LINKEDIT    "__LINKEDIT"    /* the segment containing all structs */
616*4d9fdb46SRobert Mustacchi                     /* created and maintained by the link */
617*4d9fdb46SRobert Mustacchi                     /* editor.  Created with -seglinkedit */
618*4d9fdb46SRobert Mustacchi                     /* option to ld(1) for MH_EXECUTE and */
619*4d9fdb46SRobert Mustacchi                     /* FVMLIB file types only */
620*4d9fdb46SRobert Mustacchi 
621*4d9fdb46SRobert Mustacchi #define SEG_UNIXSTACK    "__UNIXSTACK"    /* the unix stack segment */
622*4d9fdb46SRobert Mustacchi 
623*4d9fdb46SRobert Mustacchi #define SEG_IMPORT    "__IMPORT"    /* the segment for the self (dyld) */
624*4d9fdb46SRobert Mustacchi                     /* modifing code stubs that has read, */
625*4d9fdb46SRobert Mustacchi                     /* write and execute permissions */
626*4d9fdb46SRobert Mustacchi 
627*4d9fdb46SRobert Mustacchi /*
628*4d9fdb46SRobert Mustacchi * Fixed virtual memory shared libraries are identified by two things.  The
629*4d9fdb46SRobert Mustacchi * target pathname (the name of the library as found for execution), and the
630*4d9fdb46SRobert Mustacchi * minor version number.  The address of where the headers are loaded is in
631*4d9fdb46SRobert Mustacchi * header_addr. (THIS IS OBSOLETE and no longer supported).
632*4d9fdb46SRobert Mustacchi */
633*4d9fdb46SRobert Mustacchi struct fvmlib {
634*4d9fdb46SRobert Mustacchi     union lc_str    name;        /* library's target pathname */
635*4d9fdb46SRobert Mustacchi     TYP(minor_version,4); /* library's minor version number */
636*4d9fdb46SRobert Mustacchi     TYP(header_addr,4); /* library's header address */
637*4d9fdb46SRobert Mustacchi };
638*4d9fdb46SRobert Mustacchi 
639*4d9fdb46SRobert Mustacchi /*
640*4d9fdb46SRobert Mustacchi * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
641*4d9fdb46SRobert Mustacchi * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library.
642*4d9fdb46SRobert Mustacchi * An object that uses a fixed virtual shared library also contains a
643*4d9fdb46SRobert Mustacchi * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses.
644*4d9fdb46SRobert Mustacchi * (THIS IS OBSOLETE and no longer supported).
645*4d9fdb46SRobert Mustacchi */
646*4d9fdb46SRobert Mustacchi struct fvmlib_command {
647*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_IDFVMLIB or LC_LOADFVMLIB */
648*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes pathname string */
649*4d9fdb46SRobert Mustacchi     struct fvmlib    fvmlib;        /* the library identification */
650*4d9fdb46SRobert Mustacchi };
651*4d9fdb46SRobert Mustacchi 
652*4d9fdb46SRobert Mustacchi /*
653*4d9fdb46SRobert Mustacchi * Dynamicly linked shared libraries are identified by two things.  The
654*4d9fdb46SRobert Mustacchi * pathname (the name of the library as found for execution), and the
655*4d9fdb46SRobert Mustacchi * compatibility version number.  The pathname must match and the compatibility
656*4d9fdb46SRobert Mustacchi * number in the user of the library must be greater than or equal to the
657*4d9fdb46SRobert Mustacchi * library being used.  The time stamp is used to record the time a library was
658*4d9fdb46SRobert Mustacchi * built and copied into user so it can be use to determined if the library used
659*4d9fdb46SRobert Mustacchi * at runtime is exactly the same as used to built the program.
660*4d9fdb46SRobert Mustacchi */
661*4d9fdb46SRobert Mustacchi struct dylib {
662*4d9fdb46SRobert Mustacchi     union lc_str  name;            /* library's path name */
663*4d9fdb46SRobert Mustacchi     TYP(timestamp,4); /* library's build time stamp */
664*4d9fdb46SRobert Mustacchi     TYP(current_version,4); /* library's current version number */
665*4d9fdb46SRobert Mustacchi     TYP(compatibility_version,4); /* library's compatibility vers number*/
666*4d9fdb46SRobert Mustacchi };
667*4d9fdb46SRobert Mustacchi 
668*4d9fdb46SRobert Mustacchi /*
669*4d9fdb46SRobert Mustacchi * A dynamically linked shared library (filetype == MH_DYLIB in the mach header)
670*4d9fdb46SRobert Mustacchi * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library.
671*4d9fdb46SRobert Mustacchi * An object that uses a dynamically linked shared library also contains a
672*4d9fdb46SRobert Mustacchi * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or
673*4d9fdb46SRobert Mustacchi * LC_REEXPORT_DYLIB) for each library it uses.
674*4d9fdb46SRobert Mustacchi */
675*4d9fdb46SRobert Mustacchi struct dylib_command {
676*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,
677*4d9fdb46SRobert Mustacchi         LC_REEXPORT_DYLIB */
678*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes pathname string */
679*4d9fdb46SRobert Mustacchi     struct dylib    dylib;        /* the library identification */
680*4d9fdb46SRobert Mustacchi };
681*4d9fdb46SRobert Mustacchi 
682*4d9fdb46SRobert Mustacchi /*
683*4d9fdb46SRobert Mustacchi * A dynamically linked shared library may be a subframework of an umbrella
684*4d9fdb46SRobert Mustacchi * framework.  If so it will be linked with "-umbrella umbrella_name" where
685*4d9fdb46SRobert Mustacchi * Where "umbrella_name" is the name of the umbrella framework. A subframework
686*4d9fdb46SRobert Mustacchi * can only be linked against by its umbrella framework or other subframeworks
687*4d9fdb46SRobert Mustacchi * that are part of the same umbrella framework.  Otherwise the static link
688*4d9fdb46SRobert Mustacchi * editor produces an error and states to link against the umbrella framework.
689*4d9fdb46SRobert Mustacchi * The name of the umbrella framework for subframeworks is recorded in the
690*4d9fdb46SRobert Mustacchi * following structure.
691*4d9fdb46SRobert Mustacchi */
692*4d9fdb46SRobert Mustacchi struct sub_framework_command {
693*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SUB_FRAMEWORK */
694*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes umbrella string */
695*4d9fdb46SRobert Mustacchi     union lc_str     umbrella;    /* the umbrella framework name */
696*4d9fdb46SRobert Mustacchi };
697*4d9fdb46SRobert Mustacchi 
698*4d9fdb46SRobert Mustacchi /*
699*4d9fdb46SRobert Mustacchi * For dynamically linked shared libraries that are subframework of an umbrella
700*4d9fdb46SRobert Mustacchi * framework they can allow clients other than the umbrella framework or other
701*4d9fdb46SRobert Mustacchi * subframeworks in the same umbrella framework.  To do this the subframework
702*4d9fdb46SRobert Mustacchi * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load
703*4d9fdb46SRobert Mustacchi * command is created for each -allowable_client flag.  The client_name is
704*4d9fdb46SRobert Mustacchi * usually a framework name.  It can also be a name used for bundles clients
705*4d9fdb46SRobert Mustacchi * where the bundle is built with "-client_name client_name".
706*4d9fdb46SRobert Mustacchi */
707*4d9fdb46SRobert Mustacchi struct sub_client_command {
708*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SUB_CLIENT */
709*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes client string */
710*4d9fdb46SRobert Mustacchi     union lc_str     client;        /* the client name */
711*4d9fdb46SRobert Mustacchi };
712*4d9fdb46SRobert Mustacchi 
713*4d9fdb46SRobert Mustacchi /*
714*4d9fdb46SRobert Mustacchi * A dynamically linked shared library may be a sub_umbrella of an umbrella
715*4d9fdb46SRobert Mustacchi * framework.  If so it will be linked with "-sub_umbrella umbrella_name" where
716*4d9fdb46SRobert Mustacchi * Where "umbrella_name" is the name of the sub_umbrella framework.  When
717*4d9fdb46SRobert Mustacchi * staticly linking when -twolevel_namespace is in effect a twolevel namespace
718*4d9fdb46SRobert Mustacchi * umbrella framework will only cause its subframeworks and those frameworks
719*4d9fdb46SRobert Mustacchi * listed as sub_umbrella frameworks to be implicited linked in.  Any other
720*4d9fdb46SRobert Mustacchi * dependent dynamic libraries will not be linked it when -twolevel_namespace
721*4d9fdb46SRobert Mustacchi * is in effect.  The primary library recorded by the static linker when
722*4d9fdb46SRobert Mustacchi * resolving a symbol in these libraries will be the umbrella framework.
723*4d9fdb46SRobert Mustacchi * Zero or more sub_umbrella frameworks may be use by an umbrella framework.
724*4d9fdb46SRobert Mustacchi * The name of a sub_umbrella framework is recorded in the following structure.
725*4d9fdb46SRobert Mustacchi */
726*4d9fdb46SRobert Mustacchi struct sub_umbrella_command {
727*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SUB_UMBRELLA */
728*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes sub_umbrella string */
729*4d9fdb46SRobert Mustacchi     union lc_str     sub_umbrella;    /* the sub_umbrella framework name */
730*4d9fdb46SRobert Mustacchi };
731*4d9fdb46SRobert Mustacchi 
732*4d9fdb46SRobert Mustacchi /*
733*4d9fdb46SRobert Mustacchi * A dynamically linked shared library may be a sub_library of another shared
734*4d9fdb46SRobert Mustacchi * library.  If so it will be linked with "-sub_library library_name" where
735*4d9fdb46SRobert Mustacchi * Where "library_name" is the name of the sub_library shared library.  When
736*4d9fdb46SRobert Mustacchi * staticly linking when -twolevel_namespace is in effect a twolevel namespace
737*4d9fdb46SRobert Mustacchi * shared library will only cause its subframeworks and those frameworks
738*4d9fdb46SRobert Mustacchi * listed as sub_umbrella frameworks and libraries listed as sub_libraries to
739*4d9fdb46SRobert Mustacchi * be implicited linked in.  Any other dependent dynamic libraries will not be
740*4d9fdb46SRobert Mustacchi * linked it when -twolevel_namespace is in effect.  The primary library
741*4d9fdb46SRobert Mustacchi * recorded by the static linker when resolving a symbol in these libraries
742*4d9fdb46SRobert Mustacchi * will be the umbrella framework (or dynamic library). Zero or more sub_library
743*4d9fdb46SRobert Mustacchi * shared libraries may be use by an umbrella framework or (or dynamic library).
744*4d9fdb46SRobert Mustacchi * The name of a sub_library framework is recorded in the following structure.
745*4d9fdb46SRobert Mustacchi * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".
746*4d9fdb46SRobert Mustacchi */
747*4d9fdb46SRobert Mustacchi struct sub_library_command {
748*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SUB_LIBRARY */
749*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes sub_library string */
750*4d9fdb46SRobert Mustacchi     union lc_str     sub_library;    /* the sub_library name */
751*4d9fdb46SRobert Mustacchi };
752*4d9fdb46SRobert Mustacchi 
753*4d9fdb46SRobert Mustacchi /*
754*4d9fdb46SRobert Mustacchi * A program (filetype == MH_EXECUTE) that is
755*4d9fdb46SRobert Mustacchi * prebound to its dynamic libraries has one of these for each library that
756*4d9fdb46SRobert Mustacchi * the static linker used in prebinding.  It contains a bit vector for the
757*4d9fdb46SRobert Mustacchi * modules in the library.  The bits indicate which modules are bound (1) and
758*4d9fdb46SRobert Mustacchi * which are not (0) from the library.  The bit for module 0 is the low bit
759*4d9fdb46SRobert Mustacchi * of the first byte.  So the bit for the Nth module is:
760*4d9fdb46SRobert Mustacchi * (linked_modules[N/8] >> N%8) & 1
761*4d9fdb46SRobert Mustacchi */
762*4d9fdb46SRobert Mustacchi struct prebound_dylib_command {
763*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_PREBOUND_DYLIB */
764*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes strings */
765*4d9fdb46SRobert Mustacchi     union lc_str    name;        /* library's path name */
766*4d9fdb46SRobert Mustacchi     TYP(nmodules,4); /* number of modules in library */
767*4d9fdb46SRobert Mustacchi     union lc_str    linked_modules;    /* bit vector of linked modules */
768*4d9fdb46SRobert Mustacchi };
769*4d9fdb46SRobert Mustacchi 
770*4d9fdb46SRobert Mustacchi /*
771*4d9fdb46SRobert Mustacchi * A program that uses a dynamic linker contains a dylinker_command to identify
772*4d9fdb46SRobert Mustacchi * the name of the dynamic linker (LC_LOAD_DYLINKER).  And a dynamic linker
773*4d9fdb46SRobert Mustacchi * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER).
774*4d9fdb46SRobert Mustacchi * A file can have at most one of these.
775*4d9fdb46SRobert Mustacchi * This struct is also used for the LC_DYLD_ENVIRONMENT load command and
776*4d9fdb46SRobert Mustacchi * contains string for dyld to treat like environment variable.
777*4d9fdb46SRobert Mustacchi */
778*4d9fdb46SRobert Mustacchi struct dylinker_command {
779*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_ID_DYLINKER, LC_LOAD_DYLINKER or
780*4d9fdb46SRobert Mustacchi         LC_DYLD_ENVIRONMENT */
781*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* includes pathname string */
782*4d9fdb46SRobert Mustacchi     union lc_str    name;        /* dynamic linker's path name */
783*4d9fdb46SRobert Mustacchi };
784*4d9fdb46SRobert Mustacchi 
785*4d9fdb46SRobert Mustacchi /*
786*4d9fdb46SRobert Mustacchi * Thread commands contain machine-specific data structures suitable for
787*4d9fdb46SRobert Mustacchi * use in the thread state primitives.  The machine specific data structures
788*4d9fdb46SRobert Mustacchi * follow the struct thread_command as follows.
789*4d9fdb46SRobert Mustacchi * Each flavor of machine specific data structure is preceded by an unsigned
790*4d9fdb46SRobert Mustacchi * long constant for the flavor of that data structure, an uint32_t
791*4d9fdb46SRobert Mustacchi * that is the count of longs of the size of the state data structure and then
792*4d9fdb46SRobert Mustacchi * the state data structure follows.  This triple may be repeated for many
793*4d9fdb46SRobert Mustacchi * flavors.  The constants for the flavors, counts and state data structure
794*4d9fdb46SRobert Mustacchi * definitions are expected to be in the header file <machine/thread_status.h>.
795*4d9fdb46SRobert Mustacchi * These machine specific data structures sizes must be multiples of
796*4d9fdb46SRobert Mustacchi * 4 bytes  The cmdsize reflects the total size of the thread_command
797*4d9fdb46SRobert Mustacchi * and all of the sizes of the constants for the flavors, counts and state
798*4d9fdb46SRobert Mustacchi * data structures.
799*4d9fdb46SRobert Mustacchi *
800*4d9fdb46SRobert Mustacchi * For executable objects that are unix processes there will be one
801*4d9fdb46SRobert Mustacchi * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.
802*4d9fdb46SRobert Mustacchi * This is the same as a LC_THREAD, except that a stack is automatically
803*4d9fdb46SRobert Mustacchi * created (based on the shell's limit for the stack size).  Command arguments
804*4d9fdb46SRobert Mustacchi * and environment variables are copied onto that stack.
805*4d9fdb46SRobert Mustacchi */
806*4d9fdb46SRobert Mustacchi struct thread_command {
807*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_THREAD or LC_UNIXTHREAD */
808*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* total size of this command */
809*4d9fdb46SRobert Mustacchi     /* uint32_t flavor           flavor of thread state */
810*4d9fdb46SRobert Mustacchi     /* uint32_t count           count of longs in thread state */
811*4d9fdb46SRobert Mustacchi     /* struct XXX_thread_state state   thread state for this flavor */
812*4d9fdb46SRobert Mustacchi     /* ... */
813*4d9fdb46SRobert Mustacchi };
814*4d9fdb46SRobert Mustacchi 
815*4d9fdb46SRobert Mustacchi /*
816*4d9fdb46SRobert Mustacchi * The routines command contains the address of the dynamic shared library
817*4d9fdb46SRobert Mustacchi * initialization routine and an index into the module table for the module
818*4d9fdb46SRobert Mustacchi * that defines the routine.  Before any modules are used from the library the
819*4d9fdb46SRobert Mustacchi * dynamic linker fully binds the module that defines the initialization routine
820*4d9fdb46SRobert Mustacchi * and then calls it.  This gets called before any module initialization
821*4d9fdb46SRobert Mustacchi * routines (used for C++ static constructors) in the library.
822*4d9fdb46SRobert Mustacchi */
823*4d9fdb46SRobert Mustacchi struct routines_command { /* for 32-bit architectures */
824*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_ROUTINES */
825*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* total size of this command */
826*4d9fdb46SRobert Mustacchi     TYP(init_address,4); /* address of initialization routine */
827*4d9fdb46SRobert Mustacchi     TYP(init_module,4); /* index into the module table that */
828*4d9fdb46SRobert Mustacchi         /*  the init routine is defined in */
829*4d9fdb46SRobert Mustacchi     TYP(reserved1,4);
830*4d9fdb46SRobert Mustacchi     TYP(reserved2,4);
831*4d9fdb46SRobert Mustacchi     TYP(reserved3,4);
832*4d9fdb46SRobert Mustacchi     TYP(reserved4,4);
833*4d9fdb46SRobert Mustacchi     TYP(reserved5,4);
834*4d9fdb46SRobert Mustacchi     TYP(reserved6,4);
835*4d9fdb46SRobert Mustacchi };
836*4d9fdb46SRobert Mustacchi 
837*4d9fdb46SRobert Mustacchi /*
838*4d9fdb46SRobert Mustacchi * The 64-bit routines command.  Same use as above.
839*4d9fdb46SRobert Mustacchi */
840*4d9fdb46SRobert Mustacchi struct routines_command_64 { /* for 64-bit architectures */
841*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_ROUTINES_64 */
842*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* total size of this command */
843*4d9fdb46SRobert Mustacchi     TYP(init_address,8); /* address of initialization routine */
844*4d9fdb46SRobert Mustacchi     TYP(init_module,8); /* index into the module table that */
845*4d9fdb46SRobert Mustacchi         /*  the init routine is defined in */
846*4d9fdb46SRobert Mustacchi     TYP(reserved1,8);
847*4d9fdb46SRobert Mustacchi     TYP(reserved2,8);
848*4d9fdb46SRobert Mustacchi     TYP(reserved3,8);
849*4d9fdb46SRobert Mustacchi     TYP(reserved4,8);
850*4d9fdb46SRobert Mustacchi     TYP(reserved5,8);
851*4d9fdb46SRobert Mustacchi     TYP(reserved6,8);
852*4d9fdb46SRobert Mustacchi };
853*4d9fdb46SRobert Mustacchi 
854*4d9fdb46SRobert Mustacchi /*
855*4d9fdb46SRobert Mustacchi * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD
856*4d9fdb46SRobert Mustacchi * "stab" style symbol table information as described in the header files
857*4d9fdb46SRobert Mustacchi * <nlist.h> and <stab.h>.
858*4d9fdb46SRobert Mustacchi */
859*4d9fdb46SRobert Mustacchi struct symtab_command {
860*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_SYMTAB */
861*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* sizeof(struct symtab_command) */
862*4d9fdb46SRobert Mustacchi     TYP(symoff,4); /* symbol table offset */
863*4d9fdb46SRobert Mustacchi     TYP(nsyms,4); /* number of symbol table entries */
864*4d9fdb46SRobert Mustacchi     TYP(stroff,4); /* string table offset */
865*4d9fdb46SRobert Mustacchi     TYP(strsize,4); /* string table size in bytes */
866*4d9fdb46SRobert Mustacchi };
867*4d9fdb46SRobert Mustacchi 
868*4d9fdb46SRobert Mustacchi /*
869*4d9fdb46SRobert Mustacchi * This is the second set of the symbolic information which is used to support
870*4d9fdb46SRobert Mustacchi * the data structures for the dynamically link editor.
871*4d9fdb46SRobert Mustacchi *
872*4d9fdb46SRobert Mustacchi * The original set of symbolic information in the symtab_command which contains
873*4d9fdb46SRobert Mustacchi * the symbol and string tables must also be present when this load command is
874*4d9fdb46SRobert Mustacchi * present.  When this load command is present the symbol table is organized
875*4d9fdb46SRobert Mustacchi * into three groups of symbols:
876*4d9fdb46SRobert Mustacchi *    local symbols (static and debugging symbols) - grouped by module
877*4d9fdb46SRobert Mustacchi *    defined external symbols - grouped by module (sorted by name if not lib)
878*4d9fdb46SRobert Mustacchi *    undefined external symbols (sorted by name if MH_BINDATLOAD is not set,
879*4d9fdb46SRobert Mustacchi *                         and in order the were seen by the static
880*4d9fdb46SRobert Mustacchi *                    linker if MH_BINDATLOAD is set)
881*4d9fdb46SRobert Mustacchi * In this load command there are offsets and counts to each of the three groups
882*4d9fdb46SRobert Mustacchi * of symbols.
883*4d9fdb46SRobert Mustacchi *
884*4d9fdb46SRobert Mustacchi * This load command contains a the offsets and sizes of the following new
885*4d9fdb46SRobert Mustacchi * symbolic information tables:
886*4d9fdb46SRobert Mustacchi *    table of contents
887*4d9fdb46SRobert Mustacchi *    module table
888*4d9fdb46SRobert Mustacchi *    reference symbol table
889*4d9fdb46SRobert Mustacchi *    indirect symbol table
890*4d9fdb46SRobert Mustacchi * The first three tables above (the table of contents, module table and
891*4d9fdb46SRobert Mustacchi * reference symbol table) are only present if the file is a dynamically linked
892*4d9fdb46SRobert Mustacchi * shared library.  For executable and object modules, which are files
893*4d9fdb46SRobert Mustacchi * containing only one module, the information that would be in these three
894*4d9fdb46SRobert Mustacchi * tables is determined as follows:
895*4d9fdb46SRobert Mustacchi *     table of contents - the defined external symbols are sorted by name
896*4d9fdb46SRobert Mustacchi *    module table - the file contains only one module so everything in the
897*4d9fdb46SRobert Mustacchi *               file is part of the module.
898*4d9fdb46SRobert Mustacchi *    reference symbol table - is the defined and undefined external symbols
899*4d9fdb46SRobert Mustacchi *
900*4d9fdb46SRobert Mustacchi * For dynamically linked shared library files this load command also contains
901*4d9fdb46SRobert Mustacchi * offsets and sizes to the pool of relocation entries for all sections
902*4d9fdb46SRobert Mustacchi * separated into two groups:
903*4d9fdb46SRobert Mustacchi *    external relocation entries
904*4d9fdb46SRobert Mustacchi *    local relocation entries
905*4d9fdb46SRobert Mustacchi * For executable and object modules the relocation entries continue to hang
906*4d9fdb46SRobert Mustacchi * off the section structures.
907*4d9fdb46SRobert Mustacchi */
908*4d9fdb46SRobert Mustacchi struct dysymtab_command {
909*4d9fdb46SRobert Mustacchi     TYP(cmd,4); /* LC_DYSYMTAB */
910*4d9fdb46SRobert Mustacchi     TYP(cmdsize,4); /* sizeof(struct dysymtab_command) */
911*4d9fdb46SRobert Mustacchi 
912*4d9fdb46SRobert Mustacchi     /*
913*4d9fdb46SRobert Mustacchi     * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
914*4d9fdb46SRobert Mustacchi     * are grouped into the following three groups:
915*4d9fdb46SRobert Mustacchi     *    local symbols (further grouped by the module they are from)
916*4d9fdb46SRobert Mustacchi     *    defined external symbols (further grouped by the module they are from)
917*4d9fdb46SRobert Mustacchi     *    undefined symbols
918*4d9fdb46SRobert Mustacchi     *
919*4d9fdb46SRobert Mustacchi     * The local symbols are used only for debugging.  The dynamic binding
920*4d9fdb46SRobert Mustacchi     * process may have to use them to indicate to the debugger the local