]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
593a1d5f | 2 | * Copyright (c) 1999-2008 Apple Inc. All Rights Reserved. |
1c79356b | 3 | * |
b0d623f7 | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
b0d623f7 A |
9 | * compliance with the License. Please obtain a copy of the License at |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
2d21ac55 A |
12 | * |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
8f6c56a5 | 20 | * |
b0d623f7 | 21 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
22 | */ |
23 | #ifndef _MACHO_LOADER_H_ | |
24 | #define _MACHO_LOADER_H_ | |
25 | ||
26 | /* | |
27 | * This file describes the format of mach object files. | |
28 | */ | |
2d21ac55 | 29 | #include <stdint.h> |
1c79356b A |
30 | |
31 | /* | |
32 | * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types | |
33 | * and contains the constants for the possible values of these types. | |
34 | */ | |
35 | #include <mach/machine.h> | |
36 | ||
37 | /* | |
38 | * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the | |
39 | * constants that are or'ed together for the possible values of this type. | |
40 | */ | |
41 | #include <mach/vm_prot.h> | |
42 | ||
43 | /* | |
44 | * <machine/thread_status.h> is expected to define the flavors of the thread | |
45 | * states and the structures of those flavors for each machine. | |
46 | */ | |
47 | #include <mach/machine/thread_status.h> | |
2d21ac55 | 48 | #include <architecture/byte_order.h> |
1c79356b A |
49 | |
50 | /* | |
2d21ac55 A |
51 | * The 32-bit mach header appears at the very beginning of the object file for |
52 | * 32-bit architectures. | |
1c79356b A |
53 | */ |
54 | struct mach_header { | |
91447636 | 55 | uint32_t magic; /* mach magic number identifier */ |
1c79356b A |
56 | cpu_type_t cputype; /* cpu specifier */ |
57 | cpu_subtype_t cpusubtype; /* machine specifier */ | |
91447636 A |
58 | uint32_t filetype; /* type of file */ |
59 | uint32_t ncmds; /* number of load commands */ | |
60 | uint32_t sizeofcmds; /* the size of all the load commands */ | |
61 | uint32_t flags; /* flags */ | |
62 | }; | |
63 | ||
2d21ac55 A |
64 | /* Constant for the magic field of the mach_header (32-bit architectures) */ |
65 | #define MH_MAGIC 0xfeedface /* the mach magic number */ | |
66 | #define MH_CIGAM 0xcefaedfe /* NXSwapInt(MH_MAGIC) */ | |
67 | ||
91447636 A |
68 | /* |
69 | * The 64-bit mach header appears at the very beginning of object files for | |
70 | * 64-bit architectures. | |
71 | */ | |
72 | struct mach_header_64 { | |
73 | uint32_t magic; /* mach magic number identifier */ | |
74 | cpu_type_t cputype; /* cpu specifier */ | |
75 | cpu_subtype_t cpusubtype; /* machine specifier */ | |
76 | uint32_t filetype; /* type of file */ | |
77 | uint32_t ncmds; /* number of load commands */ | |
78 | uint32_t sizeofcmds; /* the size of all the load commands */ | |
79 | uint32_t flags; /* flags */ | |
80 | uint32_t reserved; /* reserved */ | |
1c79356b A |
81 | }; |
82 | ||
91447636 | 83 | /* Constant for the magic field of the mach_header_64 (64-bit architectures) */ |
2d21ac55 A |
84 | #define MH_MAGIC_64 0xfeedfacf /* the 64-bit mach magic number */ |
85 | #define MH_CIGAM_64 0xcffaedfe /* NXSwapInt(MH_MAGIC_64) */ | |
91447636 | 86 | |
1c79356b A |
87 | /* |
88 | * The layout of the file depends on the filetype. For all but the MH_OBJECT | |
89 | * file type the segments are padded out and aligned on a segment alignment | |
90 | * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB, | |
91 | * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part | |
92 | * of their first segment. | |
93 | * | |
94 | * The file type MH_OBJECT is a compact format intended as output of the | |
95 | * assembler and input (and possibly output) of the link editor (the .o | |
96 | * format). All sections are in one unnamed segment with no segment padding. | |
97 | * This format is used as an executable format when the file is so small the | |
2d21ac55 | 98 | * segment padding greatly increases its size. |
1c79356b A |
99 | * |
100 | * The file type MH_PRELOAD is an executable format intended for things that | |
2d21ac55 | 101 | * are not executed under the kernel (proms, stand alones, kernels, etc). The |
1c79356b A |
102 | * format can be executed under the kernel but may demand paged it and not |
103 | * preload it before execution. | |
104 | * | |
105 | * A core file is in MH_CORE format and can be any in an arbritray legal | |
106 | * Mach-O file. | |
107 | * | |
108 | * Constants for the filetype field of the mach_header | |
109 | */ | |
110 | #define MH_OBJECT 0x1 /* relocatable object file */ | |
111 | #define MH_EXECUTE 0x2 /* demand paged executable file */ | |
112 | #define MH_FVMLIB 0x3 /* fixed VM shared library file */ | |
113 | #define MH_CORE 0x4 /* core file */ | |
114 | #define MH_PRELOAD 0x5 /* preloaded executable file */ | |
2d21ac55 | 115 | #define MH_DYLIB 0x6 /* dynamically bound shared library */ |
1c79356b | 116 | #define MH_DYLINKER 0x7 /* dynamic link editor */ |
2d21ac55 A |
117 | #define MH_BUNDLE 0x8 /* dynamically bound bundle file */ |
118 | #define MH_DYLIB_STUB 0x9 /* shared library stub for static */ | |
119 | /* linking only, no section contents */ | |
120 | #define MH_DSYM 0xa /* companion file with only debug */ | |
121 | /* sections */ | |
b0d623f7 | 122 | #define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */ |
1c79356b A |
123 | |
124 | /* Constants for the flags field of the mach_header */ | |
125 | #define MH_NOUNDEFS 0x1 /* the object file has no undefined | |
2d21ac55 | 126 | references */ |
1c79356b A |
127 | #define MH_INCRLINK 0x2 /* the object file is the output of an |
128 | incremental link against a base file | |
129 | and can't be link edited again */ | |
130 | #define MH_DYLDLINK 0x4 /* the object file is input for the | |
131 | dynamic linker and can't be staticly | |
132 | link edited again */ | |
133 | #define MH_BINDATLOAD 0x8 /* the object file's undefined | |
134 | references are bound by the dynamic | |
135 | linker when loaded. */ | |
2d21ac55 | 136 | #define MH_PREBOUND 0x10 /* the file has its dynamic undefined |
1c79356b | 137 | references prebound. */ |
2d21ac55 A |
138 | #define MH_SPLIT_SEGS 0x20 /* the file has its read-only and |
139 | read-write segments split */ | |
140 | #define MH_LAZY_INIT 0x40 /* the shared library init routine is | |
141 | to be run lazily via catching memory | |
142 | faults to its writeable segments | |
143 | (obsolete) */ | |
144 | #define MH_TWOLEVEL 0x80 /* the image is using two-level name | |
145 | space bindings */ | |
146 | #define MH_FORCE_FLAT 0x100 /* the executable is forcing all images | |
147 | to use flat name space bindings */ | |
148 | #define MH_NOMULTIDEFS 0x200 /* this umbrella guarantees no multiple | |
149 | defintions of symbols in its | |
150 | sub-images so the two-level namespace | |
151 | hints can always be used. */ | |
152 | #define MH_NOFIXPREBINDING 0x400 /* do not have dyld notify the | |
153 | prebinding agent about this | |
154 | executable */ | |
155 | #define MH_PREBINDABLE 0x800 /* the binary is not prebound but can | |
156 | have its prebinding redone. only used | |
157 | when MH_PREBOUND is not set. */ | |
158 | #define MH_ALLMODSBOUND 0x1000 /* indicates that this binary binds to | |
159 | all two-level namespace modules of | |
160 | its dependent libraries. only used | |
161 | when MH_PREBINDABLE and MH_TWOLEVEL | |
162 | are both set. */ | |
163 | #define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into | |
164 | sub-sections via symbols for dead | |
165 | code stripping */ | |
166 | #define MH_CANONICAL 0x4000 /* the binary has been canonicalized | |
167 | via the unprebind operation */ | |
168 | #define MH_WEAK_DEFINES 0x8000 /* the final linked image contains | |
169 | external weak symbols */ | |
170 | #define MH_BINDS_TO_WEAK 0x10000 /* the final linked image uses | |
171 | weak symbols */ | |
172 | ||
0c530ab8 A |
173 | #define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks |
174 | in the task will be given stack | |
175 | execution privilege. Only used in | |
176 | MH_EXECUTE filetypes. */ | |
b0d623f7 A |
177 | #define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When |
178 | linking against a dylib that | |
179 | has this bit set, the static linker | |
180 | will automatically not create a | |
181 | LC_LOAD_DYLIB load command to the | |
182 | dylib if no symbols are being | |
183 | referenced from the dylib. */ | |
2d21ac55 A |
184 | #define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary |
185 | declares it is safe for use in | |
186 | processes with uid zero */ | |
187 | ||
188 | #define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary | |
189 | declares it is safe for use in | |
190 | processes when issetugid() is true */ | |
191 | ||
192 | #define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib, | |
193 | the static linker does not need to | |
194 | examine dependent dylibs to see | |
195 | if any are re-exported */ | |
593a1d5f A |
196 | #define MH_PIE 0x200000 /* When this bit is set, the OS will |
197 | load the main executable at a | |
198 | random address. Only used in | |
199 | MH_EXECUTE filetypes. */ | |
6d2010ae A |
200 | #define MH_NO_HEAP_EXECUTION 0x1000000 /* When this bit is set, the OS will |
201 | run the main executable with | |
202 | a non-executable heap even on | |
203 | platforms (e.g. i386) that don't | |
204 | require it. Only used in MH_EXECUTE | |
205 | filetypes. */ | |
1c79356b A |
206 | |
207 | /* | |
208 | * The load commands directly follow the mach_header. The total size of all | |
209 | * of the commands is given by the sizeofcmds field in the mach_header. All | |
210 | * load commands must have as their first two fields cmd and cmdsize. The cmd | |
211 | * field is filled in with a constant for that command type. Each command type | |
212 | * has a structure specifically for it. The cmdsize field is the size in bytes | |
213 | * of the particular load command structure plus anything that follows it that | |
214 | * is a part of the load command (i.e. section structures, strings, etc.). To | |
215 | * advance to the next load command the cmdsize can be added to the offset or | |
91447636 A |
216 | * pointer of the current load command. The cmdsize for 32-bit architectures |
217 | * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple | |
218 | * of 8 bytes (these are forever the maximum alignment of any load commands). | |
1c79356b A |
219 | * The padded bytes must be zero. All tables in the object file must also |
220 | * follow these rules so the file can be memory mapped. Otherwise the pointers | |
221 | * to these tables will not work well or at all on some machines. With all | |
222 | * padding zeroed like objects will compare byte for byte. | |
223 | */ | |
224 | struct load_command { | |
2d21ac55 A |
225 | uint32_t cmd; /* type of load command */ |
226 | uint32_t cmdsize; /* total size of command in bytes */ | |
1c79356b A |
227 | }; |
228 | ||
2d21ac55 A |
229 | /* |
230 | * After MacOS X 10.1 when a new load command is added that is required to be | |
231 | * understood by the dynamic linker for the image to execute properly the | |
232 | * LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic | |
233 | * linker sees such a load command it it does not understand will issue a | |
234 | * "unknown load command required for execution" error and refuse to use the | |
235 | * image. Other load commands without this bit that are not understood will | |
236 | * simply be ignored. | |
237 | */ | |
238 | #define LC_REQ_DYLD 0x80000000 | |
239 | ||
1c79356b A |
240 | /* Constants for the cmd field of all load commands, the type */ |
241 | #define LC_SEGMENT 0x1 /* segment of this file to be mapped */ | |
242 | #define LC_SYMTAB 0x2 /* link-edit stab symbol table info */ | |
243 | #define LC_SYMSEG 0x3 /* link-edit gdb symbol table info (obsolete) */ | |
244 | #define LC_THREAD 0x4 /* thread */ | |
245 | #define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */ | |
246 | #define LC_LOADFVMLIB 0x6 /* load a specified fixed VM shared library */ | |
247 | #define LC_IDFVMLIB 0x7 /* fixed VM shared library identification */ | |
248 | #define LC_IDENT 0x8 /* object identification info (obsolete) */ | |
249 | #define LC_FVMFILE 0x9 /* fixed VM file inclusion (internal use) */ | |
250 | #define LC_PREPAGE 0xa /* prepage command (internal use) */ | |
251 | #define LC_DYSYMTAB 0xb /* dynamic link-edit symbol table info */ | |
2d21ac55 A |
252 | #define LC_LOAD_DYLIB 0xc /* load a dynamically linked shared library */ |
253 | #define LC_ID_DYLIB 0xd /* dynamically linked shared lib ident */ | |
1c79356b A |
254 | #define LC_LOAD_DYLINKER 0xe /* load a dynamic linker */ |
255 | #define LC_ID_DYLINKER 0xf /* dynamic linker identification */ | |
2d21ac55 | 256 | #define LC_PREBOUND_DYLIB 0x10 /* modules prebound for a dynamically */ |
1c79356b | 257 | /* linked shared library */ |
2d21ac55 A |
258 | #define LC_ROUTINES 0x11 /* image routines */ |
259 | #define LC_SUB_FRAMEWORK 0x12 /* sub framework */ | |
260 | #define LC_SUB_UMBRELLA 0x13 /* sub umbrella */ | |
261 | #define LC_SUB_CLIENT 0x14 /* sub client */ | |
262 | #define LC_SUB_LIBRARY 0x15 /* sub library */ | |
263 | #define LC_TWOLEVEL_HINTS 0x16 /* two-level namespace lookup hints */ | |
264 | #define LC_PREBIND_CKSUM 0x17 /* prebind checksum */ | |
265 | ||
266 | /* | |
267 | * load a dynamically linked shared library that is allowed to be missing | |
268 | * (all symbols are weak imported). | |
269 | */ | |
270 | #define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) | |
271 | ||
272 | #define LC_SEGMENT_64 0x19 /* 64-bit segment of this file to be | |
273 | mapped */ | |
274 | #define LC_ROUTINES_64 0x1a /* 64-bit image routines */ | |
275 | #define LC_UUID 0x1b /* the uuid */ | |
276 | #define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */ | |
277 | #define LC_CODE_SIGNATURE 0x1d /* local of code signature */ | |
278 | #define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */ | |
279 | #define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */ | |
593a1d5f A |
280 | #define LC_LAZY_LOAD_DYLIB 0x20 /* delay load of dylib until first use */ |
281 | #define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */ | |
b0d623f7 A |
282 | #define LC_DYLD_INFO 0x22 /* compressed dyld information */ |
283 | #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */ | |
1c79356b A |
284 | |
285 | /* | |
286 | * A variable length string in a load command is represented by an lc_str | |
287 | * union. The strings are stored just after the load command structure and | |
288 | * the offset is from the start of the load command structure. The size | |
289 | * of the string is reflected in the cmdsize field of the load command. | |
290 | * Once again any padded bytes to bring the cmdsize field to a multiple | |
2d21ac55 | 291 | * of 4 bytes must be zero. |
1c79356b A |
292 | */ |
293 | union lc_str { | |
2d21ac55 A |
294 | uint32_t offset; /* offset to the string */ |
295 | #ifndef __LP64__ | |
1c79356b | 296 | char *ptr; /* pointer to the string */ |
2d21ac55 | 297 | #endif |
1c79356b A |
298 | }; |
299 | ||
300 | /* | |
301 | * The segment load command indicates that a part of this file is to be | |
302 | * mapped into the task's address space. The size of this segment in memory, | |
303 | * vmsize, maybe equal to or larger than the amount to map from this file, | |
304 | * filesize. The file is mapped starting at fileoff to the beginning of | |
305 | * the segment in memory, vmaddr. The rest of the memory of the segment, | |
306 | * if any, is allocated zero fill on demand. The segment's maximum virtual | |
307 | * memory protection and initial virtual memory protection are specified | |
308 | * by the maxprot and initprot fields. If the segment has sections then the | |
309 | * section structures directly follow the segment command and their size is | |
310 | * reflected in cmdsize. | |
311 | */ | |
2d21ac55 A |
312 | struct segment_command { /* for 32-bit architectures */ |
313 | uint32_t cmd; /* LC_SEGMENT */ | |
314 | uint32_t cmdsize; /* includes sizeof section structs */ | |
1c79356b | 315 | char segname[16]; /* segment name */ |
2d21ac55 A |
316 | uint32_t vmaddr; /* memory address of this segment */ |
317 | uint32_t vmsize; /* memory size of this segment */ | |
318 | uint32_t fileoff; /* file offset of this segment */ | |
319 | uint32_t filesize; /* amount to map from the file */ | |
1c79356b A |
320 | vm_prot_t maxprot; /* maximum VM protection */ |
321 | vm_prot_t initprot; /* initial VM protection */ | |
2d21ac55 A |
322 | uint32_t nsects; /* number of sections in segment */ |
323 | uint32_t flags; /* flags */ | |
1c79356b A |
324 | }; |
325 | ||
91447636 A |
326 | /* |
327 | * The 64-bit segment load command indicates that a part of this file is to be | |
328 | * mapped into a 64-bit task's address space. If the 64-bit segment has | |
329 | * sections then section_64 structures directly follow the 64-bit segment | |
330 | * command and their size is reflected in cmdsize. | |
331 | */ | |
2d21ac55 | 332 | struct segment_command_64 { /* for 64-bit architectures */ |
91447636 A |
333 | uint32_t cmd; /* LC_SEGMENT_64 */ |
334 | uint32_t cmdsize; /* includes sizeof section_64 structs */ | |
335 | char segname[16]; /* segment name */ | |
336 | uint64_t vmaddr; /* memory address of this segment */ | |
337 | uint64_t vmsize; /* memory size of this segment */ | |
338 | uint64_t fileoff; /* file offset of this segment */ | |
339 | uint64_t filesize; /* amount to map from the file */ | |
340 | vm_prot_t maxprot; /* maximum VM protection */ | |
341 | vm_prot_t initprot; /* initial VM protection */ | |
342 | uint32_t nsects; /* number of sections in segment */ | |
343 | uint32_t flags; /* flags */ | |
344 | }; | |
345 | ||
1c79356b A |
346 | /* Constants for the flags field of the segment_command */ |
347 | #define SG_HIGHVM 0x1 /* the file contents for this segment is for | |
348 | the high part of the VM space, the low part | |
349 | is zero filled (for stacks in core files) */ | |
350 | #define SG_FVMLIB 0x2 /* this segment is the VM that is allocated by | |
351 | a fixed VM library, for overlap checking in | |
352 | the link editor */ | |
353 | #define SG_NORELOC 0x4 /* this segment has nothing that was relocated | |
354 | in it and nothing relocated to it, that is | |
355 | it maybe safely replaced without relocation*/ | |
2d21ac55 A |
356 | #define SG_PROTECTED_VERSION_1 0x8 /* This segment is protected. If the |
357 | segment starts at file offset 0, the | |
358 | first page of the segment is not | |
359 | protected. All other pages of the | |
360 | segment are protected. */ | |
1c79356b A |
361 | |
362 | /* | |
363 | * A segment is made up of zero or more sections. Non-MH_OBJECT files have | |
364 | * all of their segments with the proper sections in each, and padded to the | |
365 | * specified segment alignment when produced by the link editor. The first | |
366 | * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header | |
2d21ac55 | 367 | * and load commands of the object file before its first section. The zero |
1c79356b A |
368 | * fill sections are always last in their segment (in all formats). This |
369 | * allows the zeroed segment padding to be mapped into memory where zero fill | |
91447636 A |
370 | * sections might be. The gigabyte zero fill sections, those with the section |
371 | * type S_GB_ZEROFILL, can only be in a segment with sections of this type. | |
372 | * These segments are then placed after all other segments. | |
1c79356b | 373 | * |
2d21ac55 | 374 | * The MH_OBJECT format has all of its sections in one segment for |
1c79356b A |
375 | * compactness. There is no padding to a specified segment boundary and the |
376 | * mach_header and load commands are not part of the segment. | |
377 | * | |
378 | * Sections with the same section name, sectname, going into the same segment, | |
379 | * segname, are combined by the link editor. The resulting section is aligned | |
380 | * to the maximum alignment of the combined sections and is the new section's | |
381 | * alignment. The combined sections are aligned to their original alignment in | |
382 | * the combined section. Any padded bytes to get the specified alignment are | |
383 | * zeroed. | |
384 | * | |
385 | * The format of the relocation entries referenced by the reloff and nreloc | |
386 | * fields of the section structure for mach object files is described in the | |
387 | * header file <reloc.h>. | |
388 | */ | |
2d21ac55 | 389 | struct section { /* for 32-bit architectures */ |
1c79356b A |
390 | char sectname[16]; /* name of this section */ |
391 | char segname[16]; /* segment this section goes in */ | |
2d21ac55 A |
392 | uint32_t addr; /* memory address of this section */ |
393 | uint32_t size; /* size in bytes of this section */ | |
394 | uint32_t offset; /* file offset of this section */ | |
395 | uint32_t align; /* section alignment (power of 2) */ | |
396 | uint32_t reloff; /* file offset of relocation entries */ | |
397 | uint32_t nreloc; /* number of relocation entries */ | |
398 | uint32_t flags; /* flags (section type and attributes)*/ | |
399 | uint32_t reserved1; /* reserved (for offset or index) */ | |
400 | uint32_t reserved2; /* reserved (for count or sizeof) */ | |
1c79356b A |
401 | }; |
402 | ||
91447636 A |
403 | struct section_64 { /* for 64-bit architectures */ |
404 | char sectname[16]; /* name of this section */ | |
405 | char segname[16]; /* segment this section goes in */ | |
406 | uint64_t addr; /* memory address of this section */ | |
407 | uint64_t size; /* size in bytes of this section */ | |
408 | uint32_t offset; /* file offset of this section */ | |
409 | uint32_t align; /* section alignment (power of 2) */ | |
410 | uint32_t reloff; /* file offset of relocation entries */ | |
411 | uint32_t nreloc; /* number of relocation entries */ | |
412 | uint32_t flags; /* flags (section type and attributes)*/ | |
413 | uint32_t reserved1; /* reserved (for offset or index) */ | |
414 | uint32_t reserved2; /* reserved (for count or sizeof) */ | |
415 | uint32_t reserved3; /* reserved */ | |
416 | }; | |
417 | ||
1c79356b A |
418 | /* |
419 | * The flags field of a section structure is separated into two parts a section | |
420 | * type and section attributes. The section types are mutually exclusive (it | |
421 | * can only have one type) but the section attributes are not (it may have more | |
422 | * than one attribute). | |
423 | */ | |
424 | #define SECTION_TYPE 0x000000ff /* 256 section types */ | |
425 | #define SECTION_ATTRIBUTES 0xffffff00 /* 24 section attributes */ | |
426 | ||
427 | /* Constants for the type of a section */ | |
428 | #define S_REGULAR 0x0 /* regular section */ | |
429 | #define S_ZEROFILL 0x1 /* zero fill on demand section */ | |
430 | #define S_CSTRING_LITERALS 0x2 /* section with only literal C strings*/ | |
431 | #define S_4BYTE_LITERALS 0x3 /* section with only 4 byte literals */ | |
432 | #define S_8BYTE_LITERALS 0x4 /* section with only 8 byte literals */ | |
433 | #define S_LITERAL_POINTERS 0x5 /* section with only pointers to */ | |
434 | /* literals */ | |
435 | /* | |
436 | * For the two types of symbol pointers sections and the symbol stubs section | |
437 | * they have indirect symbol table entries. For each of the entries in the | |
438 | * section the indirect symbol table entries, in corresponding order in the | |
439 | * indirect symbol table, start at the index stored in the reserved1 field | |
440 | * of the section structure. Since the indirect symbol table entries | |
441 | * correspond to the entries in the section the number of indirect symbol table | |
442 | * entries is inferred from the size of the section divided by the size of the | |
443 | * entries in the section. For symbol pointers sections the size of the entries | |
444 | * in the section is 4 bytes and for symbol stubs sections the byte size of the | |
445 | * stubs is stored in the reserved2 field of the section structure. | |
446 | */ | |
447 | #define S_NON_LAZY_SYMBOL_POINTERS 0x6 /* section with only non-lazy | |
448 | symbol pointers */ | |
449 | #define S_LAZY_SYMBOL_POINTERS 0x7 /* section with only lazy symbol | |
450 | pointers */ | |
451 | #define S_SYMBOL_STUBS 0x8 /* section with only symbol | |
452 | stubs, byte size of stub in | |
453 | the reserved2 field */ | |
454 | #define S_MOD_INIT_FUNC_POINTERS 0x9 /* section with only function | |
455 | pointers for initialization*/ | |
2d21ac55 A |
456 | #define S_MOD_TERM_FUNC_POINTERS 0xa /* section with only function |
457 | pointers for termination */ | |
458 | #define S_COALESCED 0xb /* section contains symbols that | |
459 | are to be coalesced */ | |
460 | #define S_GB_ZEROFILL 0xc /* zero fill on demand section | |
461 | (that can be larger than 4 | |
462 | gigabytes) */ | |
463 | #define S_INTERPOSING 0xd /* section with only pairs of | |
464 | function pointers for | |
465 | interposing */ | |
593a1d5f A |
466 | #define S_16BYTE_LITERALS 0xe /* section with only 16 byte |
467 | literals */ | |
468 | #define S_DTRACE_DOF 0xf /* section contains | |
469 | DTrace Object Format */ | |
470 | #define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 /* section with only lazy | |
471 | symbol pointers to lazy | |
472 | loaded dylibs */ | |
1c79356b A |
473 | /* |
474 | * Constants for the section attributes part of the flags field of a section | |
475 | * structure. | |
476 | */ | |
477 | #define SECTION_ATTRIBUTES_USR 0xff000000 /* User setable attributes */ | |
478 | #define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section contains only true | |
479 | machine instructions */ | |
2d21ac55 A |
480 | #define S_ATTR_NO_TOC 0x40000000 /* section contains coalesced |
481 | symbols that are not to be | |
482 | in a ranlib table of | |
483 | contents */ | |
484 | #define S_ATTR_STRIP_STATIC_SYMS 0x20000000 /* ok to strip static symbols | |
485 | in this section in files | |
486 | with the MH_DYLDLINK flag */ | |
487 | #define S_ATTR_NO_DEAD_STRIP 0x10000000 /* no dead stripping */ | |
488 | #define S_ATTR_LIVE_SUPPORT 0x08000000 /* blocks are live if they | |
489 | reference live blocks */ | |
490 | #define S_ATTR_SELF_MODIFYING_CODE 0x04000000 /* Used with i386 code stubs | |
491 | written on by dyld */ | |
492 | /* | |
493 | * If a segment contains any sections marked with S_ATTR_DEBUG then all | |
494 | * sections in that segment must have this attribute. No section other than | |
495 | * a section marked with this attribute may reference the contents of this | |
496 | * section. A section with this attribute may contain no symbols and must have | |
497 | * a section type S_REGULAR. The static linker will not copy section contents | |
498 | * from sections with this attribute into its output file. These sections | |
499 | * generally contain DWARF debugging info. | |
500 | */ | |
501 | #define S_ATTR_DEBUG 0x02000000 /* a debug section */ | |
1c79356b A |
502 | #define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */ |
503 | #define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some | |
504 | machine instructions */ | |
505 | #define S_ATTR_EXT_RELOC 0x00000200 /* section has external | |
506 | relocation entries */ | |
507 | #define S_ATTR_LOC_RELOC 0x00000100 /* section has local | |
508 | relocation entries */ | |
509 | ||
510 | ||
511 | /* | |
512 | * The names of segments and sections in them are mostly meaningless to the | |
513 | * link-editor. But there are few things to support traditional UNIX | |
514 | * executables that require the link-editor and assembler to use some names | |
515 | * agreed upon by convention. | |
516 | * | |
517 | * The initial protection of the "__TEXT" segment has write protection turned | |
518 | * off (not writeable). | |
519 | * | |
520 | * The link-editor will allocate common symbols at the end of the "__common" | |
521 | * section in the "__DATA" segment. It will create the section and segment | |
522 | * if needed. | |
523 | */ | |
524 | ||
525 | /* The currently known segment names and the section names in those segments */ | |
526 | ||
527 | #define SEG_PAGEZERO "__PAGEZERO" /* the pagezero segment which has no */ | |
528 | /* protections and catches NULL */ | |
529 | /* references for MH_EXECUTE files */ | |
530 | ||
531 | ||
532 | #define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */ | |
533 | #define SECT_TEXT "__text" /* the real text part of the text */ | |
534 | /* section no headers, and no padding */ | |
535 | #define SECT_FVMLIB_INIT0 "__fvmlib_init0" /* the fvmlib initialization */ | |
536 | /* section */ | |
537 | #define SECT_FVMLIB_INIT1 "__fvmlib_init1" /* the section following the */ | |
538 | /* fvmlib initialization */ | |
539 | /* section */ | |
540 | ||
541 | #define SEG_DATA "__DATA" /* the tradition UNIX data segment */ | |
542 | #define SECT_DATA "__data" /* the real initialized data section */ | |
543 | /* no padding, no bss overlap */ | |
544 | #define SECT_BSS "__bss" /* the real uninitialized data section*/ | |
545 | /* no padding */ | |
546 | #define SECT_COMMON "__common" /* the section common symbols are */ | |
547 | /* allocated in by the link editor */ | |
548 | ||
549 | #define SEG_OBJC "__OBJC" /* objective-C runtime segment */ | |
550 | #define SECT_OBJC_SYMBOLS "__symbol_table" /* symbol table */ | |
551 | #define SECT_OBJC_MODULES "__module_info" /* module information */ | |
552 | #define SECT_OBJC_STRINGS "__selector_strs" /* string table */ | |
553 | #define SECT_OBJC_REFS "__selector_refs" /* string table */ | |
554 | ||
2d21ac55 | 555 | #define SEG_ICON "__ICON" /* the icon segment */ |
1c79356b A |
556 | #define SECT_ICON_HEADER "__header" /* the icon headers */ |
557 | #define SECT_ICON_TIFF "__tiff" /* the icons in tiff format */ | |
558 | ||
559 | #define SEG_LINKEDIT "__LINKEDIT" /* the segment containing all structs */ | |
560 | /* created and maintained by the link */ | |
561 | /* editor. Created with -seglinkedit */ | |
562 | /* option to ld(1) for MH_EXECUTE and */ | |
563 | /* FVMLIB file types only */ | |
564 | ||
565 | #define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */ | |
566 | ||
2d21ac55 A |
567 | #define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */ |
568 | /* modifing code stubs that has read, */ | |
569 | /* write and execute permissions */ | |
570 | ||
1c79356b A |
571 | /* |
572 | * Fixed virtual memory shared libraries are identified by two things. The | |
573 | * target pathname (the name of the library as found for execution), and the | |
574 | * minor version number. The address of where the headers are loaded is in | |
2d21ac55 | 575 | * header_addr. (THIS IS OBSOLETE and no longer supported). |
1c79356b A |
576 | */ |
577 | struct fvmlib { | |
578 | union lc_str name; /* library's target pathname */ | |
2d21ac55 A |
579 | uint32_t minor_version; /* library's minor version number */ |
580 | uint32_t header_addr; /* library's header address */ | |
1c79356b A |
581 | }; |
582 | ||
583 | /* | |
584 | * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header) | |
585 | * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library. | |
586 | * An object that uses a fixed virtual shared library also contains a | |
587 | * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses. | |
2d21ac55 | 588 | * (THIS IS OBSOLETE and no longer supported). |
1c79356b A |
589 | */ |
590 | struct fvmlib_command { | |
2d21ac55 A |
591 | uint32_t cmd; /* LC_IDFVMLIB or LC_LOADFVMLIB */ |
592 | uint32_t cmdsize; /* includes pathname string */ | |
1c79356b A |
593 | struct fvmlib fvmlib; /* the library identification */ |
594 | }; | |
595 | ||
596 | /* | |
597 | * Dynamicly linked shared libraries are identified by two things. The | |
598 | * pathname (the name of the library as found for execution), and the | |
599 | * compatibility version number. The pathname must match and the compatibility | |
600 | * number in the user of the library must be greater than or equal to the | |
601 | * library being used. The time stamp is used to record the time a library was | |
602 | * built and copied into user so it can be use to determined if the library used | |
603 | * at runtime is exactly the same as used to built the program. | |
604 | */ | |
605 | struct dylib { | |
606 | union lc_str name; /* library's path name */ | |
2d21ac55 A |
607 | uint32_t timestamp; /* library's build time stamp */ |
608 | uint32_t current_version; /* library's current version number */ | |
609 | uint32_t compatibility_version; /* library's compatibility vers number*/ | |
1c79356b A |
610 | }; |
611 | ||
612 | /* | |
2d21ac55 | 613 | * A dynamically linked shared library (filetype == MH_DYLIB in the mach header) |
1c79356b | 614 | * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library. |
2d21ac55 A |
615 | * An object that uses a dynamically linked shared library also contains a |
616 | * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or | |
617 | * LC_REEXPORT_DYLIB) for each library it uses. | |
1c79356b A |
618 | */ |
619 | struct dylib_command { | |
2d21ac55 A |
620 | uint32_t cmd; /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB, |
621 | LC_REEXPORT_DYLIB */ | |
622 | uint32_t cmdsize; /* includes pathname string */ | |
1c79356b A |
623 | struct dylib dylib; /* the library identification */ |
624 | }; | |
625 | ||
626 | /* | |
2d21ac55 A |
627 | * A dynamically linked shared library may be a subframework of an umbrella |
628 | * framework. If so it will be linked with "-umbrella umbrella_name" where | |
629 | * Where "umbrella_name" is the name of the umbrella framework. A subframework | |
630 | * can only be linked against by its umbrella framework or other subframeworks | |
631 | * that are part of the same umbrella framework. Otherwise the static link | |
632 | * editor produces an error and states to link against the umbrella framework. | |
633 | * The name of the umbrella framework for subframeworks is recorded in the | |
634 | * following structure. | |
635 | */ | |
636 | struct sub_framework_command { | |
637 | uint32_t cmd; /* LC_SUB_FRAMEWORK */ | |
638 | uint32_t cmdsize; /* includes umbrella string */ | |
639 | union lc_str umbrella; /* the umbrella framework name */ | |
640 | }; | |
641 | ||
642 | /* | |
643 | * For dynamically linked shared libraries that are subframework of an umbrella | |
644 | * framework they can allow clients other than the umbrella framework or other | |
645 | * subframeworks in the same umbrella framework. To do this the subframework | |
646 | * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load | |
647 | * command is created for each -allowable_client flag. The client_name is | |
648 | * usually a framework name. It can also be a name used for bundles clients | |
649 | * where the bundle is built with "-client_name client_name". | |
650 | */ | |
651 | struct sub_client_command { | |
652 | uint32_t cmd; /* LC_SUB_CLIENT */ | |
653 | uint32_t cmdsize; /* includes client string */ | |
654 | union lc_str client; /* the client name */ | |
655 | }; | |
656 | ||
657 | /* | |
658 | * A dynamically linked shared library may be a sub_umbrella of an umbrella | |
659 | * framework. If so it will be linked with "-sub_umbrella umbrella_name" where | |
660 | * Where "umbrella_name" is the name of the sub_umbrella framework. When | |
661 | * staticly linking when -twolevel_namespace is in effect a twolevel namespace | |
662 | * umbrella framework will only cause its subframeworks and those frameworks | |
663 | * listed as sub_umbrella frameworks to be implicited linked in. Any other | |
664 | * dependent dynamic libraries will not be linked it when -twolevel_namespace | |
665 | * is in effect. The primary library recorded by the static linker when | |
666 | * resolving a symbol in these libraries will be the umbrella framework. | |
667 | * Zero or more sub_umbrella frameworks may be use by an umbrella framework. | |
668 | * The name of a sub_umbrella framework is recorded in the following structure. | |
669 | */ | |
670 | struct sub_umbrella_command { | |
671 | uint32_t cmd; /* LC_SUB_UMBRELLA */ | |
672 | uint32_t cmdsize; /* includes sub_umbrella string */ | |
673 | union lc_str sub_umbrella; /* the sub_umbrella framework name */ | |
674 | }; | |
675 | ||
676 | /* | |
677 | * A dynamically linked shared library may be a sub_library of another shared | |
678 | * library. If so it will be linked with "-sub_library library_name" where | |
679 | * Where "library_name" is the name of the sub_library shared library. When | |
680 | * staticly linking when -twolevel_namespace is in effect a twolevel namespace | |
681 | * shared library will only cause its subframeworks and those frameworks | |
682 | * listed as sub_umbrella frameworks and libraries listed as sub_libraries to | |
683 | * be implicited linked in. Any other dependent dynamic libraries will not be | |
684 | * linked it when -twolevel_namespace is in effect. The primary library | |
685 | * recorded by the static linker when resolving a symbol in these libraries | |
686 | * will be the umbrella framework (or dynamic library). Zero or more sub_library | |
687 | * shared libraries may be use by an umbrella framework or (or dynamic library). | |
688 | * The name of a sub_library framework is recorded in the following structure. | |
689 | * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc". | |
690 | */ | |
691 | struct sub_library_command { | |
692 | uint32_t cmd; /* LC_SUB_LIBRARY */ | |
693 | uint32_t cmdsize; /* includes sub_library string */ | |
694 | union lc_str sub_library; /* the sub_library name */ | |
695 | }; | |
696 | ||
697 | /* | |
698 | * A program (filetype == MH_EXECUTE) that is | |
699 | * prebound to its dynamic libraries has one of these for each library that | |
1c79356b A |
700 | * the static linker used in prebinding. It contains a bit vector for the |
701 | * modules in the library. The bits indicate which modules are bound (1) and | |
702 | * which are not (0) from the library. The bit for module 0 is the low bit | |
703 | * of the first byte. So the bit for the Nth module is: | |
704 | * (linked_modules[N/8] >> N%8) & 1 | |
705 | */ | |
706 | struct prebound_dylib_command { | |
2d21ac55 A |
707 | uint32_t cmd; /* LC_PREBOUND_DYLIB */ |
708 | uint32_t cmdsize; /* includes strings */ | |
1c79356b | 709 | union lc_str name; /* library's path name */ |
2d21ac55 | 710 | uint32_t nmodules; /* number of modules in library */ |
1c79356b A |
711 | union lc_str linked_modules; /* bit vector of linked modules */ |
712 | }; | |
713 | ||
714 | /* | |
715 | * A program that uses a dynamic linker contains a dylinker_command to identify | |
716 | * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker | |
717 | * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER). | |
718 | * A file can have at most one of these. | |
719 | */ | |
720 | struct dylinker_command { | |
2d21ac55 A |
721 | uint32_t cmd; /* LC_ID_DYLINKER or LC_LOAD_DYLINKER */ |
722 | uint32_t cmdsize; /* includes pathname string */ | |
1c79356b A |
723 | union lc_str name; /* dynamic linker's path name */ |
724 | }; | |
725 | ||
726 | /* | |
727 | * Thread commands contain machine-specific data structures suitable for | |
728 | * use in the thread state primitives. The machine specific data structures | |
729 | * follow the struct thread_command as follows. | |
730 | * Each flavor of machine specific data structure is preceded by an unsigned | |
2d21ac55 | 731 | * long constant for the flavor of that data structure, an uint32_t |
1c79356b A |
732 | * that is the count of longs of the size of the state data structure and then |
733 | * the state data structure follows. This triple may be repeated for many | |
734 | * flavors. The constants for the flavors, counts and state data structure | |
735 | * definitions are expected to be in the header file <machine/thread_status.h>. | |
736 | * These machine specific data structures sizes must be multiples of | |
2d21ac55 | 737 | * 4 bytes The cmdsize reflects the total size of the thread_command |
1c79356b A |
738 | * and all of the sizes of the constants for the flavors, counts and state |
739 | * data structures. | |
740 | * | |
741 | * For executable objects that are unix processes there will be one | |
742 | * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor. | |
743 | * This is the same as a LC_THREAD, except that a stack is automatically | |
744 | * created (based on the shell's limit for the stack size). Command arguments | |
745 | * and environment variables are copied onto that stack. | |
746 | */ | |
747 | struct thread_command { | |
2d21ac55 A |
748 | uint32_t cmd; /* LC_THREAD or LC_UNIXTHREAD */ |
749 | uint32_t cmdsize; /* total size of this command */ | |
750 | /* uint32_t flavor flavor of thread state */ | |
751 | /* uint32_t count count of longs in thread state */ | |
1c79356b A |
752 | /* struct XXX_thread_state state thread state for this flavor */ |
753 | /* ... */ | |
754 | }; | |
755 | ||
2d21ac55 A |
756 | /* |
757 | * The routines command contains the address of the dynamic shared library | |
758 | * initialization routine and an index into the module table for the module | |
759 | * that defines the routine. Before any modules are used from the library the | |
760 | * dynamic linker fully binds the module that defines the initialization routine | |
761 | * and then calls it. This gets called before any module initialization | |
762 | * routines (used for C++ static constructors) in the library. | |
763 | */ | |
764 | struct routines_command { /* for 32-bit architectures */ | |
765 | uint32_t cmd; /* LC_ROUTINES */ | |
766 | uint32_t cmdsize; /* total size of this command */ | |
767 | uint32_t init_address; /* address of initialization routine */ | |
768 | uint32_t init_module; /* index into the module table that */ | |
769 | /* the init routine is defined in */ | |
770 | uint32_t reserved1; | |
771 | uint32_t reserved2; | |
772 | uint32_t reserved3; | |
773 | uint32_t reserved4; | |
774 | uint32_t reserved5; | |
775 | uint32_t reserved6; | |
776 | }; | |
777 | ||
778 | /* | |
779 | * The 64-bit routines command. Same use as above. | |
780 | */ | |
781 | struct routines_command_64 { /* for 64-bit architectures */ | |
782 | uint32_t cmd; /* LC_ROUTINES_64 */ | |
783 | uint32_t cmdsize; /* total size of this command */ | |
784 | uint64_t init_address; /* address of initialization routine */ | |
785 | uint64_t init_module; /* index into the module table that */ | |
786 | /* the init routine is defined in */ | |
787 | uint64_t reserved1; | |
788 | uint64_t reserved2; | |
789 | uint64_t reserved3; | |
790 | uint64_t reserved4; | |
791 | uint64_t reserved5; | |
792 | uint64_t reserved6; | |
793 | }; | |
794 | ||
1c79356b A |
795 | /* |
796 | * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD | |
797 | * "stab" style symbol table information as described in the header files | |
798 | * <nlist.h> and <stab.h>. | |
799 | */ | |
800 | struct symtab_command { | |
2d21ac55 A |
801 | uint32_t cmd; /* LC_SYMTAB */ |
802 | uint32_t cmdsize; /* sizeof(struct symtab_command) */ | |
803 | uint32_t symoff; /* symbol table offset */ | |
804 | uint32_t nsyms; /* number of symbol table entries */ | |
805 | uint32_t stroff; /* string table offset */ | |
806 | uint32_t strsize; /* string table size in bytes */ | |
1c79356b A |
807 | }; |
808 | ||
809 | /* | |
810 | * This is the second set of the symbolic information which is used to support | |
2d21ac55 | 811 | * the data structures for the dynamically link editor. |
1c79356b A |
812 | * |
813 | * The original set of symbolic information in the symtab_command which contains | |
814 | * the symbol and string tables must also be present when this load command is | |
815 | * present. When this load command is present the symbol table is organized | |
816 | * into three groups of symbols: | |
817 | * local symbols (static and debugging symbols) - grouped by module | |
818 | * defined external symbols - grouped by module (sorted by name if not lib) | |
2d21ac55 A |
819 | * undefined external symbols (sorted by name if MH_BINDATLOAD is not set, |
820 | * and in order the were seen by the static | |
821 | * linker if MH_BINDATLOAD is set) | |
1c79356b A |
822 | * In this load command there are offsets and counts to each of the three groups |
823 | * of symbols. | |
824 | * | |
825 | * This load command contains a the offsets and sizes of the following new | |
826 | * symbolic information tables: | |
827 | * table of contents | |
828 | * module table | |
829 | * reference symbol table | |
830 | * indirect symbol table | |
831 | * The first three tables above (the table of contents, module table and | |
2d21ac55 | 832 | * reference symbol table) are only present if the file is a dynamically linked |
1c79356b A |
833 | * shared library. For executable and object modules, which are files |
834 | * containing only one module, the information that would be in these three | |
835 | * tables is determined as follows: | |
836 | * table of contents - the defined external symbols are sorted by name | |
837 | * module table - the file contains only one module so everything in the | |
838 | * file is part of the module. | |
839 | * reference symbol table - is the defined and undefined external symbols | |
840 | * | |
2d21ac55 | 841 | * For dynamically linked shared library files this load command also contains |
1c79356b A |
842 | * offsets and sizes to the pool of relocation entries for all sections |
843 | * separated into two groups: | |
844 | * external relocation entries | |
845 | * local relocation entries | |
846 | * For executable and object modules the relocation entries continue to hang | |
847 | * off the section structures. | |
848 | */ | |
849 | struct dysymtab_command { | |
2d21ac55 A |
850 | uint32_t cmd; /* LC_DYSYMTAB */ |
851 | uint32_t cmdsize; /* sizeof(struct dysymtab_command) */ | |
1c79356b A |
852 | |
853 | /* | |
854 | * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command | |
855 | * are grouped into the following three groups: | |
856 | * local symbols (further grouped by the module they are from) | |
857 | * defined external symbols (further grouped by the module they are from) | |
858 | * undefined symbols | |
859 | * | |
860 | * The local symbols are used only for debugging. The dynamic binding | |
861 | * process may have to use them to indicate to the debugger the local | |
862 | * symbols for a module that is being bound. | |
863 | * | |
864 | * The last two groups are used by the dynamic binding process to do the | |
865 | * binding (indirectly through the module table and the reference symbol | |
2d21ac55 | 866 | * table when this is a dynamically linked shared library file). |
1c79356b | 867 | */ |
2d21ac55 A |
868 | uint32_t ilocalsym; /* index to local symbols */ |
869 | uint32_t nlocalsym; /* number of local symbols */ | |
1c79356b | 870 | |
2d21ac55 A |
871 | uint32_t iextdefsym;/* index to externally defined symbols */ |
872 | uint32_t nextdefsym;/* number of externally defined symbols */ | |
1c79356b | 873 | |
2d21ac55 A |
874 | uint32_t iundefsym; /* index to undefined symbols */ |
875 | uint32_t nundefsym; /* number of undefined symbols */ | |
1c79356b A |
876 | |
877 | /* | |
878 | * For the for the dynamic binding process to find which module a symbol | |
879 | * is defined in the table of contents is used (analogous to the ranlib | |
880 | * structure in an archive) which maps defined external symbols to modules | |
2d21ac55 | 881 | * they are defined in. This exists only in a dynamically linked shared |
1c79356b A |
882 | * library file. For executable and object modules the defined external |
883 | * symbols are sorted by name and is use as the table of contents. | |
884 | */ | |
2d21ac55 A |
885 | uint32_t tocoff; /* file offset to table of contents */ |
886 | uint32_t ntoc; /* number of entries in table of contents */ | |
1c79356b A |
887 | |
888 | /* | |
889 | * To support dynamic binding of "modules" (whole object files) the symbol | |
890 | * table must reflect the modules that the file was created from. This is | |
891 | * done by having a module table that has indexes and counts into the merged | |
892 | * tables for each module. The module structure that these two entries | |
2d21ac55 | 893 | * refer to is described below. This exists only in a dynamically linked |
1c79356b A |
894 | * shared library file. For executable and object modules the file only |
895 | * contains one module so everything in the file belongs to the module. | |
896 | */ | |
2d21ac55 A |
897 | uint32_t modtaboff; /* file offset to module table */ |
898 | uint32_t nmodtab; /* number of module table entries */ | |
1c79356b A |
899 | |
900 | /* | |
901 | * To support dynamic module binding the module structure for each module | |
902 | * indicates the external references (defined and undefined) each module | |
903 | * makes. For each module there is an offset and a count into the | |
904 | * reference symbol table for the symbols that the module references. | |
2d21ac55 | 905 | * This exists only in a dynamically linked shared library file. For |
1c79356b A |
906 | * executable and object modules the defined external symbols and the |
907 | * undefined external symbols indicates the external references. | |
908 | */ | |
2d21ac55 A |
909 | uint32_t extrefsymoff; /* offset to referenced symbol table */ |
910 | uint32_t nextrefsyms; /* number of referenced symbol table entries */ | |
1c79356b A |
911 | |
912 | /* | |
913 | * The sections that contain "symbol pointers" and "routine stubs" have | |
914 | * indexes and (implied counts based on the size of the section and fixed | |
915 | * size of the entry) into the "indirect symbol" table for each pointer | |
916 | * and stub. For every section of these two types the index into the | |
917 | * indirect symbol table is stored in the section header in the field | |
918 | * reserved1. An indirect symbol table entry is simply a 32bit index into | |
919 | * the symbol table to the symbol that the pointer or stub is referring to. | |
920 | * The indirect symbol table is ordered to match the entries in the section. | |
921 | */ | |
2d21ac55 A |
922 | uint32_t indirectsymoff; /* file offset to the indirect symbol table */ |
923 | uint32_t nindirectsyms; /* number of indirect symbol table entries */ | |
1c79356b A |
924 | |
925 | /* | |
926 | * To support relocating an individual module in a library file quickly the | |
927 | * external relocation entries for each module in the library need to be | |
928 | * accessed efficiently. Since the relocation entries can't be accessed | |
929 | * through the section headers for a library file they are separated into | |
930 | * groups of local and external entries further grouped by module. In this | |
931 | * case the presents of this load command who's extreloff, nextrel, | |
932 | * locreloff and nlocrel fields are non-zero indicates that the relocation | |
933 | * entries of non-merged sections are not referenced through the section | |
934 | * structures (and the reloff and nreloc fields in the section headers are | |
935 | * set to zero). | |
936 | * | |
937 | * Since the relocation entries are not accessed through the section headers | |
938 | * this requires the r_address field to be something other than a section | |
939 | * offset to identify the item to be relocated. In this case r_address is | |
940 | * set to the offset from the vmaddr of the first LC_SEGMENT command. | |
2d21ac55 A |
941 | * For MH_SPLIT_SEGS images r_address is set to the the offset from the |
942 | * vmaddr of the first read-write LC_SEGMENT command. | |
1c79356b A |
943 | * |
944 | * The relocation entries are grouped by module and the module table | |
945 | * entries have indexes and counts into them for the group of external | |
946 | * relocation entries for that the module. | |
947 | * | |
948 | * For sections that are merged across modules there must not be any | |
949 | * remaining external relocation entries for them (for merged sections | |
950 | * remaining relocation entries must be local). | |
951 | */ | |
2d21ac55 A |
952 | uint32_t extreloff; /* offset to external relocation entries */ |
953 | uint32_t nextrel; /* number of external relocation entries */ | |
1c79356b A |
954 | |
955 | /* | |
956 | * All the local relocation entries are grouped together (they are not | |
957 | * grouped by their module since they are only used if the object is moved | |
958 | * from it staticly link edited address). | |
959 | */ | |
2d21ac55 A |
960 | uint32_t locreloff; /* offset to local relocation entries */ |
961 | uint32_t nlocrel; /* number of local relocation entries */ | |
1c79356b A |
962 | |
963 | }; | |
964 | ||
965 | /* | |
966 | * An indirect symbol table entry is simply a 32bit index into the symbol table | |
967 | * to the symbol that the pointer or stub is refering to. Unless it is for a | |
968 | * non-lazy symbol pointer section for a defined symbol which strip(1) as | |
969 | * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the | |
970 | * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. | |
971 | */ | |
972 | #define INDIRECT_SYMBOL_LOCAL 0x80000000 | |
973 | #define INDIRECT_SYMBOL_ABS 0x40000000 | |
974 | ||
975 | ||
976 | /* a table of contents entry */ | |
977 | struct dylib_table_of_contents { | |
2d21ac55 | 978 | uint32_t symbol_index; /* the defined external symbol |
1c79356b | 979 | (index into the symbol table) */ |
2d21ac55 | 980 | uint32_t module_index; /* index into the module table this symbol |
1c79356b A |
981 | is defined in */ |
982 | }; | |
983 | ||
984 | /* a module table entry */ | |
985 | struct dylib_module { | |
2d21ac55 | 986 | uint32_t module_name; /* the module name (index into string table) */ |
1c79356b | 987 | |
2d21ac55 A |
988 | uint32_t iextdefsym; /* index into externally defined symbols */ |
989 | uint32_t nextdefsym; /* number of externally defined symbols */ | |
990 | uint32_t irefsym; /* index into reference symbol table */ | |
991 | uint32_t nrefsym; /* number of reference symbol table entries */ | |
992 | uint32_t ilocalsym; /* index into symbols for local symbols */ | |
993 | uint32_t nlocalsym; /* number of local symbols */ | |
1c79356b | 994 | |
2d21ac55 A |
995 | uint32_t iextrel; /* index into external relocation entries */ |
996 | uint32_t nextrel; /* number of external relocation entries */ | |
1c79356b | 997 | |
2d21ac55 A |
998 | uint32_t iinit_iterm; /* low 16 bits are the index into the init |
999 | section, high 16 bits are the index into | |
1000 | the term section */ | |
1001 | uint32_t ninit_nterm; /* low 16 bits are the number of init section | |
1002 | entries, high 16 bits are the number of | |
1003 | term section entries */ | |
1c79356b | 1004 | |
2d21ac55 | 1005 | uint32_t /* for this module address of the start of */ |
1c79356b | 1006 | objc_module_info_addr; /* the (__OBJC,__module_info) section */ |
2d21ac55 | 1007 | uint32_t /* for this module size of */ |
1c79356b A |
1008 | objc_module_info_size; /* the (__OBJC,__module_info) section */ |
1009 | }; | |
1010 | ||
91447636 A |
1011 | /* a 64-bit module table entry */ |
1012 | struct dylib_module_64 { | |
2d21ac55 | 1013 | uint32_t module_name; /* the module name (index into string table) */ |
91447636 | 1014 | |
2d21ac55 A |
1015 | uint32_t iextdefsym; /* index into externally defined symbols */ |
1016 | uint32_t nextdefsym; /* number of externally defined symbols */ | |
1017 | uint32_t irefsym; /* index into reference symbol table */ | |
1018 | uint32_t nrefsym; /* number of reference symbol table entries */ | |
1019 | uint32_t ilocalsym; /* index into symbols for local symbols */ | |
1020 | uint32_t nlocalsym; /* number of local symbols */ | |
91447636 | 1021 | |
2d21ac55 A |
1022 | uint32_t iextrel; /* index into external relocation entries */ |
1023 | uint32_t nextrel; /* number of external relocation entries */ | |
91447636 | 1024 | |
2d21ac55 | 1025 | uint32_t iinit_iterm; /* low 16 bits are the index into the init |
91447636 A |
1026 | section, high 16 bits are the index into |
1027 | the term section */ | |
2d21ac55 A |
1028 | uint32_t ninit_nterm; /* low 16 bits are the number of init section |
1029 | entries, high 16 bits are the number of | |
1030 | term section entries */ | |
1031 | ||
1032 | uint32_t /* for this module size of */ | |
1033 | objc_module_info_size; /* the (__OBJC,__module_info) section */ | |
1034 | uint64_t /* for this module address of the start of */ | |
1035 | objc_module_info_addr; /* the (__OBJC,__module_info) section */ | |
91447636 A |
1036 | }; |
1037 | ||
1c79356b A |
1038 | /* |
1039 | * The entries in the reference symbol table are used when loading the module | |
1040 | * (both by the static and dynamic link editors) and if the module is unloaded | |
1041 | * or replaced. Therefore all external symbols (defined and undefined) are | |
1042 | * listed in the module's reference table. The flags describe the type of | |
1043 | * reference that is being made. The constants for the flags are defined in | |
1044 | * <mach-o/nlist.h> as they are also used for symbol table entries. | |
1045 | */ | |
1046 | struct dylib_reference { | |
2d21ac55 | 1047 | uint32_t isym:24, /* index into the symbol table */ |
1c79356b A |
1048 | flags:8; /* flags to indicate the type of reference */ |
1049 | }; | |
1050 | ||
2d21ac55 A |
1051 | /* |
1052 | * The twolevel_hints_command contains the offset and number of hints in the | |
1053 | * two-level namespace lookup hints table. | |
1054 | */ | |
1055 | struct twolevel_hints_command { | |
1056 | uint32_t cmd; /* LC_TWOLEVEL_HINTS */ | |
1057 | uint32_t cmdsize; /* sizeof(struct twolevel_hints_command) */ | |
1058 | uint32_t offset; /* offset to the hint table */ | |
1059 | uint32_t nhints; /* number of hints in the hint table */ | |
1060 | }; | |
1061 | ||
1062 | /* | |
1063 | * The entries in the two-level namespace lookup hints table are twolevel_hint | |
1064 | * structs. These provide hints to the dynamic link editor where to start | |
1065 | * looking for an undefined symbol in a two-level namespace image. The | |
1066 | * isub_image field is an index into the sub-images (sub-frameworks and | |
1067 | * sub-umbrellas list) that made up the two-level image that the undefined | |
1068 | * symbol was found in when it was built by the static link editor. If | |
1069 | * isub-image is 0 the the symbol is expected to be defined in library and not | |
1070 | * in the sub-images. If isub-image is non-zero it is an index into the array | |
1071 | * of sub-images for the umbrella with the first index in the sub-images being | |
1072 | * 1. The array of sub-images is the ordered list of sub-images of the umbrella | |
1073 | * that would be searched for a symbol that has the umbrella recorded as its | |
1074 | * primary library. The table of contents index is an index into the | |
1075 | * library's table of contents. This is used as the starting point of the | |
1076 | * binary search or a directed linear search. | |
1077 | */ | |
1078 | struct twolevel_hint { | |
1079 | uint32_t | |
1080 | isub_image:8, /* index into the sub images */ | |
1081 | itoc:24; /* index into the table of contents */ | |
1082 | }; | |
1083 | ||
1084 | /* | |
1085 | * The prebind_cksum_command contains the value of the original check sum for | |
1086 | * prebound files or zero. When a prebound file is first created or modified | |
1087 | * for other than updating its prebinding information the value of the check sum | |
1088 | * is set to zero. When the file has it prebinding re-done and if the value of | |
1089 | * the check sum is zero the original check sum is calculated and stored in | |
1090 | * cksum field of this load command in the output file. If when the prebinding | |
1091 | * is re-done and the cksum field is non-zero it is left unchanged from the | |
1092 | * input file. | |
1093 | */ | |
1094 | struct prebind_cksum_command { | |
1095 | uint32_t cmd; /* LC_PREBIND_CKSUM */ | |
1096 | uint32_t cmdsize; /* sizeof(struct prebind_cksum_command) */ | |
1097 | uint32_t cksum; /* the check sum or zero */ | |
1098 | }; | |
1099 | ||
1100 | /* | |
1101 | * The uuid load command contains a single 128-bit unique random number that | |
1102 | * identifies an object produced by the static link editor. | |
1103 | */ | |
1104 | struct uuid_command { | |
1105 | uint32_t cmd; /* LC_UUID */ | |
1106 | uint32_t cmdsize; /* sizeof(struct uuid_command) */ | |
1107 | uint8_t uuid[16]; /* the 128-bit uuid */ | |
1108 | }; | |
1109 | ||
1110 | /* | |
1111 | * The rpath_command contains a path which at runtime should be added to | |
1112 | * the current run path used to find @rpath prefixed dylibs. | |
1113 | */ | |
1114 | struct rpath_command { | |
1115 | uint32_t cmd; /* LC_RPATH */ | |
1116 | uint32_t cmdsize; /* includes string */ | |
1117 | union lc_str path; /* path to add to run path */ | |
1118 | }; | |
1119 | ||
1120 | /* | |
1121 | * The linkedit_data_command contains the offsets and sizes of a blob | |
1122 | * of data in the __LINKEDIT segment. | |
1123 | */ | |
1124 | struct linkedit_data_command { | |
1125 | uint32_t cmd; /* LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO */ | |
1126 | uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */ | |
1127 | uint32_t dataoff; /* file offset of data in __LINKEDIT segment */ | |
1128 | uint32_t datasize; /* file size of data in __LINKEDIT segment */ | |
1129 | }; | |
1130 | ||
593a1d5f A |
1131 | /* |
1132 | * The encryption_info_command contains the file offset and size of an | |
1133 | * of an encrypted segment. | |
1134 | */ | |
1135 | struct encryption_info_command { | |
1136 | uint32_t cmd; /* LC_ENCRYPTION_INFO */ | |
1137 | uint32_t cmdsize; /* sizeof(struct encryption_info_command) */ | |
1138 | uint32_t cryptoff; /* file offset of encrypted range */ | |
1139 | uint32_t cryptsize; /* file size of encrypted range */ | |
1140 | uint32_t cryptid; /* which enryption system, | |
1141 | 0 means not-encrypted yet */ | |
1142 | }; | |
1143 | ||
b0d623f7 A |
1144 | /* |
1145 | * The dyld_info_command contains the file offsets and sizes of | |
1146 | * the new compressed form of the information dyld needs to | |
1147 | * load the image. This information is used by dyld on Mac OS X | |
1148 | * 10.6 and later. All information pointed to by this command | |
1149 | * is encoded using byte streams, so no endian swapping is needed | |
1150 | * to interpret it. | |
1151 | */ | |
1152 | struct dyld_info_command { | |
1153 | uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */ | |
1154 | uint32_t cmdsize; /* sizeof(struct dyld_info_command) */ | |
1155 | ||
1156 | /* | |
1157 | * Dyld rebases an image whenever dyld loads it at an address different | |
1158 | * from its preferred address. The rebase information is a stream | |
1159 | * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_. | |
1160 | * Conceptually the rebase information is a table of tuples: | |
1161 | * <seg-index, seg-offset, type> | |
1162 | * The opcodes are a compressed way to encode the table by only | |
1163 | * encoding when a column changes. In addition simple patterns | |
1164 | * like "every n'th offset for m times" can be encoded in a few | |
1165 | * bytes. | |
1166 | */ | |
1167 | uint32_t rebase_off; /* file offset to rebase info */ | |
1168 | uint32_t rebase_size; /* size of rebase info */ | |
1169 | ||
1170 | /* | |
1171 | * Dyld binds an image during the loading process, if the image | |
1172 | * requires any pointers to be initialized to symbols in other images. | |
1173 | * The rebase information is a stream of byte sized | |
1174 | * opcodes whose symbolic names start with BIND_OPCODE_. | |
1175 | * Conceptually the bind information is a table of tuples: | |
1176 | * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend> | |
1177 | * The opcodes are a compressed way to encode the table by only | |
1178 | * encoding when a column changes. In addition simple patterns | |
1179 | * like for runs of pointers initialzed to the same value can be | |
1180 | * encoded in a few bytes. | |
1181 | */ | |
1182 | uint32_t bind_off; /* file offset to binding info */ | |
1183 | uint32_t bind_size; /* size of binding info */ | |
1184 | ||
1185 | /* | |
1186 | * Some C++ programs require dyld to unique symbols so that all | |
1187 | * images in the process use the same copy of some code/data. | |
1188 | * This step is done after binding. The content of the weak_bind | |
1189 | * info is an opcode stream like the bind_info. But it is sorted | |
1190 | * alphabetically by symbol name. This enable dyld to walk | |
1191 | * all images with weak binding information in order and look | |
1192 | * for collisions. If there are no collisions, dyld does | |
1193 | * no updating. That means that some fixups are also encoded | |
1194 | * in the bind_info. For instance, all calls to "operator new" | |
1195 | * are first bound to libstdc++.dylib using the information | |
1196 | * in bind_info. Then if some image overrides operator new | |
1197 | * that is detected when the weak_bind information is processed | |
1198 | * and the call to operator new is then rebound. | |
1199 | */ | |
1200 | uint32_t weak_bind_off; /* file offset to weak binding info */ | |
1201 | uint32_t weak_bind_size; /* size of weak binding info */ | |
1202 | ||
1203 | /* | |
1204 | * Some uses of external symbols do not need to be bound immediately. | |
1205 | * Instead they can be lazily bound on first use. The lazy_bind | |
1206 | * are contains a stream of BIND opcodes to bind all lazy symbols. | |
1207 | * Normal use is that dyld ignores the lazy_bind section when | |
1208 | * loading an image. Instead the static linker arranged for the | |
1209 | * lazy pointer to initially point to a helper function which | |
1210 | * pushes the offset into the lazy_bind area for the symbol | |
1211 | * needing to be bound, then jumps to dyld which simply adds | |
1212 | * the offset to lazy_bind_off to get the information on what | |
1213 | * to bind. | |
1214 | */ | |
1215 | uint32_t lazy_bind_off; /* file offset to lazy binding info */ | |
1216 | uint32_t lazy_bind_size; /* size of lazy binding infs */ | |
1217 | ||
1218 | /* | |
1219 | * The symbols exported by a dylib are encoded in a trie. This | |
1220 | * is a compact representation that factors out common prefixes. | |
1221 | * It also reduces LINKEDIT pages in RAM because it encodes all | |
1222 | * information (name, address, flags) in one small, contiguous range. | |
1223 | * The export area is a stream of nodes. The first node sequentially | |
1224 | * is the start node for the trie. | |
1225 | * | |
1226 | * Nodes for a symbol start with a byte that is the length of | |
1227 | * the exported symbol information for the string so far. | |
1228 | * If there is no exported symbol, the byte is zero. If there | |
1229 | * is exported info, it follows the length byte. The exported | |
1230 | * info normally consists of a flags and offset both encoded | |
1231 | * in uleb128. The offset is location of the content named | |
1232 | * by the symbol. It is the offset from the mach_header for | |
1233 | * the image. | |
1234 | * | |
1235 | * After the initial byte and optional exported symbol information | |
1236 | * is a byte of how many edges (0-255) that this node has leaving | |
1237 | * it, followed by each edge. | |
1238 | * Each edge is a zero terminated cstring of the addition chars | |
1239 | * in the symbol, followed by a uleb128 offset for the node that | |
1240 | * edge points to. | |
1241 | * | |
1242 | */ | |
1243 | uint32_t export_off; /* file offset to lazy binding info */ | |
1244 | uint32_t export_size; /* size of lazy binding infs */ | |
1245 | }; | |
1246 | ||
1247 | /* | |
1248 | * The following are used to encode rebasing information | |
1249 | */ | |
1250 | #define REBASE_TYPE_POINTER 1 | |
1251 | #define REBASE_TYPE_TEXT_ABSOLUTE32 2 | |
1252 | #define REBASE_TYPE_TEXT_PCREL32 3 | |
1253 | ||
1254 | #define REBASE_OPCODE_MASK 0xF0 | |
1255 | #define REBASE_IMMEDIATE_MASK 0x0F | |
1256 | #define REBASE_OPCODE_DONE 0x00 | |
1257 | #define REBASE_OPCODE_SET_TYPE_IMM 0x10 | |
1258 | #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20 | |
1259 | #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30 | |
1260 | #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40 | |
1261 | #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50 | |
1262 | #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60 | |
1263 | #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70 | |
1264 | #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80 | |
1265 | ||
1266 | ||
1267 | /* | |
1268 | * The following are used to encode binding information | |
1269 | */ | |
1270 | #define BIND_TYPE_POINTER 1 | |
1271 | #define BIND_TYPE_TEXT_ABSOLUTE32 2 | |
1272 | #define BIND_TYPE_TEXT_PCREL32 3 | |
1273 | ||
1274 | #define BIND_SPECIAL_DYLIB_SELF 0 | |
1275 | #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1 | |
1276 | #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2 | |
1277 | ||
1278 | #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1 | |
1279 | #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8 | |
1280 | ||
1281 | #define BIND_OPCODE_MASK 0xF0 | |
1282 | #define BIND_IMMEDIATE_MASK 0x0F | |
1283 | #define BIND_OPCODE_DONE 0x00 | |
1284 | #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10 | |
1285 | #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20 | |
1286 | #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30 | |
1287 | #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40 | |
1288 | #define BIND_OPCODE_SET_TYPE_IMM 0x50 | |
1289 | #define BIND_OPCODE_SET_ADDEND_SLEB 0x60 | |
1290 | #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70 | |
1291 | #define BIND_OPCODE_ADD_ADDR_ULEB 0x80 | |
1292 | #define BIND_OPCODE_DO_BIND 0x90 | |
1293 | #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0 | |
1294 | #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0 | |
1295 | #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0 | |
1296 | ||
1297 | ||
1298 | /* | |
1299 | * The following are used on the flags byte of a terminal node | |
1300 | * in the export information. | |
1301 | */ | |
1302 | #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03 | |
1303 | #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00 | |
1304 | #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01 | |
1305 | #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04 | |
1306 | #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08 | |
1307 | #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10 | |
1308 | ||
1c79356b A |
1309 | /* |
1310 | * The symseg_command contains the offset and size of the GNU style | |
1311 | * symbol table information as described in the header file <symseg.h>. | |
1312 | * The symbol roots of the symbol segments must also be aligned properly | |
1313 | * in the file. So the requirement of keeping the offsets aligned to a | |
2d21ac55 | 1314 | * multiple of a 4 bytes translates to the length field of the symbol |
1c79356b A |
1315 | * roots also being a multiple of a long. Also the padding must again be |
1316 | * zeroed. (THIS IS OBSOLETE and no longer supported). | |
1317 | */ | |
1318 | struct symseg_command { | |
2d21ac55 A |
1319 | uint32_t cmd; /* LC_SYMSEG */ |
1320 | uint32_t cmdsize; /* sizeof(struct symseg_command) */ | |
1321 | uint32_t offset; /* symbol segment offset */ | |
1322 | uint32_t size; /* symbol segment size in bytes */ | |
1c79356b A |
1323 | }; |
1324 | ||
1325 | /* | |
1326 | * The ident_command contains a free format string table following the | |
1327 | * ident_command structure. The strings are null terminated and the size of | |
2d21ac55 | 1328 | * the command is padded out with zero bytes to a multiple of 4 bytes/ |
1c79356b A |
1329 | * (THIS IS OBSOLETE and no longer supported). |
1330 | */ | |
1331 | struct ident_command { | |
2d21ac55 A |
1332 | uint32_t cmd; /* LC_IDENT */ |
1333 | uint32_t cmdsize; /* strings that follow this command */ | |
1c79356b A |
1334 | }; |
1335 | ||
1336 | /* | |
1337 | * The fvmfile_command contains a reference to a file to be loaded at the | |
2d21ac55 | 1338 | * specified virtual address. (Presently, this command is reserved for |
1c79356b A |
1339 | * internal use. The kernel ignores this command when loading a program into |
1340 | * memory). | |
1341 | */ | |
1342 | struct fvmfile_command { | |
2d21ac55 A |
1343 | uint32_t cmd; /* LC_FVMFILE */ |
1344 | uint32_t cmdsize; /* includes pathname string */ | |
1c79356b | 1345 | union lc_str name; /* files pathname */ |
2d21ac55 | 1346 | uint32_t header_addr; /* files virtual address */ |
1c79356b A |
1347 | }; |
1348 | ||
55e303ae | 1349 | #endif /* _MACHO_LOADER_H_ */ |