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