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