VirtualBox

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

Last change on this file since 83941 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.4 KB
Line 
1/* $Id: mach-o.h 82968 2020-02-04 10:35:17Z 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_VALID_FLAGS UINT32_C(0x01ffffff)
264
265
266typedef struct load_command
267{
268 uint32_t cmd;
269 uint32_t cmdsize;
270} load_command_t;
271
272/* load cmd */
273#define LC_REQ_DYLD UINT32_C(0x80000000)
274#define LC_SEGMENT_32 UINT32_C(0x01)
275#define LC_SYMTAB UINT32_C(0x02)
276#define LC_SYMSEG UINT32_C(0x03)
277#define LC_THREAD UINT32_C(0x04)
278#define LC_UNIXTHREAD UINT32_C(0x05)
279#define LC_LOADFVMLIB UINT32_C(0x06)
280#define LC_IDFVMLIB UINT32_C(0x07)
281#define LC_IDENT UINT32_C(0x08)
282#define LC_FVMFILE UINT32_C(0x09)
283#define LC_PREPAGE UINT32_C(0x0a)
284#define LC_DYSYMTAB UINT32_C(0x0b)
285#define LC_LOAD_DYLIB UINT32_C(0x0c)
286#define LC_ID_DYLIB UINT32_C(0x0d)
287#define LC_LOAD_DYLINKER UINT32_C(0x0e)
288#define LC_ID_DYLINKER UINT32_C(0x0f)
289#define LC_PREBOUND_DYLIB UINT32_C(0x10)
290#define LC_ROUTINES UINT32_C(0x11)
291#define LC_SUB_FRAMEWORK UINT32_C(0x12)
292#define LC_SUB_UMBRELLA UINT32_C(0x13)
293#define LC_SUB_CLIENT UINT32_C(0x14)
294#define LC_SUB_LIBRARY UINT32_C(0x15)
295#define LC_TWOLEVEL_HINTS UINT32_C(0x16)
296#define LC_PREBIND_CKSUM UINT32_C(0x17)
297#define LC_LOAD_WEAK_DYLIB (UINT32_C(0x18) | LC_REQ_DYLD)
298#define LC_SEGMENT_64 UINT32_C(0x19)
299#define LC_ROUTINES_64 UINT32_C(0x1a)
300#define LC_UUID UINT32_C(0x1b)
301#define LC_RPATH (UINT32_C(0x1c) | LC_REQ_DYLD)
302#define LC_CODE_SIGNATURE UINT32_C(0x1d)
303#define LC_SEGMENT_SPLIT_INFO UINT32_C(0x1e)
304#define LC_REEXPORT_DYLIB (UINT32_C(0x1f) | LC_REQ_DYLD)
305#define LC_LAZY_LOAD_DYLIB UINT32_C(0x20)
306#define LC_ENCRYPTION_INFO UINT32_C(0x21)
307#define LC_DYLD_INFO UINT32_C(0x22)
308#define LC_DYLD_INFO_ONLY (UINT32_C(0x22) | LC_REQ_DYLD)
309#define LC_LOAD_UPWARD_DYLIB (UINT32_C(0x23) | LC_REQ_DYLD)
310#define LC_VERSION_MIN_MACOSX UINT32_C(0x24)
311#define LC_VERSION_MIN_IPHONEOS UINT32_C(0x25)
312#define LC_FUNCTION_STARTS UINT32_C(0x26)
313#define LC_DYLD_ENVIRONMENT UINT32_C(0x27)
314#define LC_MAIN (UINT32_C(0x28) | LC_REQ_DYLD)
315#define LC_DATA_IN_CODE UINT32_C(0x29)
316#define LC_SOURCE_VERSION UINT32_C(0x2a) /**< source_version_command */
317#define LC_DYLIB_CODE_SIGN_DRS UINT32_C(0x2b)
318#define LC_ENCRYPTION_INFO_64 UINT32_C(0x2c)
319#define LC_LINKER_OPTION UINT32_C(0x2d)
320#define LC_LINKER_OPTIMIZATION_HINT UINT32_C(0x2e)
321#define LC_VERSION_MIN_TVOS UINT32_C(0x2f)
322#define LC_VERSION_MIN_WATCHOS UINT32_C(0x30)
323#define LC_NOTE UINT32_C(0x31)
324#define LC_BUILD_VERSION UINT32_C(0x32)
325
326
327typedef struct lc_str
328{
329 uint32_t offset;
330} lc_str_t;
331
332typedef struct segment_command_32
333{
334 uint32_t cmd;
335 uint32_t cmdsize;
336 char segname[16];
337 uint32_t vmaddr;
338 uint32_t vmsize;
339 uint32_t fileoff;
340 uint32_t filesize;
341 uint32_t maxprot;
342 uint32_t initprot;
343 uint32_t nsects;
344 uint32_t flags;
345} segment_command_32_t;
346
347typedef struct segment_command_64
348{
349 uint32_t cmd;
350 uint32_t cmdsize;
351 char segname[16];
352 uint64_t vmaddr;
353 uint64_t vmsize;
354 uint64_t fileoff;
355 uint64_t filesize;
356 uint32_t maxprot;
357 uint32_t initprot;
358 uint32_t nsects;
359 uint32_t flags;
360} segment_command_64_t;
361
362/* segment flags */
363#define SG_HIGHVM UINT32_C(0x00000001)
364#define SG_FVMLIB UINT32_C(0x00000002)
365#define SG_NORELOC UINT32_C(0x00000004)
366#define SG_PROTECTED_VERSION_1 UINT32_C(0x00000008)
367
368/* maxprot/initprot */
369#ifndef VM_PROT_NONE
370# define VM_PROT_NONE UINT32_C(0x00000000)
371# define VM_PROT_READ UINT32_C(0x00000001)
372# define VM_PROT_WRITE UINT32_C(0x00000002)
373# define VM_PROT_EXECUTE UINT32_C(0x00000004)
374# define VM_PROT_ALL UINT32_C(0x00000007)
375#endif
376
377typedef struct section_32
378{
379 char sectname[16];
380 char segname[16];
381 uint32_t addr;
382 uint32_t size;
383 uint32_t offset;
384 uint32_t align;
385 uint32_t reloff;
386 uint32_t nreloc;
387 uint32_t flags;
388 /** For S_LAZY_SYMBOL_POINTERS, S_NON_LAZY_SYMBOL_POINTERS and S_SYMBOL_STUBS
389 * this is the index into the indirect symbol table. */
390 uint32_t reserved1;
391 /** For S_SYMBOL_STUBS this is the entry size. */
392 uint32_t reserved2;
393} section_32_t;
394
395typedef struct section_64
396{
397 char sectname[16];
398 char segname[16];
399 uint64_t addr;
400 uint64_t size;
401 uint32_t offset;
402 uint32_t align;
403 uint32_t reloff;
404 uint32_t nreloc;
405 uint32_t flags;
406 /** For S_LAZY_SYMBOL_POINTERS, S_NON_LAZY_SYMBOL_POINTERS and S_SYMBOL_STUBS
407 * this is the index into the indirect symbol table. */
408 uint32_t reserved1;
409 uint32_t reserved2;
410 uint32_t reserved3;
411} section_64_t;
412
413/* section flags */
414#define SECTION_TYPE UINT32_C(0xff)
415#define S_REGULAR UINT32_C(0x00)
416#define S_ZEROFILL UINT32_C(0x01)
417#define S_CSTRING_LITERALS UINT32_C(0x02)
418#define S_4BYTE_LITERALS UINT32_C(0x03)
419#define S_8BYTE_LITERALS UINT32_C(0x04)
420#define S_LITERAL_POINTERS UINT32_C(0x05)
421#define S_NON_LAZY_SYMBOL_POINTERS UINT32_C(0x06)
422#define S_LAZY_SYMBOL_POINTERS UINT32_C(0x07)
423#define S_SYMBOL_STUBS UINT32_C(0x08)
424#define S_MOD_INIT_FUNC_POINTERS UINT32_C(0x09)
425#define S_MOD_TERM_FUNC_POINTERS UINT32_C(0x0a)
426#define S_COALESCED UINT32_C(0x0b)
427#define S_GB_ZEROFILL UINT32_C(0x0c)
428#define S_INTERPOSING UINT32_C(0x0d)
429#define S_16BYTE_LITERALS UINT32_C(0x0e)
430#define S_DTRACE_DOF UINT32_C(0x0f)
431#define S_LAZY_DYLIB_SYMBOL_POINTERS UINT32_C(0x10)
432#define S_THREAD_LOCAL_REGULAR UINT32_C(0x11)
433#define S_THREAD_LOCAL_ZEROFILL UINT32_C(0x12)
434#define S_THREAD_LOCAL_VARIABLES UINT32_C(0x13)
435#define S_THREAD_LOCAL_VARIABLE_POINTERS UINT32_C(0x14)
436#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS UINT32_C(0x15)
437
438
439
440
441#define SECTION_ATTRIBUTES UINT32_C(0xffffff00)
442#define SECTION_ATTRIBUTES_USR UINT32_C(0xff000000)
443#define S_ATTR_PURE_INSTRUCTIONS UINT32_C(0x80000000)
444#define S_ATTR_NO_TOC UINT32_C(0x40000000)
445#define S_ATTR_STRIP_STATIC_SYMS UINT32_C(0x20000000)
446#define S_ATTR_NO_DEAD_STRIP UINT32_C(0x10000000)
447#define S_ATTR_LIVE_SUPPORT UINT32_C(0x08000000)
448#define S_ATTR_SELF_MODIFYING_CODE UINT32_C(0x04000000)
449#define S_ATTR_DEBUG UINT32_C(0x02000000)
450#define SECTION_ATTRIBUTES_SYS UINT32_C(0x00ffff00)
451#define S_ATTR_SOME_INSTRUCTIONS UINT32_C(0x00000400)
452#define S_ATTR_EXT_RELOC UINT32_C(0x00000200)
453#define S_ATTR_LOC_RELOC UINT32_C(0x00000100)
454
455/* standard section names */
456#define SEG_PAGEZERO "__PAGEZERO"
457#define SEG_TEXT "__TEXT"
458#define SECT_TEXT "__text"
459#define SECT_FVMLIB_INIT0 "__fvmlib_init0"
460#define SECT_FVMLIB_INIT1 "__fvmlib_init1"
461#define SEG_DATA "__DATA"
462#define SECT_DATA "__data"
463#define SECT_BSS "__bss"
464#define SECT_COMMON "__common"
465#define SEG_OBJC "__OBJC"
466#define SECT_OBJC_SYMBOLS "__symbol_table"
467#define SECT_OBJC_MODULES "__module_info"
468#define SECT_OBJC_STRINGS "__selector_strs"
469#define SECT_OBJC_REFS "__selector_refs"
470#define SEG_ICON "__ICON"
471#define SECT_ICON_HEADER "__header"
472#define SECT_ICON_TIFF "__tiff"
473#define SEG_LINKEDIT "__LINKEDIT"
474#define SEG_UNIXSTACK "__UNIXSTACK"
475#define SEG_IMPORT "__IMPORT"
476
477typedef struct thread_command
478{
479 uint32_t cmd;
480 uint32_t cmdsize;
481} thread_command_t;
482
483typedef struct symtab_command
484{
485 uint32_t cmd;
486 uint32_t cmdsize;
487 uint32_t symoff;
488 uint32_t nsyms;
489 uint32_t stroff;
490 uint32_t strsize;
491} symtab_command_t;
492
493typedef struct dysymtab_command
494{
495 uint32_t cmd;
496 uint32_t cmdsize;
497 /** @name Symbol groupings.
498 * @{ */
499 uint32_t ilocalsym; /**< Index into the symbol table of the first local symbol. */
500 uint32_t nlocalsym; /**< Number of local symbols. */
501 uint32_t iextdefsym; /**< Index into the symbol table of the first externally defined symbol. */
502 uint32_t nextdefsym; /**< Number of externally defined symbols. */
503 uint32_t iundefsym; /**< Index into the symbol table of the first undefined symbol. */
504 uint32_t nundefsym; /**< Number of undefined symbols. */
505 /** @} */
506 uint32_t tocoff; /**< Table of content file offset. (usually empty) */
507 uint32_t ntoc; /**< Number of entries in TOC. */
508 uint32_t modtaboff; /** The module table file offset. (usually empty) */
509 uint32_t nmodtab; /**< Number of entries in the module table. */
510 /** @name Dynamic symbol tables.
511 * @{ */
512 uint32_t extrefsymoff; /**< Externally referenceable symbol table file offset. @sa dylib_reference_t */
513 uint32_t nextrefsym; /**< Number externally referenceable symbols. */
514 uint32_t indirectsymboff; /**< Indirect symbol table (32-bit symtab indexes) for thunks and offset tables. */
515 uint32_t nindirectsymb; /**< Number of indirect symbol table entries. */
516 /** @} */
517 /** @name Relocations.
518 * @{ */
519 uint32_t extreloff; /**< External relocations (r_address is relative to first segment (i.e. RVA)). */
520 uint32_t nextrel; /**< Number of external relocations. */
521 uint32_t locreloff; /**< Local relocations (r_address is relative to first segment (i.e. RVA)). */
522 uint32_t nlocrel; /**< Number of local relocations. */
523 /** @} */
524} dysymtab_command_t;
525AssertCompileSize(dysymtab_command_t, 80);
526
527/** Special indirect symbol table entry value, stripped local symbol. */
528#define INDIRECT_SYMBOL_LOCAL UINT32_C(0x80000000)
529/** Special indirect symbol table entry value, stripped absolute symbol. */
530#define INDIRECT_SYMBOL_ABS UINT32_C(0x40000000)
531
532typedef struct dylib_reference
533{
534 uint32_t isym : 24; /**< Symbol table index. */
535 uint32_t flags : 8; /**< REFERENCE_FLAG_XXX? */
536} dylib_reference_t;
537AssertCompileSize(dylib_reference_t, 4);
538
539
540typedef struct dylib_table_of_contents
541{
542 uint32_t symbol_index; /**< External symbol table entry. */
543 uint32_t module_index; /**< The module table index of the module defining it. */
544} dylib_table_of_contents_t;
545AssertCompileSize(dylib_table_of_contents_t, 8);
546
547
548/** 32-bit module table entry. */
549typedef struct dylib_module
550{
551 uint32_t module_name;
552 uint32_t iextdefsym;
553 uint32_t nextdefsym;
554 uint32_t irefsym;
555 uint32_t nrefsym;
556 uint32_t ilocalsym;
557 uint32_t nlocalsym;
558 uint32_t iextrel;
559 uint32_t nextrel;
560 uint32_t iinit_iterm;
561 uint32_t ninit_nterm;
562 uint32_t objc_module_info_addr;
563 uint32_t objc_module_info_size;
564} dylib_module_32_t;
565AssertCompileSize(dylib_module_32_t, 13*4);
566
567/* a 64-bit module table entry */
568typedef struct dylib_module_64
569{
570 uint32_t module_name;
571 uint32_t iextdefsym;
572 uint32_t nextdefsym;
573 uint32_t irefsym;
574 uint32_t nrefsym;
575 uint32_t ilocalsym;
576 uint32_t nlocalsym;
577 uint32_t iextrel;
578 uint32_t nextrel;
579 uint32_t iinit_iterm;
580 uint32_t ninit_nterm;
581 uint32_t objc_module_info_size;
582 uint64_t objc_module_info_addr;
583} dylib_module_64_t;
584AssertCompileSize(dylib_module_64_t, 12*4+8);
585
586typedef struct uuid_command
587{
588 uint32_t cmd;
589 uint32_t cmdsize;
590 uint8_t uuid[16];
591} uuid_command_t;
592AssertCompileSize(uuid_command_t, 24);
593
594typedef struct linkedit_data_command
595{
596 uint32_t cmd; /**< LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS */
597 uint32_t cmdsize; /**< Size of this structure (16). */
598 uint32_t dataoff; /**< Offset into the file of the data. */
599 uint32_t datasize; /**< The size of the data. */
600} linkedit_data_command_t;
601AssertCompileSize(linkedit_data_command_t, 16);
602
603typedef struct version_min_command
604{
605 uint32_t cmd; /**< LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS, LC_VERSION_MIN_WATCHOS */
606 uint32_t cmdsize; /**< Size of this structure (16). */
607 uint32_t version; /**< 31..16=major, 15..8=minor, 7..0=patch. */
608 uint32_t reserved; /**< MBZ. */
609} version_min_command_t;
610AssertCompileSize(version_min_command_t, 16);
611
612typedef struct build_tool_version
613{
614 uint32_t tool; /**< TOOL_XXX */
615 uint32_t version; /**< 31..16=major, 15..8=minor, 7..0=patch. */
616} build_tool_version_t;
617AssertCompileSize(build_tool_version_t, 8);
618
619/** @name TOOL_XXX - Values for build_tool_version::tool
620 * @{ */
621#define TOOL_CLANG 1
622#define TOOL_SWIFT 2
623#define TOOL_LD 3
624/** @} */
625
626typedef struct build_version_command
627{
628 uint32_t cmd; /**< LC_BUILD_VERSION */
629 uint32_t cmdsize; /**< Size of this structure (at least 24). */
630 uint32_t platform; /**< PLATFORM_XXX */
631 uint32_t minos; /**< Minimum OS version: 31..16=major, 15..8=minor, 7..0=patch */
632 uint32_t sdk; /**< SDK version: 31..16=major, 15..8=minor, 7..0=patch */
633 uint32_t ntools; /**< Number of build_tool_version entries following in aTools. */
634 build_tool_version_t aTools[RT_FLEXIBLE_ARRAY];
635} build_version_command_t;
636AssertCompileMemberOffset(build_version_command_t, aTools, 24);
637
638/** @name PLATFORM_XXX - Values for build_version_command::platform
639 * @{ */
640#define PLATFORM_MACOS 1
641#define PLATFORM_IOS 2
642#define PLATFORM_TVOS 3
643#define PLATFORM_WATCHOS 4
644/** @} */
645
646typedef struct source_version_command
647{
648 uint32_t cmd; /**< LC_SOURCE_VERSION */
649 uint32_t cmdsize; /**< Size of this structure (16). */
650 uint64_t version; /**< A.B.C.D.E, where A is 24 bits wide and the rest 10 bits each. */
651} source_version_command_t;
652AssertCompileSize(source_version_command_t, 16);
653
654
655typedef struct macho_nlist_32
656{
657 union
658 {
659 int32_t n_strx;
660 } n_un;
661 uint8_t n_type;
662 uint8_t n_sect;
663 int16_t n_desc;
664 uint32_t n_value;
665} macho_nlist_32_t;
666
667
668typedef struct macho_nlist_64
669{
670 union
671 {
672 uint32_t n_strx;
673 } n_un;
674 uint8_t n_type;
675 uint8_t n_sect;
676 int16_t n_desc;
677 uint64_t n_value;
678} macho_nlist_64_t;
679
680#define MACHO_N_EXT UINT8_C(0x01)
681#define MACHO_N_PEXT UINT8_C(0x10)
682
683#define MACHO_N_TYPE UINT8_C(0x0e)
684#define MACHO_N_UNDF UINT8_C(0x00)
685#define MACHO_N_ABS UINT8_C(0x02)
686#define MACHO_N_INDR UINT8_C(0x0a)
687#define MACHO_N_PBUD UINT8_C(0x0c)
688#define MACHO_N_SECT UINT8_C(0x0e)
689
690#define MACHO_N_STAB UINT8_C(0xe0)
691#define MACHO_N_GSYM UINT8_C(0x20)
692#define MACHO_N_FNAME UINT8_C(0x22)
693#define MACHO_N_FUN UINT8_C(0x24)
694#define MACHO_N_STSYM UINT8_C(0x26)
695#define MACHO_N_LCSYM UINT8_C(0x28)
696#define MACHO_N_BNSYM UINT8_C(0x2e)
697#define MACHO_N_PC UINT8_C(0x30)
698#define MACHO_N_OPT UINT8_C(0x3c)
699#define MACHO_N_RSYM UINT8_C(0x40)
700#define MACHO_N_SLINE UINT8_C(0x44)
701#define MACHO_N_ENSYM UINT8_C(0x4e)
702#define MACHO_N_SSYM UINT8_C(0x60)
703#define MACHO_N_SO UINT8_C(0x64)
704#define MACHO_N_OSO UINT8_C(0x66)
705#define MACHO_N_LSYM UINT8_C(0x80)
706#define MACHO_N_BINCL UINT8_C(0x82)
707#define MACHO_N_SOL UINT8_C(0x84)
708#define MACHO_N_PARAMS UINT8_C(0x86)
709#define MACHO_N_VERSION UINT8_C(0x88)
710#define MACHO_N_OLEVEL UINT8_C(0x8A)
711#define MACHO_N_PSYM UINT8_C(0xa0)
712#define MACHO_N_EINCL UINT8_C(0xa2)
713#define MACHO_N_ENTRY UINT8_C(0xa4)
714#define MACHO_N_LBRAC UINT8_C(0xc0)
715#define MACHO_N_EXCL UINT8_C(0xc2)
716#define MACHO_N_RBRAC UINT8_C(0xe0)
717#define MACHO_N_BCOMM UINT8_C(0xe2)
718#define MACHO_N_ECOMM UINT8_C(0xe4)
719#define MACHO_N_ECOML UINT8_C(0xe8)
720#define MACHO_N_LENG UINT8_C(0xfe)
721
722#define MACHO_NO_SECT UINT8_C(0x00)
723#define MACHO_MAX_SECT UINT8_C(0xff)
724
725#define REFERENCE_TYPE UINT16_C(0x000f)
726#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
727#define REFERENCE_FLAG_UNDEFINED_LAZY 1
728#define REFERENCE_FLAG_DEFINED 2
729#define REFERENCE_FLAG_PRIVATE_DEFINED 3
730#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
731#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
732#define REFERENCED_DYNAMICALLY UINT16_C(0x0010)
733
734#define GET_LIBRARY_ORDINAL(a_n_desc) \
735 RT_BYTE2(a_n_desc)
736#define SET_LIBRARY_ORDINAL(a_n_desc, a_ordinal) \
737 do { (a_n_desc) = RT_MAKE_U16(RT_BYTE1(a_n_desc), a_ordinal); } while (0)
738
739#define SELF_LIBRARY_ORDINAL 0x00
740#define MAX_LIBRARY_ORDINAL 0xfd
741#define DYNAMIC_LOOKUP_ORDINAL 0xfe
742#define EXECUTABLE_ORDINAL 0xff
743
744#define N_NO_DEAD_STRIP UINT16_C(0x0020)
745#define N_DESC_DISCARDED UINT16_C(0x0020)
746#define N_WEAK_REF UINT16_C(0x0040)
747#define N_WEAK_DEF UINT16_C(0x0080)
748#define N_REF_TO_WEAK UINT16_C(0x0080)
749#define N_SYMBOL_RESOLVER UINT16_C(0x0100)
750#define N_ALT_ENTRY UINT16_C(0x0200)
751
752typedef struct macho_relocation_info
753{
754 int32_t r_address;
755 uint32_t r_symbolnum : 24;
756 uint32_t r_pcrel : 1;
757 uint32_t r_length : 2;
758 uint32_t r_extern : 1;
759 uint32_t r_type : 4;
760} macho_relocation_info_t;
761AssertCompileSize(macho_relocation_info_t, 8);
762
763#define R_ABS 0
764#define R_SCATTERED UINT32_C(0x80000000)
765
766typedef struct scattered_relocation_info
767{
768#ifdef RT_LITTLE_ENDIAN
769 uint32_t r_address : 24;
770 uint32_t r_type : 4;
771 uint32_t r_length : 2;
772 uint32_t r_pcrel : 1;
773 uint32_t r_scattered : 1;
774#elif defined(RT_BIG_ENDIAN)
775 uint32_t r_scattered : 1;
776 uint32_t r_pcrel : 1;
777 uint32_t r_length : 2;
778 uint32_t r_type : 4;
779 uint32_t r_address : 24;
780#else
781# error "Neither K_ENDIAN isn't LITTLE or BIG!"
782#endif
783 int32_t r_value;
784} scattered_relocation_info_t;
785AssertCompileSize(scattered_relocation_info_t, 8);
786
787typedef union
788{
789 macho_relocation_info_t r;
790 scattered_relocation_info_t s;
791} macho_relocation_union_t;
792AssertCompileSize(macho_relocation_union_t, 8);
793
794typedef enum reloc_type_generic
795{
796 GENERIC_RELOC_VANILLA = 0,
797 GENERIC_RELOC_PAIR,
798 GENERIC_RELOC_SECTDIFF,
799 GENERIC_RELOC_PB_LA_PTR,
800 GENERIC_RELOC_LOCAL_SECTDIFF
801} reloc_type_generic_t;
802
803typedef enum reloc_type_x86_64
804{
805 X86_64_RELOC_UNSIGNED = 0,
806 X86_64_RELOC_SIGNED,
807 X86_64_RELOC_BRANCH,
808 X86_64_RELOC_GOT_LOAD,
809 X86_64_RELOC_GOT,
810 X86_64_RELOC_SUBTRACTOR,
811 X86_64_RELOC_SIGNED_1,
812 X86_64_RELOC_SIGNED_2,
813 X86_64_RELOC_SIGNED_4
814} reloc_type_x86_64_t;
815
816#endif /* !IPRT_INCLUDED_formats_mach_o_h */
817
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