VirtualBox

source: vbox/trunk/include/iprt/formats/mach-o.h@ 74844

Last change on this file since 74844 was 74844, checked in by vboxsync, 6 years ago

IPRT/ldr: Working on applying fixups to non-object Mach-O binaries. bugref:9232

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.4 KB
Line 
1/* $Id: mach-o.h 74844 2018-10-15 12:51:52Z vboxsync $ */
2/** @file
3 * IPRT - Mach-O Structures and Constants.
4 */
5
6/*
7 * Copyright (C) 2011-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___internal_ldrMach_O_h
28#define ___internal_ldrMach_O_h
29
30#include <iprt/types.h>
31#include <iprt/assertcompile.h>
32
33#ifndef CPU_ARCH_MASK
34
35/* cputype */
36#define CPU_ARCH_MASK INT32_C(0xff000000)
37#define CPU_ARCH_ABI64 INT32_C(0x01000000)
38#define CPU_TYPE_ANY INT32_C(-1)
39#define CPU_TYPE_VAX INT32_C(1)
40#define CPU_TYPE_MC680x0 INT32_C(6)
41#define CPU_TYPE_X86 INT32_C(7)
42#define CPU_TYPE_I386 CPU_TYPE_X86
43#define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
44#define CPU_TYPE_MC98000 INT32_C(10)
45#define CPU_TYPE_HPPA INT32_C(11)
46#define CPU_TYPE_MC88000 INT32_C(13)
47#define CPU_TYPE_SPARC INT32_C(14)
48#define CPU_TYPE_I860 INT32_C(15)
49#define CPU_TYPE_POWERPC INT32_C(18)
50#define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
51
52/* cpusubtype */
53#define CPU_SUBTYPE_MULTIPLE INT32_C(-1)
54#define CPU_SUBTYPE_LITTLE_ENDIAN INT32_C(0)
55#define CPU_SUBTYPE_BIG_ENDIAN INT32_C(1)
56
57#define CPU_SUBTYPE_VAX_ALL INT32_C(0)
58#define CPU_SUBTYPE_VAX780 INT32_C(1)
59#define CPU_SUBTYPE_VAX785 INT32_C(2)
60#define CPU_SUBTYPE_VAX750 INT32_C(3)
61#define CPU_SUBTYPE_VAX730 INT32_C(4)
62#define CPU_SUBTYPE_UVAXI INT32_C(5)
63#define CPU_SUBTYPE_UVAXII INT32_C(6)
64#define CPU_SUBTYPE_VAX8200 INT32_C(7)
65#define CPU_SUBTYPE_VAX8500 INT32_C(8)
66#define CPU_SUBTYPE_VAX8600 INT32_C(9)
67#define CPU_SUBTYPE_VAX8650 INT32_C(10)
68#define CPU_SUBTYPE_VAX8800 INT32_C(11)
69#define CPU_SUBTYPE_UVAXIII INT32_C(12)
70
71#define CPU_SUBTYPE_MC680x0_ALL INT32_C(1)
72#define CPU_SUBTYPE_MC68030 INT32_C(1)
73#define CPU_SUBTYPE_MC68040 INT32_C(2)
74#define CPU_SUBTYPE_MC68030_ONLY INT32_C(3)
75
76#define CPU_SUBTYPE_INTEL(fam, model) ( (int32_t )(((model) << 4) | (fam)) )
77#define CPU_SUBTYPE_INTEL_FAMILY(subtype) ( (subtype) & 0xf )
78#define CPU_SUBTYPE_INTEL_MODEL(subtype) ( (subtype) >> 4 )
79#define CPU_SUBTYPE_INTEL_FAMILY_MAX 0xf
80#define CPU_SUBTYPE_INTEL_MODEL_ALL 0
81
82#define CPU_SUBTYPE_I386_ALL CPU_SUBTYPE_INTEL(3, 0)
83#define CPU_SUBTYPE_386 CPU_SUBTYPE_INTEL(3, 0)
84#define CPU_SUBTYPE_486 CPU_SUBTYPE_INTEL(4, 0)
85#define CPU_SUBTYPE_486SX CPU_SUBTYPE_INTEL(4, 8)
86#define CPU_SUBTYPE_586 CPU_SUBTYPE_INTEL(5, 0)
87#define CPU_SUBTYPE_PENT CPU_SUBTYPE_INTEL(5, 0)
88#define CPU_SUBTYPE_PENTPRO CPU_SUBTYPE_INTEL(6, 1)
89#define CPU_SUBTYPE_PENTII_M3 CPU_SUBTYPE_INTEL(6, 3)
90#define CPU_SUBTYPE_PENTII_M5 CPU_SUBTYPE_INTEL(6, 5)
91#define CPU_SUBTYPE_CELERON CPU_SUBTYPE_INTEL(7, 6)
92#define CPU_SUBTYPE_CELERON_MOBILE CPU_SUBTYPE_INTEL(7, 7)
93#define CPU_SUBTYPE_PENTIUM_3 CPU_SUBTYPE_INTEL(8, 0)
94#define CPU_SUBTYPE_PENTIUM_3_M CPU_SUBTYPE_INTEL(8, 1)
95#define CPU_SUBTYPE_PENTIUM_3_XEON CPU_SUBTYPE_INTEL(8, 2)
96#define CPU_SUBTYPE_PENTIUM_M CPU_SUBTYPE_INTEL(9, 0)
97#define CPU_SUBTYPE_PENTIUM_4 CPU_SUBTYPE_INTEL(10, 0)
98#define CPU_SUBTYPE_PENTIUM_4_M CPU_SUBTYPE_INTEL(10, 1)
99#define CPU_SUBTYPE_ITANIUM CPU_SUBTYPE_INTEL(11, 0)
100#define CPU_SUBTYPE_ITANIUM_2 CPU_SUBTYPE_INTEL(11, 1)
101#define CPU_SUBTYPE_XEON CPU_SUBTYPE_INTEL(12, 0)
102#define CPU_SUBTYPE_XEON_MP CPU_SUBTYPE_INTEL(12, 1)
103
104#define CPU_SUBTYPE_X86_ALL INT32_C(3)
105#define CPU_SUBTYPE_X86_64_ALL INT32_C(3)
106#define CPU_SUBTYPE_X86_ARCH1 INT32_C(4)
107
108#define CPU_SUBTYPE_MIPS_ALL INT32_C(0)
109#define CPU_SUBTYPE_MIPS_R2300 INT32_C(1)
110#define CPU_SUBTYPE_MIPS_R2600 INT32_C(2)
111#define CPU_SUBTYPE_MIPS_R2800 INT32_C(3)
112#define CPU_SUBTYPE_MIPS_R2000a INT32_C(4)
113#define CPU_SUBTYPE_MIPS_R2000 INT32_C(5)
114#define CPU_SUBTYPE_MIPS_R3000a INT32_C(6)
115#define CPU_SUBTYPE_MIPS_R3000 INT32_C(7)
116
117#define CPU_SUBTYPE_MC98000_ALL INT32_C(0)
118#define CPU_SUBTYPE_MC98601 INT32_C(1)
119
120#define CPU_SUBTYPE_HPPA_ALL INT32_C(0)
121#define CPU_SUBTYPE_HPPA_7100 INT32_C(0)
122#define CPU_SUBTYPE_HPPA_7100LC INT32_C(1)
123
124#define CPU_SUBTYPE_MC88000_ALL INT32_C(0)
125#define CPU_SUBTYPE_MC88100 INT32_C(1)
126#define CPU_SUBTYPE_MC88110 INT32_C(2)
127
128#define CPU_SUBTYPE_SPARC_ALL INT32_C(0)
129
130#define CPU_SUBTYPE_I860_ALL INT32_C(0)
131#define CPU_SUBTYPE_I860_860 INT32_C(1)
132
133#define CPU_SUBTYPE_POWERPC_ALL INT32_C(0)
134#define CPU_SUBTYPE_POWERPC_601 INT32_C(1)
135#define CPU_SUBTYPE_POWERPC_602 INT32_C(2)
136#define CPU_SUBTYPE_POWERPC_603 INT32_C(3)
137#define CPU_SUBTYPE_POWERPC_603e INT32_C(4)
138#define CPU_SUBTYPE_POWERPC_603ev INT32_C(5)
139#define CPU_SUBTYPE_POWERPC_604 INT32_C(6)
140#define CPU_SUBTYPE_POWERPC_604e INT32_C(7)
141#define CPU_SUBTYPE_POWERPC_620 INT32_C(8)
142#define CPU_SUBTYPE_POWERPC_750 INT32_C(9)
143#define CPU_SUBTYPE_POWERPC_7400 INT32_C(10)
144#define CPU_SUBTYPE_POWERPC_7450 INT32_C(11)
145#define CPU_SUBTYPE_POWERPC_Max INT32_C(10)
146#define CPU_SUBTYPE_POWERPC_SCVger INT32_C(11)
147#define CPU_SUBTYPE_POWERPC_970 INT32_C(100)
148
149#define CPU_SUBTYPE_MASK UINT32_C(0xff000000)
150#define CPU_SUBTYPE_LIB64 UINT32_C(0x80000000)
151
152#endif /* !CPU_ARCH_MASK */
153
154
155typedef struct fat_header
156{
157 uint32_t magic;
158 uint32_t nfat_arch;
159} fat_header_t;
160
161#ifndef IMAGE_FAT_SIGNATURE
162# define IMAGE_FAT_SIGNATURE UINT32_C(0xcafebabe)
163#endif
164#ifndef IMAGE_FAT_SIGNATURE_OE
165# define IMAGE_FAT_SIGNATURE_OE UINT32_C(0xbebafeca)
166#endif
167
168typedef struct fat_arch
169{
170 int32_t cputype;
171 int32_t cpusubtype;
172 uint32_t offset;
173 uint32_t size;
174 uint32_t align;
175} fat_arch_t;
176
177typedef struct mach_header_32
178{
179 uint32_t magic;
180 int32_t cputype;
181 int32_t cpusubtype;
182 uint32_t filetype;
183 uint32_t ncmds;
184 uint32_t sizeofcmds;
185 uint32_t flags;
186} mach_header_32_t;
187
188/* magic */
189#ifndef IMAGE_MACHO32_SIGNATURE
190# define IMAGE_MACHO32_SIGNATURE UINT32_C(0xfeedface)
191#endif
192#ifndef IMAGE_MACHO32_SIGNATURE_OE
193# define IMAGE_MACHO32_SIGNATURE_OE UINT32_C(0xcefaedfe)
194#endif
195#define MH_MAGIC IMAGE_MACHO32_SIGNATURE
196#define MH_CIGAM IMAGE_MACHO32_SIGNATURE_OE
197
198typedef struct mach_header_64
199{
200 uint32_t magic;
201 int32_t cputype;
202 int32_t cpusubtype;
203 uint32_t filetype;
204 uint32_t ncmds;
205 uint32_t sizeofcmds;
206 uint32_t flags;
207 uint32_t reserved;
208} mach_header_64_t;
209
210/* magic */
211#ifndef IMAGE_MACHO64_SIGNATURE
212# define IMAGE_MACHO64_SIGNATURE UINT32_C(0xfeedfacf)
213#endif
214#ifndef IMAGE_MACHO64_SIGNATURE_OE
215# define IMAGE_MACHO64_SIGNATURE_OE UINT32_C(0xfefaedfe)
216#endif
217#define MH_MAGIC_64 IMAGE_MACHO64_SIGNATURE
218#define MH_CIGAM_64 IMAGE_MACHO64_SIGNATURE_OE
219
220/* mach_header_* filetype */
221#define MH_OBJECT UINT32_C(1)
222#define MH_EXECUTE UINT32_C(2)
223#define MH_FVMLIB UINT32_C(3)
224#define MH_CORE UINT32_C(4)
225#define MH_PRELOAD UINT32_C(5)
226#define MH_DYLIB UINT32_C(6)
227#define MH_DYLINKER UINT32_C(7)
228#define MH_BUNDLE UINT32_C(8)
229#define MH_DYLIB_STUB UINT32_C(9)
230#define MH_DSYM UINT32_C(10)
231#define MH_KEXT_BUNDLE UINT32_C(11)
232
233/* mach_header_* flags */
234#define MH_NOUNDEFS UINT32_C(0x00000001)
235#define MH_INCRLINK UINT32_C(0x00000002)
236#define MH_DYLDLINK UINT32_C(0x00000004)
237#define MH_BINDATLOAD UINT32_C(0x00000008)
238#define MH_PREBOUND UINT32_C(0x00000010)
239#define MH_SPLIT_SEGS UINT32_C(0x00000020)
240#define MH_LAZY_INIT UINT32_C(0x00000040)
241#define MH_TWOLEVEL UINT32_C(0x00000080)
242#define MH_FORCE_FLAT UINT32_C(0x00000100)
243#define MH_NOMULTIDEFS UINT32_C(0x00000200)
244#define MH_NOFIXPREBINDING UINT32_C(0x00000400)
245#define MH_PREBINDABLE UINT32_C(0x00000800)
246#define MH_ALLMODSBOUND UINT32_C(0x00001000)
247#define MH_SUBSECTIONS_VIA_SYMBOLS UINT32_C(0x00002000)
248#define MH_CANONICAL UINT32_C(0x00004000)
249#define MH_WEAK_DEFINES UINT32_C(0x00008000)
250#define MH_BINDS_TO_WEAK UINT32_C(0x00010000)
251#define MH_ALLOW_STACK_EXECUTION UINT32_C(0x00020000)
252#define MH_ROOT_SAFE UINT32_C(0x00040000)
253#define MH_SETUID_SAFE UINT32_C(0x00080000)
254#define MH_NO_REEXPORTED_DYLIBS UINT32_C(0x00100000)
255#define MH_PIE UINT32_C(0x00200000)
256#define MH_DEAD_STRIPPABLE_DYLIB UINT32_C(0x00400000)
257#define MH_HAS_TLV_DESCRIPTORS UINT32_C(0x00800000)
258#define MH_NO_HEAP_EXECUTION UINT32_C(0x01000000)
259#define MH_VALID_FLAGS UINT32_C(0x01ffffff)
260
261
262typedef struct load_command
263{
264 uint32_t cmd;
265 uint32_t cmdsize;
266} load_command_t;
267
268/* load cmd */
269#define LC_REQ_DYLD UINT32_C(0x80000000)
270#define LC_SEGMENT_32 UINT32_C(0x01)
271#define LC_SYMTAB UINT32_C(0x02)
272#define LC_SYMSEG UINT32_C(0x03)
273#define LC_THREAD UINT32_C(0x04)
274#define LC_UNIXTHREAD UINT32_C(0x05)
275#define LC_LOADFVMLIB UINT32_C(0x06)
276#define LC_IDFVMLIB UINT32_C(0x07)
277#define LC_IDENT UINT32_C(0x08)
278#define LC_FVMFILE UINT32_C(0x09)
279#define LC_PREPAGE UINT32_C(0x0a)
280#define LC_DYSYMTAB UINT32_C(0x0b)
281#define LC_LOAD_DYLIB UINT32_C(0x0c)
282#define LC_ID_DYLIB UINT32_C(0x0d)
283#define LC_LOAD_DYLINKER UINT32_C(0x0e)
284#define LC_ID_DYLINKER UINT32_C(0x0f)
285#define LC_PREBOUND_DYLIB UINT32_C(0x10)
286#define LC_ROUTINES UINT32_C(0x11)
287#define LC_SUB_FRAMEWORK UINT32_C(0x12)
288#define LC_SUB_UMBRELLA UINT32_C(0x13)
289#define LC_SUB_CLIENT UINT32_C(0x14)
290#define LC_SUB_LIBRARY UINT32_C(0x15)
291#define LC_TWOLEVEL_HINTS UINT32_C(0x16)
292#define LC_PREBIND_CKSUM UINT32_C(0x17)
293#define LC_LOAD_WEAK_DYLIB (UINT32_C(0x18) | LC_REQ_DYLD)
294#define LC_SEGMENT_64 UINT32_C(0x19)
295#define LC_ROUTINES_64 UINT32_C(0x1a)
296#define LC_UUID UINT32_C(0x1b)
297#define LC_RPATH (UINT32_C(0x1c) | LC_REQ_DYLD)
298#define LC_CODE_SIGNATURE UINT32_C(0x1d)
299#define LC_SEGMENT_SPLIT_INFO UINT32_C(0x1e)
300#define LC_REEXPORT_DYLIB (UINT32_C(0x1f) | LC_REQ_DYLD)
301#define LC_LAZY_LOAD_DYLIB UINT32_C(0x20)
302#define LC_ENCRYPTION_INFO UINT32_C(0x21)
303#define LC_DYLD_INFO UINT32_C(0x22)
304#define LC_DYLD_INFO_ONLY (UINT32_C(0x22) | LC_REQ_DYLD)
305#define LC_LOAD_UPWARD_DYLIB (UINT32_C(0x23) | LC_REQ_DYLD)
306#define LC_VERSION_MIN_MACOSX UINT32_C(0x24)
307#define LC_VERSION_MIN_IPHONEOS UINT32_C(0x25)
308#define LC_FUNCTION_STARTS UINT32_C(0x26)
309#define LC_DYLD_ENVIRONMENT UINT32_C(0x27)
310#define LC_MAIN (UINT32_C(0x28) | LC_REQ_DYLD)
311#define LC_DATA_IN_CODE UINT32_C(0x29)
312#define LC_SOURCE_VERSION UINT32_C(0x2a)
313#define LC_DYLIB_CODE_SIGN_DRS UINT32_C(0x2b)
314#define LC_ENCRYPTION_INFO_64 UINT32_C(0x2c)
315#define LC_LINKER_OPTION UINT32_C(0x2d)
316#define LC_LINKER_OPTIMIZATION_HINT UINT32_C(0x2e)
317#define LC_VERSION_MIN_TVOS UINT32_C(0x2f)
318#define LC_VERSION_MIN_WATCHOS UINT32_C(0x30)
319#define LC_NOTE UINT32_C(0x31)
320#define LC_BUILD_VERSION UINT32_C(0x32)
321
322
323typedef struct lc_str
324{
325 uint32_t offset;
326} lc_str_t;
327
328typedef struct segment_command_32
329{
330 uint32_t cmd;
331 uint32_t cmdsize;
332 char segname[16];
333 uint32_t vmaddr;
334 uint32_t vmsize;
335 uint32_t fileoff;
336 uint32_t filesize;
337 uint32_t maxprot;
338 uint32_t initprot;
339 uint32_t nsects;
340 uint32_t flags;
341} segment_command_32_t;
342
343typedef struct segment_command_64
344{
345 uint32_t cmd;
346 uint32_t cmdsize;
347 char segname[16];
348 uint64_t vmaddr;
349 uint64_t vmsize;
350 uint64_t fileoff;
351 uint64_t filesize;
352 uint32_t maxprot;
353 uint32_t initprot;
354 uint32_t nsects;
355 uint32_t flags;
356} segment_command_64_t;
357
358/* segment flags */
359#define SG_HIGHVM UINT32_C(0x00000001)
360#define SG_FVMLIB UINT32_C(0x00000002)
361#define SG_NORELOC UINT32_C(0x00000004)
362#define SG_PROTECTED_VERSION_1 UINT32_C(0x00000008)
363
364/* maxprot/initprot */
365#ifndef VM_PROT_NONE
366# define VM_PROT_NONE UINT32_C(0x00000000)
367# define VM_PROT_READ UINT32_C(0x00000001)
368# define VM_PROT_WRITE UINT32_C(0x00000002)
369# define VM_PROT_EXECUTE UINT32_C(0x00000004)
370# define VM_PROT_ALL UINT32_C(0x00000007)
371#endif
372
373typedef struct section_32
374{
375 char sectname[16];
376 char segname[16];
377 uint32_t addr;
378 uint32_t size;
379 uint32_t offset;
380 uint32_t align;
381 uint32_t reloff;
382 uint32_t nreloc;
383 uint32_t flags;
384 /** For S_LAZY_SYMBOL_POINTERS, S_NON_LAZY_SYMBOL_POINTERS and S_SYMBOL_STUBS
385 * this is the index into the indirect symbol table. */
386 uint32_t reserved1;
387 /** For S_SYMBOL_STUBS this is the entry size. */
388 uint32_t reserved2;
389} section_32_t;
390
391typedef struct section_64
392{
393 char sectname[16];
394 char segname[16];
395 uint64_t addr;
396 uint64_t size;
397 uint32_t offset;
398 uint32_t align;
399 uint32_t reloff;
400 uint32_t nreloc;
401 uint32_t flags;
402 /** For S_LAZY_SYMBOL_POINTERS, S_NON_LAZY_SYMBOL_POINTERS and S_SYMBOL_STUBS
403 * this is the index into the indirect symbol table. */
404 uint32_t reserved1;
405 uint32_t reserved2;
406 uint32_t reserved3;
407} section_64_t;
408
409/* section flags */
410#define SECTION_TYPE UINT32_C(0xff)
411#define S_REGULAR UINT32_C(0x00)
412#define S_ZEROFILL UINT32_C(0x01)
413#define S_CSTRING_LITERALS UINT32_C(0x02)
414#define S_4BYTE_LITERALS UINT32_C(0x03)
415#define S_8BYTE_LITERALS UINT32_C(0x04)
416#define S_LITERAL_POINTERS UINT32_C(0x05)
417#define S_NON_LAZY_SYMBOL_POINTERS UINT32_C(0x06)
418#define S_LAZY_SYMBOL_POINTERS UINT32_C(0x07)
419#define S_SYMBOL_STUBS UINT32_C(0x08)
420#define S_MOD_INIT_FUNC_POINTERS UINT32_C(0x09)
421#define S_MOD_TERM_FUNC_POINTERS UINT32_C(0x0a)
422#define S_COALESCED UINT32_C(0x0b)
423#define S_GB_ZEROFILL UINT32_C(0x0c)
424#define S_INTERPOSING UINT32_C(0x0d)
425#define S_16BYTE_LITERALS UINT32_C(0x0e)
426#define S_DTRACE_DOF UINT32_C(0x0f)
427#define S_LAZY_DYLIB_SYMBOL_POINTERS UINT32_C(0x10)
428#define S_THREAD_LOCAL_REGULAR UINT32_C(0x11)
429#define S_THREAD_LOCAL_ZEROFILL UINT32_C(0x12)
430#define S_THREAD_LOCAL_VARIABLES UINT32_C(0x13)
431#define S_THREAD_LOCAL_VARIABLE_POINTERS UINT32_C(0x14)
432#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS UINT32_C(0x15)
433
434
435
436
437#define SECTION_ATTRIBUTES UINT32_C(0xffffff00)
438#define SECTION_ATTRIBUTES_USR UINT32_C(0xff000000)
439#define S_ATTR_PURE_INSTRUCTIONS UINT32_C(0x80000000)
440#define S_ATTR_NO_TOC UINT32_C(0x40000000)
441#define S_ATTR_STRIP_STATIC_SYMS UINT32_C(0x20000000)
442#define S_ATTR_NO_DEAD_STRIP UINT32_C(0x10000000)
443#define S_ATTR_LIVE_SUPPORT UINT32_C(0x08000000)
444#define S_ATTR_SELF_MODIFYING_CODE UINT32_C(0x04000000)
445#define S_ATTR_DEBUG UINT32_C(0x02000000)
446#define SECTION_ATTRIBUTES_SYS UINT32_C(0x00ffff00)
447#define S_ATTR_SOME_INSTRUCTIONS UINT32_C(0x00000400)
448#define S_ATTR_EXT_RELOC UINT32_C(0x00000200)
449#define S_ATTR_LOC_RELOC UINT32_C(0x00000100)
450
451/* standard section names */
452#define SEG_PAGEZERO "__PAGEZERO"
453#define SEG_TEXT "__TEXT"
454#define SECT_TEXT "__text"
455#define SECT_FVMLIB_INIT0 "__fvmlib_init0"
456#define SECT_FVMLIB_INIT1 "__fvmlib_init1"
457#define SEG_DATA "__DATA"
458#define SECT_DATA "__data"
459#define SECT_BSS "__bss"
460#define SECT_COMMON "__common"
461#define SEG_OBJC "__OBJC"
462#define SECT_OBJC_SYMBOLS "__symbol_table"
463#define SECT_OBJC_MODULES "__module_info"
464#define SECT_OBJC_STRINGS "__selector_strs"
465#define SECT_OBJC_REFS "__selector_refs"
466#define SEG_ICON "__ICON"
467#define SECT_ICON_HEADER "__header"
468#define SECT_ICON_TIFF "__tiff"
469#define SEG_LINKEDIT "__LINKEDIT"
470#define SEG_UNIXSTACK "__UNIXSTACK"
471#define SEG_IMPORT "__IMPORT"
472
473typedef struct thread_command
474{
475 uint32_t cmd;
476 uint32_t cmdsize;
477} thread_command_t;
478
479typedef struct symtab_command
480{
481 uint32_t cmd;
482 uint32_t cmdsize;
483 uint32_t symoff;
484 uint32_t nsyms;
485 uint32_t stroff;
486 uint32_t strsize;
487} symtab_command_t;
488
489typedef struct dysymtab_command
490{
491 uint32_t cmd;
492 uint32_t cmdsize;
493 /** @name Symbol groupings.
494 * @{ */
495 uint32_t ilocalsym; /**< Index into the symbol table of the first local symbol. */
496 uint32_t nlocalsym; /**< Number of local symbols. */
497 uint32_t iextdefsym; /**< Index into the symbol table of the first externally defined symbol. */
498 uint32_t nextdefsym; /**< Number of externally defined symbols. */
499 uint32_t iundefsym; /**< Index into the symbol table of the first undefined symbol. */
500 uint32_t nundefsym; /**< Number of undefined symbols. */
501 /** @} */
502 uint32_t tocoff; /**< Table of content file offset. (usually empty) */
503 uint32_t ntoc; /**< Number of entries in TOC. */
504 uint32_t modtaboff; /** The module table file offset. (usually empty) */
505 uint32_t nmodtab; /**< Number of entries in the module table. */
506 /** @name Dynamic symbol tables.
507 * @{ */
508 uint32_t extrefsymoff; /**< Externally referenceable symbol table file offset. @sa dylib_reference_t */
509 uint32_t nextrefsym; /**< Number externally referenceable symbols. */
510 uint32_t indirectsymboff; /**< Indirect symbol table (32-bit symtab indexes) for thunks and offset tables. */
511 uint32_t nindirectsymb; /**< Number of indirect symbol table entries. */
512 /** @} */
513 /** @name Relocations.
514 * @{ */
515 uint32_t extreloff; /**< External relocations (r_address is relative to first segment (i.e. RVA)). */
516 uint32_t nextrel; /**< Number of external relocations. */
517 uint32_t locreloff; /**< Local relocations (r_address is relative to first segment (i.e. RVA)). */
518 uint32_t nlocrel; /**< Number of local relocations. */
519 /** @} */
520} dysymtab_command_t;
521AssertCompileSize(dysymtab_command_t, 80);
522
523/** Special indirect symbol table entry value, stripped local symbol. */
524#define INDIRECT_SYMBOL_LOCAL UINT32_C(0x80000000)
525/** Special indirect symbol table entry value, stripped absolute symbol. */
526#define INDIRECT_SYMBOL_ABS UINT32_C(0x40000000)
527
528typedef struct dylib_reference
529{
530 uint32_t isym : 24; /**< Symbol table index. */
531 uint32_t flags : 8; /**< REFERENCE_FLAG_XXX? */
532} dylib_reference_t;
533AssertCompileSize(dylib_reference_t, 4);
534
535
536typedef struct dylib_table_of_contents
537{
538 uint32_t symbol_index; /**< External symbol table entry. */
539 uint32_t module_index; /**< The module table index of the module defining it. */
540} dylib_table_of_contents_t;
541AssertCompileSize(dylib_table_of_contents_t, 8);
542
543
544/** 32-bit module table entry. */
545typedef struct dylib_module
546{
547 uint32_t module_name;
548 uint32_t iextdefsym;
549 uint32_t nextdefsym;
550 uint32_t irefsym;
551 uint32_t nrefsym;
552 uint32_t ilocalsym;
553 uint32_t nlocalsym;
554 uint32_t iextrel;
555 uint32_t nextrel;
556 uint32_t iinit_iterm;
557 uint32_t ninit_nterm;
558 uint32_t objc_module_info_addr;
559 uint32_t objc_module_info_size;
560} dylib_module_32_t;
561AssertCompileSize(dylib_module_32_t, 13*4);
562
563/* a 64-bit module table entry */
564typedef struct dylib_module_64
565{
566 uint32_t module_name;
567 uint32_t iextdefsym;
568 uint32_t nextdefsym;
569 uint32_t irefsym;
570 uint32_t nrefsym;
571 uint32_t ilocalsym;
572 uint32_t nlocalsym;
573 uint32_t iextrel;
574 uint32_t nextrel;
575 uint32_t iinit_iterm;
576 uint32_t ninit_nterm;
577 uint32_t objc_module_info_size;
578 uint64_t objc_module_info_addr;
579} dylib_module_64_t;
580AssertCompileSize(dylib_module_64_t, 12*4+8);
581
582typedef struct uuid_command
583{
584 uint32_t cmd;
585 uint32_t cmdsize;
586 uint8_t uuid[16];
587} uuid_command_t;
588AssertCompileSize(uuid_command_t, 24);
589
590typedef struct linkedit_data_command
591{
592 uint32_t cmd; /**< LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS */
593 uint32_t cmdsize; /**< Size of this structure. */
594 uint32_t dataoff; /**< Offset into the file of the data. */
595 uint32_t datasize; /**< The size of the data. */
596} linkedit_data_command_t;
597AssertCompileSize(linkedit_data_command_t, 16);
598
599typedef struct version_min_command
600{
601 uint32_t cmd; /**< LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS */
602 uint32_t cmdsize; /**< Size of this structure. */
603 uint32_t version; /**< 31..16=major, 15..8=minor, 7..0=patch. */
604 uint32_t reserved; /**< MBZ. */
605} version_min_command_t;
606AssertCompileSize(version_min_command_t, 16);
607
608typedef struct macho_nlist_32
609{
610 union
611 {
612 int32_t n_strx;
613 } n_un;
614 uint8_t n_type;
615 uint8_t n_sect;
616 int16_t n_desc;
617 uint32_t n_value;
618} macho_nlist_32_t;
619
620
621typedef struct macho_nlist_64
622{
623 union
624 {
625 uint32_t n_strx;
626 } n_un;
627 uint8_t n_type;
628 uint8_t n_sect;
629 int16_t n_desc;
630 uint64_t n_value;
631} macho_nlist_64_t;
632
633#define MACHO_N_EXT UINT8_C(0x01)
634#define MACHO_N_PEXT UINT8_C(0x10)
635
636#define MACHO_N_TYPE UINT8_C(0x0e)
637#define MACHO_N_UNDF UINT8_C(0x00)
638#define MACHO_N_ABS UINT8_C(0x02)
639#define MACHO_N_INDR UINT8_C(0x0a)
640#define MACHO_N_PBUD UINT8_C(0x0c)
641#define MACHO_N_SECT UINT8_C(0x0e)
642
643#define MACHO_N_STAB UINT8_C(0xe0)
644#define MACHO_N_GSYM UINT8_C(0x20)
645#define MACHO_N_FNAME UINT8_C(0x22)
646#define MACHO_N_FUN UINT8_C(0x24)
647#define MACHO_N_STSYM UINT8_C(0x26)
648#define MACHO_N_LCSYM UINT8_C(0x28)
649#define MACHO_N_BNSYM UINT8_C(0x2e)
650#define MACHO_N_PC UINT8_C(0x30)
651#define MACHO_N_OPT UINT8_C(0x3c)
652#define MACHO_N_RSYM UINT8_C(0x40)
653#define MACHO_N_SLINE UINT8_C(0x44)
654#define MACHO_N_ENSYM UINT8_C(0x4e)
655#define MACHO_N_SSYM UINT8_C(0x60)
656#define MACHO_N_SO UINT8_C(0x64)
657#define MACHO_N_OSO UINT8_C(0x66)
658#define MACHO_N_LSYM UINT8_C(0x80)
659#define MACHO_N_BINCL UINT8_C(0x82)
660#define MACHO_N_SOL UINT8_C(0x84)
661#define MACHO_N_PARAMS UINT8_C(0x86)
662#define MACHO_N_VERSION UINT8_C(0x88)
663#define MACHO_N_OLEVEL UINT8_C(0x8A)
664#define MACHO_N_PSYM UINT8_C(0xa0)
665#define MACHO_N_EINCL UINT8_C(0xa2)
666#define MACHO_N_ENTRY UINT8_C(0xa4)
667#define MACHO_N_LBRAC UINT8_C(0xc0)
668#define MACHO_N_EXCL UINT8_C(0xc2)
669#define MACHO_N_RBRAC UINT8_C(0xe0)
670#define MACHO_N_BCOMM UINT8_C(0xe2)
671#define MACHO_N_ECOMM UINT8_C(0xe4)
672#define MACHO_N_ECOML UINT8_C(0xe8)
673#define MACHO_N_LENG UINT8_C(0xfe)
674
675#define MACHO_NO_SECT UINT8_C(0x00)
676#define MACHO_MAX_SECT UINT8_C(0xff)
677
678#define REFERENCE_TYPE UINT16_C(0x000f)
679#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
680#define REFERENCE_FLAG_UNDEFINED_LAZY 1
681#define REFERENCE_FLAG_DEFINED 2
682#define REFERENCE_FLAG_PRIVATE_DEFINED 3
683#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
684#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
685#define REFERENCED_DYNAMICALLY UINT16_C(0x0010)
686
687#define GET_LIBRARY_ORDINAL(a_n_desc) \
688 RT_BYTE2(a_n_desc)
689#define SET_LIBRARY_ORDINAL(a_n_desc, a_ordinal) \
690 do { (a_n_desc) = RT_MAKE_U16(RT_BYTE1(a_n_desc), a_ordinal); } while (0)
691
692#define SELF_LIBRARY_ORDINAL 0x00
693#define MAX_LIBRARY_ORDINAL 0xfd
694#define DYNAMIC_LOOKUP_ORDINAL 0xfe
695#define EXECUTABLE_ORDINAL 0xff
696
697#define N_NO_DEAD_STRIP UINT16_C(0x0020)
698#define N_DESC_DISCARDED UINT16_C(0x0020)
699#define N_WEAK_REF UINT16_C(0x0040)
700#define N_WEAK_DEF UINT16_C(0x0080)
701#define N_REF_TO_WEAK UINT16_C(0x0080)
702#define N_SYMBOL_RESOLVER UINT16_C(0x0100)
703#define N_ALT_ENTRY UINT16_C(0x0200)
704
705typedef struct macho_relocation_info
706{
707 int32_t r_address;
708 uint32_t r_symbolnum : 24;
709 uint32_t r_pcrel : 1;
710 uint32_t r_length : 2;
711 uint32_t r_extern : 1;
712 uint32_t r_type : 4;
713} macho_relocation_info_t;
714AssertCompileSize(macho_relocation_info_t, 8);
715
716#define R_ABS 0
717#define R_SCATTERED UINT32_C(0x80000000)
718
719typedef struct scattered_relocation_info
720{
721#ifdef RT_LITTLE_ENDIAN
722 uint32_t r_address : 24;
723 uint32_t r_type : 4;
724 uint32_t r_length : 2;
725 uint32_t r_pcrel : 1;
726 uint32_t r_scattered : 1;
727#elif defined(RT_BIG_ENDIAN)
728 uint32_t r_scattered : 1;
729 uint32_t r_pcrel : 1;
730 uint32_t r_length : 2;
731 uint32_t r_type : 4;
732 uint32_t r_address : 24;
733#else
734# error "Neither K_ENDIAN isn't LITTLE or BIG!"
735#endif
736 int32_t r_value;
737} scattered_relocation_info_t;
738AssertCompileSize(scattered_relocation_info_t, 8);
739
740typedef union
741{
742 macho_relocation_info_t r;
743 scattered_relocation_info_t s;
744} macho_relocation_union_t;
745AssertCompileSize(macho_relocation_union_t, 8);
746
747typedef enum reloc_type_generic
748{
749 GENERIC_RELOC_VANILLA = 0,
750 GENERIC_RELOC_PAIR,
751 GENERIC_RELOC_SECTDIFF,
752 GENERIC_RELOC_PB_LA_PTR,
753 GENERIC_RELOC_LOCAL_SECTDIFF
754} reloc_type_generic_t;
755
756typedef enum reloc_type_x86_64
757{
758 X86_64_RELOC_UNSIGNED = 0,
759 X86_64_RELOC_SIGNED,
760 X86_64_RELOC_BRANCH,
761 X86_64_RELOC_GOT_LOAD,
762 X86_64_RELOC_GOT,
763 X86_64_RELOC_SUBTRACTOR,
764 X86_64_RELOC_SIGNED_1,
765 X86_64_RELOC_SIGNED_2,
766 X86_64_RELOC_SIGNED_4
767} reloc_type_x86_64_t;
768
769#endif
770
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette