1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2018 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
34 #ifndef OUTPUT_MACHO_H
35 #define OUTPUT_MACHO_H
40 #define MH_MAGIC 0xfeedface
41 #define MH_MAGIC_64 0xfeedfacf
47 #define CPU_ARCH_MASK 0xff000000
48 #define CPU_ARCH_ABI64 0x01000000
49 #define CPU_TYPE_X86 7
50 #define CPU_TYPE_I386 CPU_TYPE_X86
51 #define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
53 #define CPU_SUBTYPE_MASK 0xff000000
54 #define CPU_SUBTYPE_I386_ALL 3
57 #define MH_SUBSECTIONS_VIA_SYMBOLS 0x00002000
60 #define LC_SEGMENT 0x1
61 #define LC_SEGMENT_64 0x19
64 /* Symbol type bits */
70 /* To mask with N_TYPE */
77 /* Section ordinals */
82 #define SECTION_TYPE 0x000000ff
83 #define SECTION_ATTRIBUTES 0xffffff00
84 #define SECTION_ATTRIBUTES_USR 0xff000000
85 #define SECTION_ATTRIBUTES_SYS 0x00ffff00
87 #define S_REGULAR 0x00
88 #define S_ZEROFILL 0x01
89 #define S_CSTRING_LITERALS 0x02
90 #define S_4BYTE_LITERALS 0x03
91 #define S_8BYTE_LITERALS 0x04
92 #define S_LITERAL_POINTERS 0x05
93 #define S_NON_LAZY_SYMBOL_POINTERS 0x06
94 #define S_LAZY_SYMBOL_POINTERS 0x07
95 #define S_SYMBOL_STUBS 0x08
96 #define S_MOD_INIT_FUNC_POINTERS 0x09
97 #define S_MOD_TERM_FUNC_POINTERS 0x0a
98 #define S_COALESCED 0x0b
99 #define S_GB_ZEROFILL 0x0c
100 #define S_INTERPOSING 0x0d
101 #define S_16BYTE_LITERALS 0x0e
102 #define S_DTRACE_DOF 0x0f
103 #define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10
104 #define S_THREAD_LOCAL_REGULAR 0x11
105 #define S_THREAD_LOCAL_ZEROFILL 0x12
106 #define S_THREAD_LOCAL_VARIABLES 0x13
107 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
108 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
110 #define S_ATTR_PURE_INSTRUCTIONS 0x80000000
111 #define S_ATTR_NO_TOC 0x40000000
112 #define S_ATTR_STRIP_STATIC_SYMS 0x20000000
113 #define S_ATTR_NO_DEAD_STRIP 0x10000000
114 #define S_ATTR_LIVE_SUPPORT 0x08000000
115 #define S_ATTR_SELF_MODIFYING_CODE 0x04000000
116 #define S_ATTR_DEBUG 0x02000000
118 #define S_ATTR_SOME_INSTRUCTIONS 0x00000400
119 #define S_ATTR_EXT_RELOC 0x00000200
120 #define S_ATTR_LOC_RELOC 0x00000100
121 #define INDIRECT_SYMBOL_LOCAL 0x80000000
122 #define INDIRECT_SYMBOL_ABS 0x40000000
124 /* Relocation info type */
125 #define GENERIC_RELOC_VANILLA 0
126 #define GENERIC_RELOC_PAIR 1
127 #define GENERIC_RELOC_SECTDIFF 2
128 #define GENERIC_RELOC_PB_LA_PTR 3
129 #define GENERIC_RELOC_LOCAL_SECTDIFF 4
130 #define GENERIC_RELOC_TLV 5
132 #define X86_64_RELOC_UNSIGNED 0
133 #define X86_64_RELOC_SIGNED 1
134 #define X86_64_RELOC_BRANCH 2
135 #define X86_64_RELOC_GOT_LOAD 3
136 #define X86_64_RELOC_GOT 4
137 #define X86_64_RELOC_SUBTRACTOR 5
138 #define X86_64_RELOC_SIGNED_1 6
139 #define X86_64_RELOC_SIGNED_2 7
140 #define X86_64_RELOC_SIGNED_4 8
141 #define X86_64_RELOC_TLV 9
143 /* Relocation info */
145 #define R_SCATTERED 0x80000000
147 /* VM permission constants */
148 #define VM_PROT_NONE 0x00
149 #define VM_PROT_READ 0x01
150 #define VM_PROT_WRITE 0x02
151 #define VM_PROT_EXECUTE 0x04
177 } macho_load_command_t
;
191 } macho_segment_command_t
;
205 } macho_segment_command_64_t
;
234 } macho_section_64_t
;
243 } macho_symtab_command_t
;
249 uint32_t r_symbolnum
: 24,
257 } macho_relocation_info_t
;
259 typedef struct nlist_base
{
264 } macho_nlist_base_t
;
266 typedef struct nlist
{
282 #endif /* OUTPUT_MACHO_H */