VirtualBox

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

Last change on this file since 85859 was 85339, checked in by vboxsync, 4 years ago

iprt/formats/mach-o.h,ldrMachO.cpp: New segment flag SG_READ_ONLY added in 10.14. Harmless. bugref:9790

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