OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [bfd/] [mach-o.h] - Blame information for rev 280

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.