2009-06-25 Rafael Avila de Espindola <espindola@google.com>
[deliverable/binutils-gdb.git] / bfd / mach-o.h
CommitLineData
3af9a47b 1/* Mach-O support for BFD.
154a1ee5 2 Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009
3af9a47b
NC
3 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
3af9a47b
NC
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
e84d6fca 18 along with this program; if not, write to the Free Software
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
3af9a47b
NC
21
22#ifndef _BFD_MACH_O_H_
23#define _BFD_MACH_O_H_
24
25#include "bfd.h"
26
92bc0e80 27/* Symbol n_type values. */
3af9a47b
NC
28#define BFD_MACH_O_N_STAB 0xe0 /* If any of these bits set, a symbolic debugging entry. */
29#define BFD_MACH_O_N_PEXT 0x10 /* Private external symbol bit. */
30#define BFD_MACH_O_N_TYPE 0x0e /* Mask for the type bits. */
31#define BFD_MACH_O_N_EXT 0x01 /* External symbol bit, set for external symbols. */
32#define BFD_MACH_O_N_UNDF 0x00 /* Undefined, n_sect == NO_SECT. */
33#define BFD_MACH_O_N_ABS 0x02 /* Absolute, n_sect == NO_SECT. */
3af9a47b 34#define BFD_MACH_O_N_INDR 0x0a /* Indirect. */
15e1c58a
TG
35#define BFD_MACH_O_N_PBUD 0x0c /* Prebound undefined (defined in a dylib). */
36#define BFD_MACH_O_N_SECT 0x0e /* Defined in section number n_sect. */
37
92bc0e80
TG
38#define BFD_MACH_O_NO_SECT 0 /* Symbol not in any section of the image. */
39
046b007d
TG
40/* Symbol n_desc reference flags. */
41#define BFD_MACH_O_REFERENCE_MASK 0x0f
92bc0e80
TG
42#define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_NON_LAZY 0x00
43#define BFD_MACH_O_REFERENCE_FLAG_UNDEFINED_LAZY 0x01
44#define BFD_MACH_O_REFERENCE_FLAG_DEFINED 0x02
45#define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_DEFINED 0x03
46#define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 0x04
47#define BFD_MACH_O_REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 0x05
046b007d 48
92bc0e80
TG
49#define BFD_MACH_O_REFERENCED_DYNAMICALLY 0x10
50#define BFD_MACH_O_N_DESC_DISCARDED 0x20
51#define BFD_MACH_O_N_NO_DEAD_STRIP 0x20
52#define BFD_MACH_O_N_WEAK_REF 0x40
53#define BFD_MACH_O_N_WEAK_DEF 0x80
3af9a47b 54
154a1ee5
TG
55typedef enum bfd_mach_o_mach_header_magic
56{
57 BFD_MACH_O_MH_MAGIC = 0xfeedface,
58 BFD_MACH_O_MH_CIGAM = 0xcefaedfe,
59 BFD_MACH_O_MH_MAGIC_64 = 0xfeedfacf,
60 BFD_MACH_O_MH_CIGAM_64 = 0xcffaedfe
61}
62bfd_mach_o_mach_header_magic;
63
3af9a47b 64typedef enum bfd_mach_o_ppc_thread_flavour
116c20d2
NC
65{
66 BFD_MACH_O_PPC_THREAD_STATE = 1,
67 BFD_MACH_O_PPC_FLOAT_STATE = 2,
68 BFD_MACH_O_PPC_EXCEPTION_STATE = 3,
1e8a024a
TG
69 BFD_MACH_O_PPC_VECTOR_STATE = 4,
70 BFD_MACH_O_PPC_THREAD_STATE_64 = 5
116c20d2 71}
3af9a47b
NC
72bfd_mach_o_ppc_thread_flavour;
73
15e1c58a 74/* Defined in <mach/i386/thread_status.h> */
3af9a47b 75typedef enum bfd_mach_o_i386_thread_flavour
116c20d2 76{
15e1c58a
TG
77 BFD_MACH_O_x86_THREAD_STATE32 = 1,
78 BFD_MACH_O_x86_FLOAT_STATE32 = 2,
79 BFD_MACH_O_x86_EXCEPTION_STATE32 = 3,
1e8a024a
TG
80 BFD_MACH_O_x86_THREAD_STATE64 = 4,
81 BFD_MACH_O_x86_FLOAT_STATE64 = 5,
82 BFD_MACH_O_x86_EXCEPTION_STATE64 = 6,
83 BFD_MACH_O_x86_THREAD_STATE = 7,
84 BFD_MACH_O_x86_FLOAT_STATE = 8,
85 BFD_MACH_O_x86_EXCEPTION_STATE = 9,
15e1c58a
TG
86 BFD_MACH_O_x86_DEBUG_STATE32 = 10,
87 BFD_MACH_O_x86_DEBUG_STATE64 = 11,
88 BFD_MACH_O_x86_DEBUG_STATE = 12,
89 BFD_MACH_O_THREAD_STATE_NONE = 13
116c20d2 90}
3af9a47b
NC
91bfd_mach_o_i386_thread_flavour;
92
93#define BFD_MACH_O_LC_REQ_DYLD 0x80000000
94
95typedef enum bfd_mach_o_load_command_type
116c20d2
NC
96{
97 BFD_MACH_O_LC_SEGMENT = 0x1, /* File segment to be mapped. */
98 BFD_MACH_O_LC_SYMTAB = 0x2, /* Link-edit stab symbol table info (obsolete). */
99 BFD_MACH_O_LC_SYMSEG = 0x3, /* Link-edit gdb symbol table info. */
100 BFD_MACH_O_LC_THREAD = 0x4, /* Thread. */
101 BFD_MACH_O_LC_UNIXTHREAD = 0x5, /* UNIX thread (includes a stack). */
102 BFD_MACH_O_LC_LOADFVMLIB = 0x6, /* Load a fixed VM shared library. */
103 BFD_MACH_O_LC_IDFVMLIB = 0x7, /* Fixed VM shared library id. */
104 BFD_MACH_O_LC_IDENT = 0x8, /* Object identification information (obsolete). */
105 BFD_MACH_O_LC_FVMFILE = 0x9, /* Fixed VM file inclusion. */
106 BFD_MACH_O_LC_PREPAGE = 0xa, /* Prepage command (internal use). */
107 BFD_MACH_O_LC_DYSYMTAB = 0xb, /* Dynamic link-edit symbol table info. */
108 BFD_MACH_O_LC_LOAD_DYLIB = 0xc, /* Load a dynamically linked shared library. */
109 BFD_MACH_O_LC_ID_DYLIB = 0xd, /* Dynamically linked shared lib identification. */
110 BFD_MACH_O_LC_LOAD_DYLINKER = 0xe, /* Load a dynamic linker. */
111 BFD_MACH_O_LC_ID_DYLINKER = 0xf, /* Dynamic linker identification. */
112 BFD_MACH_O_LC_PREBOUND_DYLIB = 0x10, /* Modules prebound for a dynamically. */
113 BFD_MACH_O_LC_ROUTINES = 0x11, /* Image routines. */
114 BFD_MACH_O_LC_SUB_FRAMEWORK = 0x12, /* Sub framework. */
115 BFD_MACH_O_LC_SUB_UMBRELLA = 0x13, /* Sub umbrella. */
116 BFD_MACH_O_LC_SUB_CLIENT = 0x14, /* Sub client. */
117 BFD_MACH_O_LC_SUB_LIBRARY = 0x15, /* Sub library. */
118 BFD_MACH_O_LC_TWOLEVEL_HINTS = 0x16, /* Two-level namespace lookup hints. */
119 BFD_MACH_O_LC_PREBIND_CKSUM = 0x17, /* Prebind checksum. */
120 /* Load a dynamically linked shared library that is allowed to be
3af9a47b 121 missing (weak). */
1e8a024a
TG
122 BFD_MACH_O_LC_LOAD_WEAK_DYLIB = 0x18,
123 BFD_MACH_O_LC_SEGMENT_64 = 0x19, /* 64-bit segment of this file to be
124 mapped. */
15e1c58a
TG
125 BFD_MACH_O_LC_ROUTINES_64 = 0x1a, /* Address of the dyld init routine
126 in a dylib. */
127 BFD_MACH_O_LC_UUID = 0x1b, /* 128-bit UUID of the executable. */
128 BFD_MACH_O_LC_RPATH = 0x1c, /* Run path addiions. */
846b9259
TG
129 BFD_MACH_O_LC_CODE_SIGNATURE = 0x1d, /* Local of code signature. */
130 BFD_MACH_O_LC_SEGMENT_SPLIT_INFO = 0x1e, /* Local of info to split seg. */
131 BFD_MACH_O_LC_REEXPORT_DYLIB = 0x1f, /* Load and re-export lib. */
132 BFD_MACH_O_LC_LAZY_LOAD_DYLIB = 0x20, /* Delay load of lib until use. */
133 BFD_MACH_O_LC_ENCRYPTION_INFO = 0x21 /* Encrypted segment info. */
116c20d2 134}
3af9a47b
NC
135bfd_mach_o_load_command_type;
136
1e8a024a
TG
137#define BFD_MACH_O_CPU_IS64BIT 0x1000000
138
3af9a47b 139typedef enum bfd_mach_o_cpu_type
116c20d2
NC
140{
141 BFD_MACH_O_CPU_TYPE_VAX = 1,
142 BFD_MACH_O_CPU_TYPE_MC680x0 = 6,
143 BFD_MACH_O_CPU_TYPE_I386 = 7,
144 BFD_MACH_O_CPU_TYPE_MIPS = 8,
145 BFD_MACH_O_CPU_TYPE_MC98000 = 10,
146 BFD_MACH_O_CPU_TYPE_HPPA = 11,
147 BFD_MACH_O_CPU_TYPE_ARM = 12,
148 BFD_MACH_O_CPU_TYPE_MC88000 = 13,
149 BFD_MACH_O_CPU_TYPE_SPARC = 14,
150 BFD_MACH_O_CPU_TYPE_I860 = 15,
151 BFD_MACH_O_CPU_TYPE_ALPHA = 16,
1e8a024a
TG
152 BFD_MACH_O_CPU_TYPE_POWERPC = 18,
153 BFD_MACH_O_CPU_TYPE_POWERPC_64 = (BFD_MACH_O_CPU_TYPE_POWERPC | BFD_MACH_O_CPU_IS64BIT),
154 BFD_MACH_O_CPU_TYPE_X86_64 = (BFD_MACH_O_CPU_TYPE_I386 | BFD_MACH_O_CPU_IS64BIT)
116c20d2 155}
3af9a47b
NC
156bfd_mach_o_cpu_type;
157
154a1ee5
TG
158typedef enum bfd_mach_o_cpu_subtype
159{
160 BFD_MACH_O_CPU_SUBTYPE_X86_ALL = 3
161}
162bfd_mach_o_cpu_subtype;
163
3af9a47b 164typedef enum bfd_mach_o_filetype
116c20d2
NC
165{
166 BFD_MACH_O_MH_OBJECT = 1,
167 BFD_MACH_O_MH_EXECUTE = 2,
168 BFD_MACH_O_MH_FVMLIB = 3,
169 BFD_MACH_O_MH_CORE = 4,
170 BFD_MACH_O_MH_PRELOAD = 5,
171 BFD_MACH_O_MH_DYLIB = 6,
172 BFD_MACH_O_MH_DYLINKER = 7,
173 BFD_MACH_O_MH_BUNDLE = 8
174}
3af9a47b
NC
175bfd_mach_o_filetype;
176
046b007d
TG
177typedef enum bfd_mach_o_header_flags
178{
179 BFD_MACH_O_MH_NOUNDEFS = 0x000001,
180 BFD_MACH_O_MH_INCRLINK = 0x000002,
181 BFD_MACH_O_MH_DYLDLINK = 0x000004,
182 BFD_MACH_O_MH_BINDATLOAD = 0x000008,
183 BFD_MACH_O_MH_PREBOUND = 0x000010,
184 BFD_MACH_O_MH_SPLIT_SEGS = 0x000020,
185 BFD_MACH_O_MH_LAZY_INIT = 0x000040,
186 BFD_MACH_O_MH_TWOLEVEL = 0x000080,
187 BFD_MACH_O_MH_FORCE_FLAT = 0x000100,
188 BFD_MACH_O_MH_NOMULTIDEFS = 0x000200,
189 BFD_MACH_O_MH_NOFIXPREBINDING = 0x000400,
190 BFD_MACH_O_MH_PREBINDABLE = 0x000800,
191 BFD_MACH_O_MH_ALLMODSBOUND = 0x001000,
192 BFD_MACH_O_MH_SUBSECTIONS_VIA_SYMBOLS = 0x002000,
193 BFD_MACH_O_MH_CANONICAL = 0x004000,
194 BFD_MACH_O_MH_WEAK_DEFINES = 0x008000,
195 BFD_MACH_O_MH_BINDS_TO_WEAK = 0x010000,
196 BFD_MACH_O_MH_ALLOW_STACK_EXECUTION = 0x020000,
197 BFD_MACH_O_MH_ROOT_SAFE = 0x040000,
198 BFD_MACH_O_MH_SETUID_SAFE = 0x080000,
199 BFD_MACH_O_MH_NO_REEXPORTED_DYLIBS = 0x100000,
200 BFD_MACH_O_MH_PIE = 0x200000
201}
202bfd_mach_o_header_flags;
203
3af9a47b
NC
204/* Constants for the type of a section. */
205
206typedef enum bfd_mach_o_section_type
116c20d2
NC
207{
208 /* Regular section. */
209 BFD_MACH_O_S_REGULAR = 0x0,
3af9a47b 210
116c20d2
NC
211 /* Zero fill on demand section. */
212 BFD_MACH_O_S_ZEROFILL = 0x1,
3af9a47b 213
116c20d2
NC
214 /* Section with only literal C strings. */
215 BFD_MACH_O_S_CSTRING_LITERALS = 0x2,
3af9a47b 216
116c20d2
NC
217 /* Section with only 4 byte literals. */
218 BFD_MACH_O_S_4BYTE_LITERALS = 0x3,
3af9a47b 219
116c20d2
NC
220 /* Section with only 8 byte literals. */
221 BFD_MACH_O_S_8BYTE_LITERALS = 0x4,
3af9a47b 222
116c20d2
NC
223 /* Section with only pointers to literals. */
224 BFD_MACH_O_S_LITERAL_POINTERS = 0x5,
3af9a47b 225
116c20d2
NC
226 /* For the two types of symbol pointers sections and the symbol stubs
227 section they have indirect symbol table entries. For each of the
228 entries in the section the indirect symbol table entries, in
229 corresponding order in the indirect symbol table, start at the index
230 stored in the reserved1 field of the section structure. Since the
231 indirect symbol table entries correspond to the entries in the
232 section the number of indirect symbol table entries is inferred from
233 the size of the section divided by the size of the entries in the
234 section. For symbol pointers sections the size of the entries in
235 the section is 4 bytes and for symbol stubs sections the byte size
236 of the stubs is stored in the reserved2 field of the section
237 structure. */
3af9a47b 238
116c20d2
NC
239 /* Section with only non-lazy symbol pointers. */
240 BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS = 0x6,
e84d6fca 241
116c20d2
NC
242 /* Section with only lazy symbol pointers. */
243 BFD_MACH_O_S_LAZY_SYMBOL_POINTERS = 0x7,
e84d6fca 244
92bc0e80
TG
245 /* Section with only symbol stubs, byte size of stub in the reserved2
246 field. */
116c20d2 247 BFD_MACH_O_S_SYMBOL_STUBS = 0x8,
e84d6fca 248
116c20d2 249 /* Section with only function pointers for initialization. */
92bc0e80
TG
250 BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9,
251
252 /* Section with only function pointers for termination. */
253 BFD_MACH_O_S_MOD_FINI_FUNC_POINTERS = 0xa,
254
255 /* Section contains symbols that are coalesced by the linkers. */
256 BFD_MACH_O_S_COALESCED = 0xb,
257
258 /* Zero fill on demand section (possibly larger than 4 GB). */
259 BFD_MACH_O_S_GB_ZEROFILL = 0xc,
260
261 /* Section with only pairs of function pointers for interposing. */
262 BFD_MACH_O_S_INTERPOSING = 0xd,
263
264 /* Section with only 16 byte literals. */
265 BFD_MACH_O_S_16BYTE_LITERALS = 0xe,
266
267 /* Section contains DTrace Object Format. */
268 BFD_MACH_O_S_DTRACE_DOF = 0xf,
269
270 /* Section with only lazy symbol pointers to lazy loaded dylibs. */
271 BFD_MACH_O_S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10
116c20d2 272}
3af9a47b
NC
273bfd_mach_o_section_type;
274
15e1c58a
TG
275/* The flags field of a section structure is separated into two parts a section
276 type and section attributes. The section types are mutually exclusive (it
277 can only have one type) but the section attributes are not (it may have more
278 than one attribute). */
279
280#define BFD_MACH_O_SECTION_TYPE_MASK 0x000000ff
281
282/* Constants for the section attributes part of the flags field of a section
283 structure. */
284#define BFD_MACH_O_SECTION_ATTRIBUTES_MASK 0xffffff00
285/* System setable attributes. */
286#define BFD_MACH_O_SECTION_ATTRIBUTES_SYS 0x00ffff00
287/* User attributes. */
288#define BFD_MACH_O_SECTION_ATTRIBUTES_USR 0xff000000
289
046b007d
TG
290typedef enum bfd_mach_o_section_attribute
291{
292 /* Section has local relocation entries. */
293 BFD_MACH_O_S_ATTR_LOC_RELOC = 0x00000100,
15e1c58a 294
046b007d
TG
295 /* Section has external relocation entries. */
296 BFD_MACH_O_S_ATTR_EXT_RELOC = 0x00000200,
15e1c58a 297
046b007d
TG
298 /* Section contains some machine instructions. */
299 BFD_MACH_O_S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
15e1c58a 300
046b007d
TG
301 /* A debug section. */
302 BFD_MACH_O_S_ATTR_DEBUG = 0x02000000,
92bc0e80 303
046b007d
TG
304 /* Used with i386 stubs. */
305 BFD_MACH_O_S_SELF_MODIFYING_CODE = 0x04000000,
306
307 /* Blocks are live if they reference live blocks. */
308 BFD_MACH_O_S_ATTR_LIVE_SUPPORT = 0x08000000,
92bc0e80 309
046b007d
TG
310 /* No dead stripping. */
311 BFD_MACH_O_S_ATTR_NO_DEAD_STRIP = 0x10000000,
92bc0e80 312
046b007d
TG
313 /* Section symbols can be stripped in files with MH_DYLDLINK flag. */
314 BFD_MACH_O_S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
92bc0e80 315
046b007d
TG
316 /* Section contains coalesced symbols that are not to be in the TOC of an
317 archive. */
318 BFD_MACH_O_S_ATTR_NO_TOC = 0x40000000,
92bc0e80 319
046b007d
TG
320 /* Section contains only true machine instructions. */
321 BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS = 0x80000000
322}
323bfd_mach_o_section_attribute;
15e1c58a 324
3af9a47b
NC
325typedef struct bfd_mach_o_header
326{
327 unsigned long magic;
328 unsigned long cputype;
329 unsigned long cpusubtype;
330 unsigned long filetype;
331 unsigned long ncmds;
332 unsigned long sizeofcmds;
333 unsigned long flags;
1e8a024a
TG
334 unsigned int reserved;
335 /* Version 1: 32 bits, version 2: 64 bits. */
336 unsigned int version;
3af9a47b
NC
337 enum bfd_endian byteorder;
338}
339bfd_mach_o_header;
340
154a1ee5
TG
341#define BFD_MACH_O_HEADER_SIZE 28
342#define BFD_MACH_O_HEADER_64_SIZE 32
343
3af9a47b
NC
344typedef struct bfd_mach_o_section
345{
346 asection *bfdsection;
347 char sectname[16 + 1];
348 char segname[16 + 1];
349 bfd_vma addr;
350 bfd_vma size;
351 bfd_vma offset;
352 unsigned long align;
353 bfd_vma reloff;
354 unsigned long nreloc;
355 unsigned long flags;
356 unsigned long reserved1;
357 unsigned long reserved2;
1e8a024a 358 unsigned long reserved3;
3af9a47b
NC
359}
360bfd_mach_o_section;
154a1ee5
TG
361#define BFD_MACH_O_SECTION_SIZE 68
362#define BFD_MACH_O_SECTION_64_SIZE 80
3af9a47b
NC
363
364typedef struct bfd_mach_o_segment_command
365{
15e1c58a 366 char segname[16 + 1];
3af9a47b
NC
367 bfd_vma vmaddr;
368 bfd_vma vmsize;
369 bfd_vma fileoff;
370 unsigned long filesize;
15e1c58a
TG
371 unsigned long maxprot; /* Maximum permitted protection. */
372 unsigned long initprot; /* Initial protection. */
3af9a47b
NC
373 unsigned long nsects;
374 unsigned long flags;
375 bfd_mach_o_section *sections;
376 asection *segment;
377}
378bfd_mach_o_segment_command;
154a1ee5
TG
379#define BFD_MACH_O_LC_SEGMENT_SIZE 56
380#define BFD_MACH_O_LC_SEGMENT_64_SIZE 72
3af9a47b 381
15e1c58a
TG
382/* Protection flags. */
383#define BFD_MACH_O_PROT_READ 0x01
384#define BFD_MACH_O_PROT_WRITE 0x02
385#define BFD_MACH_O_PROT_EXECUTE 0x04
386
92bc0e80
TG
387/* Generic relocation types (used by i386). */
388#define BFD_MACH_O_GENERIC_RELOC_VANILLA 0
389#define BFD_MACH_O_GENERIC_RELOC_PAIR 1
390#define BFD_MACH_O_GENERIC_RELOC_SECTDIFF 2
391#define BFD_MACH_O_GENERIC_RELOC_PB_LA_PTR 3
392#define BFD_MACH_O_GENERIC_RELOC_LOCAL_SECTDIFF 4
393
394/* Size of a relocation entry. */
395#define BFD_MACH_O_RELENT_SIZE 8
396
397/* Fields for a normal (non-scattered) entry. */
398#define BFD_MACH_O_R_PCREL 0x01000000
399#define BFD_MACH_O_GET_R_LENGTH(s) (((s) >> 25) & 0x3)
400#define BFD_MACH_O_R_EXTERN 0x08000000
401#define BFD_MACH_O_GET_R_TYPE(s) (((s) >> 28) & 0x0f)
402#define BFD_MACH_O_GET_R_SYMBOLNUM(s) ((s) & 0x00ffffff)
403#define BFD_MACH_O_SET_R_LENGTH(l) (((l) & 0x3) << 25)
404#define BFD_MACH_O_SET_R_TYPE(t) (((t) & 0xf) << 28)
405#define BFD_MACH_O_SET_R_SYMBOLNUM(s) ((s) & 0x00ffffff)
406
407/* Fields for a scattered entry. */
408#define BFD_MACH_O_SR_SCATTERED 0x80000000
409#define BFD_MACH_O_SR_PCREL 0x40000000
410#define BFD_MACH_O_GET_SR_LENGTH(s) (((s) >> 28) & 0x3)
411#define BFD_MACH_O_GET_SR_TYPE(s) (((s) >> 24) & 0x0f)
412#define BFD_MACH_O_GET_SR_ADDRESS(s) ((s) & 0x00ffffff)
413#define BFD_MACH_O_SET_SR_LENGTH(l) (((l) & 0x3) << 28)
414#define BFD_MACH_O_SET_SR_TYPE(t) (((t) & 0xf) << 24)
415#define BFD_MACH_O_SET_SR_ADDRESS(s) ((s) & 0x00ffffff)
416
417/* Expanded internal representation of a relocation entry. */
418typedef struct bfd_mach_o_reloc_info
419{
420 bfd_vma r_address;
421 bfd_vma r_value;
422 unsigned int r_scattered : 1;
423 unsigned int r_type : 4;
424 unsigned int r_pcrel : 1;
425 unsigned int r_length : 2;
426 unsigned int r_extern : 1;
427}
428bfd_mach_o_reloc_info;
429
430typedef struct bfd_mach_o_asymbol
431{
432 /* The actual symbol which the rest of BFD works with. */
433 asymbol symbol;
434
435 /* Fields from Mach-O symbol. */
436 unsigned char n_type;
437 unsigned char n_sect;
438 unsigned short n_desc;
439}
440bfd_mach_o_asymbol;
046b007d
TG
441#define BFD_MACH_O_NLIST_SIZE 12
442#define BFD_MACH_O_NLIST_64_SIZE 16
92bc0e80 443
3af9a47b
NC
444typedef struct bfd_mach_o_symtab_command
445{
92bc0e80
TG
446 unsigned int symoff;
447 unsigned int nsyms;
448 unsigned int stroff;
449 unsigned int strsize;
450 bfd_mach_o_asymbol *symbols;
3af9a47b 451 char *strtab;
3af9a47b
NC
452}
453bfd_mach_o_symtab_command;
454
455/* This is the second set of the symbolic information which is used to support
7dee875e 456 the data structures for the dynamically link editor.
e84d6fca 457
3af9a47b
NC
458 The original set of symbolic information in the symtab_command which contains
459 the symbol and string tables must also be present when this load command is
460 present. When this load command is present the symbol table is organized
461 into three groups of symbols:
462 local symbols (static and debugging symbols) - grouped by module
463 defined external symbols - grouped by module (sorted by name if not lib)
464 undefined external symbols (sorted by name)
465 In this load command there are offsets and counts to each of the three groups
466 of symbols.
e84d6fca 467
3af9a47b
NC
468 This load command contains a the offsets and sizes of the following new
469 symbolic information tables:
470 table of contents
471 module table
472 reference symbol table
473 indirect symbol table
474 The first three tables above (the table of contents, module table and
7dee875e 475 reference symbol table) are only present if the file is a dynamically linked
3af9a47b
NC
476 shared library. For executable and object modules, which are files
477 containing only one module, the information that would be in these three
478 tables is determined as follows:
479 table of contents - the defined external symbols are sorted by name
480 module table - the file contains only one module so everything in the
481 file is part of the module.
482 reference symbol table - is the defined and undefined external symbols
e84d6fca 483
7dee875e 484 For dynamically linked shared library files this load command also contains
3af9a47b
NC
485 offsets and sizes to the pool of relocation entries for all sections
486 separated into two groups:
487 external relocation entries
488 local relocation entries
489 For executable and object modules the relocation entries continue to hang
490 off the section structures. */
491
046b007d
TG
492typedef struct bfd_mach_o_dylib_module
493{
494 /* Index into the string table indicating the name of the module. */
495 unsigned long module_name_idx;
496 char *module_name;
497
498 /* Index into the symbol table of the first defined external symbol provided
499 by the module. */
500 unsigned long iextdefsym;
501
502 /* Number of external symbols provided by this module. */
503 unsigned long nextdefsym;
504
505 /* Index into the external reference table of the first entry
506 provided by this module. */
507 unsigned long irefsym;
508
509 /* Number of external reference entries provided by this module. */
510 unsigned long nrefsym;
511
512 /* Index into the symbol table of the first local symbol provided by this
513 module. */
514 unsigned long ilocalsym;
515
516 /* Number of local symbols provided by this module. */
517 unsigned long nlocalsym;
518
519 /* Index into the external relocation table of the first entry provided
520 by this module. */
521 unsigned long iextrel;
522
523 /* Number of external relocation entries provided by this module. */
524 unsigned long nextrel;
525
526 /* Index in the module initialization section to the pointers for this
527 module. */
528 unsigned short iinit;
529
530 /* Index in the module termination section to the pointers for this
531 module. */
532 unsigned short iterm;
533
534 /* Number of pointers in the module initialization for this module. */
535 unsigned short ninit;
536
537 /* Number of pointers in the module termination for this module. */
538 unsigned short nterm;
539
540 /* Number of data byte for this module that are used in the __module_info
541 section of the __OBJC segment. */
542 unsigned long objc_module_info_size;
543
544 /* Statically linked address of the start of the data for this module
545 in the __module_info section of the __OBJC_segment. */
546 bfd_vma objc_module_info_addr;
547}
548bfd_mach_o_dylib_module;
549#define BFD_MACH_O_DYLIB_MODULE_SIZE 52
550#define BFD_MACH_O_DYLIB_MODULE_64_SIZE 56
551
552typedef struct bfd_mach_o_dylib_table_of_content
553{
554 /* Index into the symbol table to the defined external symbol. */
555 unsigned long symbol_index;
556
557 /* Index into the module table to the module for this entry. */
558 unsigned long module_index;
559}
560bfd_mach_o_dylib_table_of_content;
561#define BFD_MACH_O_TABLE_OF_CONTENT_SIZE 8
562
563typedef struct bfd_mach_o_dylib_reference
564{
565 /* Index into the symbol table for the symbol being referenced. */
566 unsigned long isym;
567
568 /* Type of the reference being made (use REFERENCE_FLAGS constants). */
569 unsigned long flags;
570}
571bfd_mach_o_dylib_reference;
572#define BFD_MACH_O_REFERENCE_SIZE 4
573
3af9a47b
NC
574typedef struct bfd_mach_o_dysymtab_command
575{
576 /* The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
577 are grouped into the following three groups:
578 local symbols (further grouped by the module they are from)
579 defined external symbols (further grouped by the module they are from)
580 undefined symbols
e84d6fca 581
3af9a47b
NC
582 The local symbols are used only for debugging. The dynamic binding
583 process may have to use them to indicate to the debugger the local
584 symbols for a module that is being bound.
e84d6fca 585
3af9a47b
NC
586 The last two groups are used by the dynamic binding process to do the
587 binding (indirectly through the module table and the reference symbol
7dee875e 588 table when this is a dynamically linked shared library file). */
3af9a47b
NC
589
590 unsigned long ilocalsym; /* Index to local symbols. */
591 unsigned long nlocalsym; /* Number of local symbols. */
592 unsigned long iextdefsym; /* Index to externally defined symbols. */
593 unsigned long nextdefsym; /* Number of externally defined symbols. */
594 unsigned long iundefsym; /* Index to undefined symbols. */
595 unsigned long nundefsym; /* Number of undefined symbols. */
596
597 /* For the for the dynamic binding process to find which module a symbol
598 is defined in the table of contents is used (analogous to the ranlib
599 structure in an archive) which maps defined external symbols to modules
7dee875e 600 they are defined in. This exists only in a dynamically linked shared
3af9a47b
NC
601 library file. For executable and object modules the defined external
602 symbols are sorted by name and is use as the table of contents. */
603
604 unsigned long tocoff; /* File offset to table of contents. */
605 unsigned long ntoc; /* Number of entries in table of contents. */
606
607 /* To support dynamic binding of "modules" (whole object files) the symbol
608 table must reflect the modules that the file was created from. This is
609 done by having a module table that has indexes and counts into the merged
610 tables for each module. The module structure that these two entries
7dee875e 611 refer to is described below. This exists only in a dynamically linked
3af9a47b
NC
612 shared library file. For executable and object modules the file only
613 contains one module so everything in the file belongs to the module. */
614
615 unsigned long modtaboff; /* File offset to module table. */
616 unsigned long nmodtab; /* Number of module table entries. */
617
618 /* To support dynamic module binding the module structure for each module
619 indicates the external references (defined and undefined) each module
620 makes. For each module there is an offset and a count into the
621 reference symbol table for the symbols that the module references.
7dee875e 622 This exists only in a dynamically linked shared library file. For
3af9a47b
NC
623 executable and object modules the defined external symbols and the
624 undefined external symbols indicates the external references. */
625
626 unsigned long extrefsymoff; /* Offset to referenced symbol table. */
627 unsigned long nextrefsyms; /* Number of referenced symbol table entries. */
628
629 /* The sections that contain "symbol pointers" and "routine stubs" have
630 indexes and (implied counts based on the size of the section and fixed
631 size of the entry) into the "indirect symbol" table for each pointer
632 and stub. For every section of these two types the index into the
633 indirect symbol table is stored in the section header in the field
634 reserved1. An indirect symbol table entry is simply a 32bit index into
635 the symbol table to the symbol that the pointer or stub is referring to.
636 The indirect symbol table is ordered to match the entries in the section. */
637
638 unsigned long indirectsymoff; /* File offset to the indirect symbol table. */
639 unsigned long nindirectsyms; /* Number of indirect symbol table entries. */
640
641 /* To support relocating an individual module in a library file quickly the
642 external relocation entries for each module in the library need to be
643 accessed efficiently. Since the relocation entries can't be accessed
644 through the section headers for a library file they are separated into
645 groups of local and external entries further grouped by module. In this
646 case the presents of this load command who's extreloff, nextrel,
647 locreloff and nlocrel fields are non-zero indicates that the relocation
648 entries of non-merged sections are not referenced through the section
649 structures (and the reloff and nreloc fields in the section headers are
650 set to zero).
651
652 Since the relocation entries are not accessed through the section headers
653 this requires the r_address field to be something other than a section
654 offset to identify the item to be relocated. In this case r_address is
655 set to the offset from the vmaddr of the first LC_SEGMENT command.
656
657 The relocation entries are grouped by module and the module table
658 entries have indexes and counts into them for the group of external
659 relocation entries for that the module.
660
661 For sections that are merged across modules there must not be any
662 remaining external relocation entries for them (for merged sections
663 remaining relocation entries must be local). */
664
665 unsigned long extreloff; /* Offset to external relocation entries. */
666 unsigned long nextrel; /* Number of external relocation entries. */
667
668 /* All the local relocation entries are grouped together (they are not
669 grouped by their module since they are only used if the object is moved
7dee875e 670 from it statically link edited address). */
3af9a47b
NC
671
672 unsigned long locreloff; /* Offset to local relocation entries. */
673 unsigned long nlocrel; /* Number of local relocation entries. */
046b007d
TG
674
675 bfd_mach_o_dylib_module *dylib_module;
676 bfd_mach_o_dylib_table_of_content *dylib_toc;
677 unsigned int *indirect_syms;
678 bfd_mach_o_dylib_reference *ext_refs;
3af9a47b 679}
e84d6fca 680bfd_mach_o_dysymtab_command;
3af9a47b 681
e84d6fca 682/* An indirect symbol table entry is simply a 32bit index into the symbol table
3af9a47b 683 to the symbol that the pointer or stub is refering to. Unless it is for a
046b007d 684 non-lazy symbol pointer section for a defined symbol which strip(1) has
3af9a47b
NC
685 removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the
686 symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. */
687
15e1c58a
TG
688#define BFD_MACH_O_INDIRECT_SYMBOL_LOCAL 0x80000000
689#define BFD_MACH_O_INDIRECT_SYMBOL_ABS 0x40000000
046b007d 690#define BFD_MACH_O_INDIRECT_SYMBOL_SIZE 4
3af9a47b
NC
691
692typedef struct bfd_mach_o_thread_flavour
693{
694 unsigned long flavour;
695 bfd_vma offset;
696 unsigned long size;
697}
698bfd_mach_o_thread_flavour;
699
700typedef struct bfd_mach_o_thread_command
701{
702 unsigned long nflavours;
e84d6fca 703 bfd_mach_o_thread_flavour *flavours;
3af9a47b
NC
704 asection *section;
705}
706bfd_mach_o_thread_command;
707
046b007d
TG
708/* For LC_LOAD_DYLINKER and LC_ID_DYLINKER. */
709
3af9a47b
NC
710typedef struct bfd_mach_o_dylinker_command
711{
846b9259
TG
712 unsigned long name_offset; /* Offset to library's path name. */
713 unsigned long name_len; /* Offset to library's path name. */
3af9a47b
NC
714 asection *section;
715}
716bfd_mach_o_dylinker_command;
717
046b007d
TG
718/* For LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, LC_ID_DYLIB
719 or LC_REEXPORT_DYLIB. */
720
3af9a47b
NC
721typedef struct bfd_mach_o_dylib_command
722{
3af9a47b
NC
723 unsigned long name_offset; /* Offset to library's path name. */
724 unsigned long name_len; /* Offset to library's path name. */
725 unsigned long timestamp; /* Library's build time stamp. */
726 unsigned long current_version; /* Library's current version number. */
727 unsigned long compatibility_version; /* Library's compatibility vers number. */
728 asection *section;
729}
730bfd_mach_o_dylib_command;
731
046b007d
TG
732/* For LC_PREBOUND_DYLIB. */
733
3af9a47b
NC
734typedef struct bfd_mach_o_prebound_dylib_command
735{
3af9a47b
NC
736 unsigned long name; /* Library's path name. */
737 unsigned long nmodules; /* Number of modules in library. */
738 unsigned long linked_modules; /* Bit vector of linked modules. */
739 asection *section;
740}
741bfd_mach_o_prebound_dylib_command;
742
046b007d
TG
743/* For LC_UUID. */
744
15e1c58a
TG
745typedef struct bfd_mach_o_uuid_command
746{
046b007d 747 unsigned char uuid[16];
15e1c58a
TG
748 asection *section;
749}
750bfd_mach_o_uuid_command;
751
046b007d
TG
752/* For LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO. */
753
754typedef struct bfd_mach_o_linkedit_command
755{
756 unsigned long dataoff;
757 unsigned long datasize;
758}
759bfd_mach_o_linkedit_command;
760
761typedef struct bfd_mach_o_str_command
762{
763 unsigned long stroff;
764 unsigned long str_len;
765 char *str;
766}
767bfd_mach_o_str_command;
768
3af9a47b
NC
769typedef struct bfd_mach_o_load_command
770{
771 bfd_mach_o_load_command_type type;
154a1ee5 772 bfd_boolean type_required;
92bc0e80
TG
773 unsigned int offset;
774 unsigned int len;
3af9a47b
NC
775 union
776 {
777 bfd_mach_o_segment_command segment;
778 bfd_mach_o_symtab_command symtab;
779 bfd_mach_o_dysymtab_command dysymtab;
780 bfd_mach_o_thread_command thread;
781 bfd_mach_o_dylib_command dylib;
782 bfd_mach_o_dylinker_command dylinker;
783 bfd_mach_o_prebound_dylib_command prebound_dylib;
15e1c58a 784 bfd_mach_o_uuid_command uuid;
046b007d
TG
785 bfd_mach_o_linkedit_command linkedit;
786 bfd_mach_o_str_command str;
3af9a47b
NC
787 }
788 command;
789}
790bfd_mach_o_load_command;
791
792typedef struct mach_o_data_struct
793{
92bc0e80 794 /* Mach-O header. */
3af9a47b 795 bfd_mach_o_header header;
92bc0e80 796 /* Array of load commands (length is given by header.ncmds). */
3af9a47b 797 bfd_mach_o_load_command *commands;
92bc0e80
TG
798
799 /* Flatten array of sections. The array is 0-based. */
3af9a47b
NC
800 unsigned long nsects;
801 bfd_mach_o_section **sections;
92bc0e80
TG
802
803 /* Used while writting: current length of the output file. This is used
804 to allocate space in the file. */
805 ufile_ptr filelen;
046b007d
TG
806
807 /* As symtab is referenced by other load command, it is handy to have
808 a direct access to it. Also it is not clearly stated, only one symtab
809 is expected. */
810 bfd_mach_o_symtab_command *symtab;
3af9a47b 811}
046b007d 812bfd_mach_o_data_struct;
3af9a47b 813
92bc0e80
TG
814/* Target specific routines. */
815typedef struct bfd_mach_o_backend_data
816{
817 bfd_boolean (*_bfd_mach_o_swap_reloc_in)(arelent *, bfd_mach_o_reloc_info *);
818 bfd_boolean (*_bfd_mach_o_swap_reloc_out)(arelent *, bfd_mach_o_reloc_info *);
819}
820bfd_mach_o_backend_data;
15e1c58a 821
046b007d 822#define bfd_mach_o_get_data(abfd) ((abfd)->tdata.mach_o_data)
92bc0e80
TG
823#define bfd_mach_o_get_backend_data(abfd) \
824 ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
3af9a47b 825
154a1ee5 826bfd_boolean bfd_mach_o_valid (bfd *);
92bc0e80 827int bfd_mach_o_scan_read_dysymtab_symbol (bfd *, bfd_mach_o_dysymtab_command *, bfd_mach_o_symtab_command *, bfd_mach_o_asymbol *, unsigned long);
154a1ee5
TG
828int bfd_mach_o_scan_start_address (bfd *);
829int bfd_mach_o_scan (bfd *, bfd_mach_o_header *, bfd_mach_o_data_struct *);
830bfd_boolean bfd_mach_o_mkobject_init (bfd *);
831const bfd_target *bfd_mach_o_object_p (bfd *);
832const bfd_target *bfd_mach_o_core_p (bfd *);
833const bfd_target *bfd_mach_o_archive_p (bfd *);
834bfd *bfd_mach_o_openr_next_archived_file (bfd *, bfd *);
835int bfd_mach_o_lookup_section (bfd *, asection *, bfd_mach_o_load_command **, bfd_mach_o_section **);
836int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type, bfd_mach_o_load_command **);
837bfd_boolean bfd_mach_o_write_contents (bfd *);
838bfd_boolean bfd_mach_o_bfd_copy_private_symbol_data (bfd *, asymbol *,
839 bfd *, asymbol *);
840bfd_boolean bfd_mach_o_bfd_copy_private_section_data (bfd *, asection *,
841 bfd *, asection *);
842bfd_boolean bfd_mach_o_bfd_copy_private_bfd_data (bfd *, bfd *);
843long bfd_mach_o_get_symtab_upper_bound (bfd *);
844long bfd_mach_o_canonicalize_symtab (bfd *, asymbol **);
92bc0e80
TG
845long bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED,
846 asection *asect);
847long bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
848 arelent **rels, asymbol **syms);
154a1ee5
TG
849asymbol *bfd_mach_o_make_empty_symbol (bfd *);
850void bfd_mach_o_get_symbol_info (bfd *, asymbol *, symbol_info *);
851void bfd_mach_o_print_symbol (bfd *, PTR, asymbol *, bfd_print_symbol_type);
852bfd_boolean bfd_mach_o_bfd_print_private_bfd_data (bfd *, PTR);
853int bfd_mach_o_sizeof_headers (bfd *, struct bfd_link_info *);
854unsigned long bfd_mach_o_stack_addr (enum bfd_mach_o_cpu_type);
855int bfd_mach_o_core_fetch_environment (bfd *, unsigned char **, unsigned int *);
856char *bfd_mach_o_core_file_failing_command (bfd *);
857int bfd_mach_o_core_file_failing_signal (bfd *);
858bfd_boolean bfd_mach_o_core_file_matches_executable_p (bfd *, bfd *);
846b9259 859bfd *bfd_mach_o_fat_extract (bfd *, bfd_format , const bfd_arch_info_type *);
154a1ee5
TG
860const bfd_target *bfd_mach_o_header_p (bfd *, bfd_mach_o_filetype,
861 bfd_mach_o_cpu_type);
862bfd_boolean bfd_mach_o_build_commands (bfd *abfd);
863bfd_boolean bfd_mach_o_set_section_contents (bfd *, asection *, const void *,
864 file_ptr, bfd_size_type);
c2f09c75 865unsigned int bfd_mach_o_version (bfd *);
3af9a47b 866
3af9a47b
NC
867extern const bfd_target mach_o_fat_vec;
868
869#endif /* _BFD_MACH_O_H_ */
This page took 0.403392 seconds and 4 git commands to generate.