VirtualBox

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

Last change on this file since 86943 was 86290, checked in by vboxsync, 4 years ago

Runtime/r0drv/dbgfkrnlinfo-r0drv-darwin: Starting with BigSur, each segment can have a different load displacement. Account for that, bugref:9836

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