bfd/
[external/binutils.git] / bfd / mach-o.h
1 /* Mach-O support for BFD.
2    Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2011,
3    2012
4    Free Software Foundation, Inc.
5
6    This file is part of BFD, the Binary File Descriptor library.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21    MA 02110-1301, USA.  */
22
23 #ifndef _BFD_MACH_O_H_
24 #define _BFD_MACH_O_H_
25
26 #include "bfd.h"
27 #include "mach-o/loader.h"
28
29 typedef struct bfd_mach_o_header
30 {
31   unsigned long magic;
32   unsigned long cputype;
33   unsigned long cpusubtype;
34   unsigned long filetype;
35   unsigned long ncmds;
36   unsigned long sizeofcmds;
37   unsigned long flags;
38   unsigned int reserved;
39   /* Version 1: 32 bits, version 2: 64 bits.  */
40   unsigned int version;
41   enum bfd_endian byteorder;
42 }
43 bfd_mach_o_header;
44
45 #define BFD_MACH_O_SEGNAME_SIZE 16
46 #define BFD_MACH_O_SECTNAME_SIZE 16
47
48 typedef struct bfd_mach_o_section
49 {
50   /* Fields present in the file.  */
51   char sectname[BFD_MACH_O_SECTNAME_SIZE + 1];  /* Always NUL padded.  */
52   char segname[BFD_MACH_O_SEGNAME_SIZE + 1];
53   bfd_vma addr;
54   bfd_vma size;
55   bfd_vma offset;
56   unsigned long align;
57   bfd_vma reloff;
58   unsigned long nreloc;
59   unsigned long flags;
60   unsigned long reserved1;
61   unsigned long reserved2;
62   unsigned long reserved3;
63
64   /* Corresponding bfd section.  */
65   asection *bfdsection;
66
67   /* Simply linked list.  */
68   struct bfd_mach_o_section *next;
69 }
70 bfd_mach_o_section;
71
72 typedef struct bfd_mach_o_segment_command
73 {
74   char segname[BFD_MACH_O_SEGNAME_SIZE + 1];
75   bfd_vma vmaddr;
76   bfd_vma vmsize;
77   bfd_vma fileoff;
78   unsigned long filesize;
79   unsigned long maxprot;        /* Maximum permitted protection.  */
80   unsigned long initprot;       /* Initial protection.  */
81   unsigned long nsects;
82   unsigned long flags;
83
84   /* Linked list of sections.  */
85   bfd_mach_o_section *sect_head;
86   bfd_mach_o_section *sect_tail;
87 }
88 bfd_mach_o_segment_command;
89
90 /* Protection flags.  */
91 #define BFD_MACH_O_PROT_READ    0x01
92 #define BFD_MACH_O_PROT_WRITE   0x02
93 #define BFD_MACH_O_PROT_EXECUTE 0x04
94
95 /* Expanded internal representation of a relocation entry.  */
96 typedef struct bfd_mach_o_reloc_info
97 {
98   bfd_vma r_address;
99   bfd_vma r_value;
100   unsigned int r_scattered : 1;
101   unsigned int r_type : 4;
102   unsigned int r_pcrel : 1;
103   unsigned int r_length : 2;
104   unsigned int r_extern : 1;
105 }
106 bfd_mach_o_reloc_info;
107
108 typedef struct bfd_mach_o_asymbol
109 {
110   /* The actual symbol which the rest of BFD works with.  */
111   asymbol symbol;
112
113   /* Mach-O symbol fields.  */
114   unsigned char n_type;
115   unsigned char n_sect;
116   unsigned short n_desc;
117 }
118 bfd_mach_o_asymbol;
119
120 /* The symbol table is sorted like this:
121  (1) local.
122         (otherwise in order of generation)
123  (2) external defined
124         (sorted by name)
125  (3) external undefined
126         (sorted by name)
127  (4) common
128         (sorted by name)
129 */
130
131 typedef struct bfd_mach_o_symtab_command
132 {
133   unsigned int symoff;
134   unsigned int nsyms;
135   unsigned int stroff;
136   unsigned int strsize;
137   bfd_mach_o_asymbol *symbols;
138   char *strtab;
139 }
140 bfd_mach_o_symtab_command;
141
142 /* This is the second set of the symbolic information which is used to support
143    the data structures for the dynamically link editor.
144
145    The original set of symbolic information in the symtab_command which contains
146    the symbol and string tables must also be present when this load command is
147    present.  When this load command is present the symbol table is organized
148    into three groups of symbols:
149        local symbols (static and debugging symbols) - grouped by module
150        defined external symbols - grouped by module (sorted by name if not lib)
151        undefined external symbols (sorted by name)
152    In this load command there are offsets and counts to each of the three groups
153    of symbols.
154
155    This load command contains a the offsets and sizes of the following new
156    symbolic information tables:
157        table of contents
158        module table
159        reference symbol table
160        indirect symbol table
161    The first three tables above (the table of contents, module table and
162    reference symbol table) are only present if the file is a dynamically linked
163    shared library.  For executable and object modules, which are files
164    containing only one module, the information that would be in these three
165    tables is determined as follows:
166        table of contents - the defined external symbols are sorted by name
167        module table - the file contains only one module so everything in the
168                       file is part of the module.
169        reference symbol table - is the defined and undefined external symbols
170
171    For dynamically linked shared library files this load command also contains
172    offsets and sizes to the pool of relocation entries for all sections
173    separated into two groups:
174        external relocation entries
175        local relocation entries
176    For executable and object modules the relocation entries continue to hang
177    off the section structures.  */
178
179 typedef struct bfd_mach_o_dylib_module
180 {
181   /* Index into the string table indicating the name of the module.  */
182   unsigned long module_name_idx;
183   char *module_name;
184
185   /* Index into the symbol table of the first defined external symbol provided
186      by the module.  */
187   unsigned long iextdefsym;
188
189   /* Number of external symbols provided by this module.  */
190   unsigned long nextdefsym;
191
192   /* Index into the external reference table of the first entry
193      provided by this module.  */
194   unsigned long irefsym;
195
196   /* Number of external reference entries provided by this module.  */
197   unsigned long nrefsym;
198
199   /* Index into the symbol table of the first local symbol provided by this
200      module.  */
201   unsigned long ilocalsym;
202
203   /* Number of local symbols provided by this module.  */
204   unsigned long nlocalsym;
205
206   /* Index into the external relocation table of the first entry provided
207      by this module.  */
208   unsigned long iextrel;
209
210   /* Number of external relocation entries provided by this module.  */
211   unsigned long nextrel;
212
213   /* Index in the module initialization section to the pointers for this
214      module.  */
215   unsigned short iinit;
216
217   /* Index in the module termination section to the pointers for this
218      module.  */
219   unsigned short iterm;
220
221   /* Number of pointers in the module initialization for this module.  */
222   unsigned short ninit;
223
224   /* Number of pointers in the module termination for this module.  */
225   unsigned short nterm;
226
227   /* Number of data byte for this module that are used in the __module_info
228      section of the __OBJC segment.  */
229   unsigned long objc_module_info_size;
230
231   /* Statically linked address of the start of the data for this module
232      in the __module_info section of the __OBJC_segment.  */
233   bfd_vma objc_module_info_addr;
234 }
235 bfd_mach_o_dylib_module;
236
237 typedef struct bfd_mach_o_dylib_table_of_content
238 {
239   /* Index into the symbol table to the defined external symbol.  */
240   unsigned long symbol_index;
241
242   /* Index into the module table to the module for this entry.  */
243   unsigned long module_index;
244 }
245 bfd_mach_o_dylib_table_of_content;
246
247 typedef struct bfd_mach_o_dylib_reference
248 {
249   /* Index into the symbol table for the symbol being referenced.  */
250   unsigned long isym;
251
252   /* Type of the reference being made (use REFERENCE_FLAGS constants).  */
253   unsigned long flags;
254 }
255 bfd_mach_o_dylib_reference;
256 #define BFD_MACH_O_REFERENCE_SIZE 4
257
258 typedef struct bfd_mach_o_dysymtab_command
259 {
260   /* The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
261      are grouped into the following three groups:
262        local symbols (further grouped by the module they are from)
263        defined external symbols (further grouped by the module they are from)
264        undefined symbols
265
266      The local symbols are used only for debugging.  The dynamic binding
267      process may have to use them to indicate to the debugger the local
268      symbols for a module that is being bound.
269
270      The last two groups are used by the dynamic binding process to do the
271      binding (indirectly through the module table and the reference symbol
272      table when this is a dynamically linked shared library file).  */
273
274   unsigned long ilocalsym;    /* Index to local symbols.  */
275   unsigned long nlocalsym;    /* Number of local symbols.  */
276   unsigned long iextdefsym;   /* Index to externally defined symbols.  */
277   unsigned long nextdefsym;   /* Number of externally defined symbols.  */
278   unsigned long iundefsym;    /* Index to undefined symbols.  */
279   unsigned long nundefsym;    /* Number of undefined symbols.  */
280
281   /* For the for the dynamic binding process to find which module a symbol
282      is defined in the table of contents is used (analogous to the ranlib
283      structure in an archive) which maps defined external symbols to modules
284      they are defined in.  This exists only in a dynamically linked shared
285      library file.  For executable and object modules the defined external
286      symbols are sorted by name and is use as the table of contents.  */
287
288   unsigned long tocoff;       /* File offset to table of contents.  */
289   unsigned long ntoc;         /* Number of entries in table of contents.  */
290
291   /* To support dynamic binding of "modules" (whole object files) the symbol
292      table must reflect the modules that the file was created from.  This is
293      done by having a module table that has indexes and counts into the merged
294      tables for each module.  The module structure that these two entries
295      refer to is described below.  This exists only in a dynamically linked
296      shared library file.  For executable and object modules the file only
297      contains one module so everything in the file belongs to the module.  */
298
299   unsigned long modtaboff;    /* File offset to module table.  */
300   unsigned long nmodtab;      /* Number of module table entries.  */
301
302   /* To support dynamic module binding the module structure for each module
303      indicates the external references (defined and undefined) each module
304      makes.  For each module there is an offset and a count into the
305      reference symbol table for the symbols that the module references.
306      This exists only in a dynamically linked shared library file.  For
307      executable and object modules the defined external symbols and the
308      undefined external symbols indicates the external references.  */
309
310   unsigned long extrefsymoff;  /* Offset to referenced symbol table.  */
311   unsigned long nextrefsyms;   /* Number of referenced symbol table entries.  */
312
313   /* The sections that contain "symbol pointers" and "routine stubs" have
314      indexes and (implied counts based on the size of the section and fixed
315      size of the entry) into the "indirect symbol" table for each pointer
316      and stub.  For every section of these two types the index into the
317      indirect symbol table is stored in the section header in the field
318      reserved1.  An indirect symbol table entry is simply a 32bit index into
319      the symbol table to the symbol that the pointer or stub is referring to.
320      The indirect symbol table is ordered to match the entries in the section.  */
321
322   unsigned long indirectsymoff; /* File offset to the indirect symbol table.  */
323   unsigned long nindirectsyms;  /* Number of indirect symbol table entries.  */
324
325   /* To support relocating an individual module in a library file quickly the
326      external relocation entries for each module in the library need to be
327      accessed efficiently.  Since the relocation entries can't be accessed
328      through the section headers for a library file they are separated into
329      groups of local and external entries further grouped by module.  In this
330      case the presents of this load command who's extreloff, nextrel,
331      locreloff and nlocrel fields are non-zero indicates that the relocation
332      entries of non-merged sections are not referenced through the section
333      structures (and the reloff and nreloc fields in the section headers are
334      set to zero).
335
336      Since the relocation entries are not accessed through the section headers
337      this requires the r_address field to be something other than a section
338      offset to identify the item to be relocated.  In this case r_address is
339      set to the offset from the vmaddr of the first LC_SEGMENT command.
340
341      The relocation entries are grouped by module and the module table
342      entries have indexes and counts into them for the group of external
343      relocation entries for that the module.
344
345      For sections that are merged across modules there must not be any
346      remaining external relocation entries for them (for merged sections
347      remaining relocation entries must be local).  */
348
349   unsigned long extreloff;    /* Offset to external relocation entries.  */
350   unsigned long nextrel;      /* Number of external relocation entries.  */
351
352   /* All the local relocation entries are grouped together (they are not
353      grouped by their module since they are only used if the object is moved
354      from it statically link edited address).  */
355
356   unsigned long locreloff;    /* Offset to local relocation entries.  */
357   unsigned long nlocrel;      /* Number of local relocation entries.  */
358
359   bfd_mach_o_dylib_module *dylib_module;
360   bfd_mach_o_dylib_table_of_content *dylib_toc;
361   unsigned int *indirect_syms;
362   bfd_mach_o_dylib_reference *ext_refs;
363 }
364 bfd_mach_o_dysymtab_command;
365
366 /* An indirect symbol table entry is simply a 32bit index into the symbol table
367    to the symbol that the pointer or stub is refering to.  Unless it is for a
368    non-lazy symbol pointer section for a defined symbol which strip(1) has
369    removed.  In which case it has the value INDIRECT_SYMBOL_LOCAL.  If the
370    symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.  */
371
372 #define BFD_MACH_O_INDIRECT_SYMBOL_LOCAL 0x80000000
373 #define BFD_MACH_O_INDIRECT_SYMBOL_ABS   0x40000000
374 #define BFD_MACH_O_INDIRECT_SYMBOL_SIZE  4
375
376 /* For LC_THREAD or LC_UNIXTHREAD.  */
377
378 typedef struct bfd_mach_o_thread_flavour
379 {
380   unsigned long flavour;
381   unsigned long offset;
382   unsigned long size;
383 }
384 bfd_mach_o_thread_flavour;
385
386 typedef struct bfd_mach_o_thread_command
387 {
388   unsigned long nflavours;
389   bfd_mach_o_thread_flavour *flavours;
390   asection *section;
391 }
392 bfd_mach_o_thread_command;
393
394 /* For LC_LOAD_DYLINKER and LC_ID_DYLINKER.  */
395
396 typedef struct bfd_mach_o_dylinker_command
397 {
398   unsigned long name_offset;         /* Offset to library's path name.  */
399   unsigned long name_len;            /* Offset to library's path name.  */
400   char *name_str;
401 }
402 bfd_mach_o_dylinker_command;
403
404 /* For LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, LC_ID_DYLIB
405    or LC_REEXPORT_DYLIB.  */
406
407 typedef struct bfd_mach_o_dylib_command
408 {
409   unsigned long name_offset;           /* Offset to library's path name.  */
410   unsigned long name_len;              /* Offset to library's path name.  */
411   unsigned long timestamp;             /* Library's build time stamp.  */
412   unsigned long current_version;       /* Library's current version number.  */
413   unsigned long compatibility_version; /* Library's compatibility vers number.  */
414   char *name_str;
415 }
416 bfd_mach_o_dylib_command;
417
418 /* For LC_PREBOUND_DYLIB.  */
419
420 typedef struct bfd_mach_o_prebound_dylib_command
421 {
422   unsigned long name;                /* Library's path name.  */
423   unsigned long nmodules;            /* Number of modules in library.  */
424   unsigned long linked_modules;      /* Bit vector of linked modules.  */
425 }
426 bfd_mach_o_prebound_dylib_command;
427
428 /* For LC_UUID.  */
429
430 typedef struct bfd_mach_o_uuid_command
431 {
432   unsigned char uuid[16];
433 }
434 bfd_mach_o_uuid_command;
435
436 /* For LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO.  */
437
438 typedef struct bfd_mach_o_linkedit_command
439 {
440   unsigned long dataoff;
441   unsigned long datasize;
442 }
443 bfd_mach_o_linkedit_command;
444
445 typedef struct bfd_mach_o_str_command
446 {
447   unsigned long stroff;
448   unsigned long str_len;
449   char *str;
450 }
451 bfd_mach_o_str_command;
452
453 typedef struct bfd_mach_o_dyld_info_command
454 {
455   /* File offset and size to rebase info.  */
456   unsigned int rebase_off; 
457   unsigned int rebase_size;
458
459   /* File offset and size of binding info.  */
460   unsigned int bind_off;
461   unsigned int bind_size;
462
463   /* File offset and size of weak binding info.  */
464   unsigned int weak_bind_off;
465   unsigned int weak_bind_size;
466
467   /* File offset and size of lazy binding info.  */
468   unsigned int lazy_bind_off;
469   unsigned int lazy_bind_size;
470
471   /* File offset and size of export info.  */
472   unsigned int export_off;
473   unsigned int export_size;
474 }
475 bfd_mach_o_dyld_info_command;
476
477 typedef struct bfd_mach_o_version_min_command
478 {
479   unsigned char rel;
480   unsigned char maj;
481   unsigned char min;
482   unsigned int reserved;
483 }
484 bfd_mach_o_version_min_command;
485
486 typedef struct bfd_mach_o_encryption_info_command
487 {
488   unsigned int cryptoff;
489   unsigned int cryptsize;
490   unsigned int cryptid;
491 }
492 bfd_mach_o_encryption_info_command;
493
494 typedef struct bfd_mach_o_load_command
495 {
496   bfd_mach_o_load_command_type type;
497   bfd_boolean type_required;
498   unsigned int offset;
499   unsigned int len;
500   union
501   {
502     bfd_mach_o_segment_command segment;
503     bfd_mach_o_symtab_command symtab;
504     bfd_mach_o_dysymtab_command dysymtab;
505     bfd_mach_o_thread_command thread;
506     bfd_mach_o_dylib_command dylib;
507     bfd_mach_o_dylinker_command dylinker;
508     bfd_mach_o_prebound_dylib_command prebound_dylib;
509     bfd_mach_o_uuid_command uuid;
510     bfd_mach_o_linkedit_command linkedit;
511     bfd_mach_o_str_command str;
512     bfd_mach_o_dyld_info_command dyld_info;
513     bfd_mach_o_version_min_command version_min;
514     bfd_mach_o_encryption_info_command encryption_info;
515   }
516   command;
517 }
518 bfd_mach_o_load_command;
519
520 typedef struct mach_o_data_struct
521 {
522   /* Mach-O header.  */
523   bfd_mach_o_header header;
524   /* Array of load commands (length is given by header.ncmds).  */
525   bfd_mach_o_load_command *commands;
526
527   /* Flatten array of sections.  The array is 0-based.  */
528   unsigned long nsects;
529   bfd_mach_o_section **sections;
530
531   /* Used while writing: current length of the output file.  This is used
532      to allocate space in the file.  */
533   ufile_ptr filelen;
534
535   /* As symtab is referenced by other load command, it is handy to have
536      a direct access to it.  Although it is not clearly stated, only one symtab
537      is expected.  */
538   bfd_mach_o_symtab_command *symtab;
539   bfd_mach_o_dysymtab_command *dysymtab;
540
541   /* Base values used for building the dysymtab for a single-module object.  */  
542   unsigned long nlocal;
543   unsigned long ndefext;
544   unsigned long nundefext;
545
546   /* If this is non-zero, then the pointer below is populated.  */
547   unsigned long nindirect;
548   /* A set of synthetic symbols representing the 'indirect' ones in the file.
549      These should be sorted (a) by the section they represent and (b) by the
550      order that they appear within each section.  */
551   asymbol **indirect_syms;
552
553   /* A place to stash dwarf2 info for this bfd.  */
554   void *dwarf2_find_line_info;
555
556   /* BFD of .dSYM file. */
557   bfd *dsym_bfd;
558
559   /* Cache of dynamic relocs. */
560   arelent *dyn_reloc_cache;
561 }
562 bfd_mach_o_data_struct;
563
564 typedef struct bfd_mach_o_xlat_name
565 {
566   const char *name;
567   unsigned long val;
568 }
569 bfd_mach_o_xlat_name;
570
571 /* Target specific routines.  */
572
573 #define bfd_mach_o_get_data(abfd) ((abfd)->tdata.mach_o_data)
574 #define bfd_mach_o_get_backend_data(abfd) \
575   ((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
576
577 /* Get the Mach-O header for section SEC.  */
578 #define bfd_mach_o_get_mach_o_section(sec) \
579   ((bfd_mach_o_section *)(sec)->used_by_bfd)
580
581 bfd_boolean bfd_mach_o_valid (bfd *);
582 bfd_boolean bfd_mach_o_mkobject_init (bfd *);
583 const bfd_target *bfd_mach_o_object_p (bfd *);
584 const bfd_target *bfd_mach_o_core_p (bfd *);
585 const bfd_target *bfd_mach_o_archive_p (bfd *);
586 bfd *bfd_mach_o_openr_next_archived_file (bfd *, bfd *);
587 bfd_boolean bfd_mach_o_set_arch_mach (bfd *, enum bfd_architecture,
588                                       unsigned long);
589 int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type, bfd_mach_o_load_command **);
590 bfd_boolean bfd_mach_o_new_section_hook (bfd *, asection *);
591 bfd_boolean bfd_mach_o_write_contents (bfd *);
592 bfd_boolean bfd_mach_o_bfd_copy_private_symbol_data (bfd *, asymbol *,
593                                                      bfd *, asymbol *);
594 bfd_boolean bfd_mach_o_bfd_copy_private_section_data (bfd *, asection *,
595                                                       bfd *, asection *);
596 bfd_boolean bfd_mach_o_bfd_copy_private_bfd_data (bfd *, bfd *);
597 bfd_boolean bfd_mach_o_bfd_set_private_flags (bfd *, flagword);
598 long bfd_mach_o_get_symtab_upper_bound (bfd *);
599 long bfd_mach_o_canonicalize_symtab (bfd *, asymbol **);
600 long bfd_mach_o_get_synthetic_symtab (bfd *, long, asymbol **, long, 
601                                       asymbol **, asymbol **ret);
602 long bfd_mach_o_get_reloc_upper_bound (bfd *, asection *);
603 long bfd_mach_o_canonicalize_reloc (bfd *, asection *, arelent **, asymbol **);
604 long bfd_mach_o_get_dynamic_reloc_upper_bound (bfd *);
605 long bfd_mach_o_canonicalize_dynamic_reloc (bfd *, arelent **, asymbol **);
606 asymbol *bfd_mach_o_make_empty_symbol (bfd *);
607 void bfd_mach_o_get_symbol_info (bfd *, asymbol *, symbol_info *);
608 void bfd_mach_o_print_symbol (bfd *, PTR, asymbol *, bfd_print_symbol_type);
609 int bfd_mach_o_sizeof_headers (bfd *, struct bfd_link_info *);
610 unsigned long bfd_mach_o_stack_addr (enum bfd_mach_o_cpu_type);
611 int bfd_mach_o_core_fetch_environment (bfd *, unsigned char **, unsigned int *);
612 char *bfd_mach_o_core_file_failing_command (bfd *);
613 int bfd_mach_o_core_file_failing_signal (bfd *);
614 bfd_boolean bfd_mach_o_core_file_matches_executable_p (bfd *, bfd *);
615 bfd *bfd_mach_o_fat_extract (bfd *, bfd_format , const bfd_arch_info_type *);
616 const bfd_target *bfd_mach_o_header_p (bfd *, bfd_mach_o_filetype,
617                                        bfd_mach_o_cpu_type);
618 bfd_boolean bfd_mach_o_build_commands (bfd *);
619 bfd_boolean bfd_mach_o_set_section_contents (bfd *, asection *, const void *,
620                                              file_ptr, bfd_size_type);
621 unsigned int bfd_mach_o_version (bfd *);
622
623 unsigned int bfd_mach_o_get_section_type_from_name (bfd *, const char *);
624 unsigned int bfd_mach_o_get_section_attribute_from_name (const char *);
625
626 void bfd_mach_o_convert_section_name_to_bfd (bfd *, const char *, const char *,
627                                              const char **, flagword *);
628 bfd_boolean bfd_mach_o_find_nearest_line (bfd *, asection *, asymbol **,
629                                           bfd_vma, const char **,
630                                           const char **, unsigned int *);
631 bfd_boolean bfd_mach_o_close_and_cleanup (bfd *);
632 bfd_boolean bfd_mach_o_free_cached_info (bfd *);
633
634 unsigned int bfd_mach_o_section_get_nbr_indirect (bfd *, bfd_mach_o_section *);
635 unsigned int bfd_mach_o_section_get_entry_size (bfd *, bfd_mach_o_section *);
636 bfd_boolean bfd_mach_o_read_symtab_symbols (bfd *);
637 bfd_boolean bfd_mach_o_read_symtab_strtab (bfd *abfd);
638
639 /* A placeholder in case we need to suppress emitting the dysymtab for some
640    reason (e.g. compatibility with older system versions).  */
641 #define bfd_mach_o_should_emit_dysymtab(x) TRUE
642
643 extern const bfd_mach_o_xlat_name bfd_mach_o_section_attribute_name[];
644 extern const bfd_mach_o_xlat_name bfd_mach_o_section_type_name[];
645
646 extern const bfd_target mach_o_fat_vec;
647
648 /* Interfaces between BFD names and Mach-O names.  */
649
650 typedef struct mach_o_section_name_xlat
651 {
652   const char *bfd_name;
653   const char *mach_o_name;
654   flagword bfd_flags;
655   unsigned int macho_sectype;
656   unsigned int macho_secattr;
657   unsigned int sectalign;
658 } mach_o_section_name_xlat;
659
660 typedef struct mach_o_segment_name_xlat
661 {
662   const char *segname;
663   const mach_o_section_name_xlat *sections;
664 } mach_o_segment_name_xlat;
665
666 const mach_o_section_name_xlat *
667 bfd_mach_o_section_data_for_mach_sect (bfd *, const char *, const char *);
668 const mach_o_section_name_xlat *
669 bfd_mach_o_section_data_for_bfd_name (bfd *, const char *, const char **);
670
671 typedef struct bfd_mach_o_backend_data
672 {
673   enum bfd_architecture arch;
674   bfd_boolean (*_bfd_mach_o_swap_reloc_in)(arelent *, bfd_mach_o_reloc_info *);
675   bfd_boolean (*_bfd_mach_o_swap_reloc_out)(arelent *, bfd_mach_o_reloc_info *);
676   bfd_boolean (*_bfd_mach_o_print_thread)(bfd *, bfd_mach_o_thread_flavour *,
677                                           void *, char *);
678   const mach_o_segment_name_xlat *segsec_names_xlat;
679   bfd_boolean (*bfd_mach_o_section_type_valid_for_target) (unsigned long);
680 }
681 bfd_mach_o_backend_data;
682
683 /* Symbol type tests.  */
684
685 #define IS_MACHO_INDIRECT(x) (((x) & BFD_MACH_O_N_TYPE) == BFD_MACH_O_N_INDR)
686
687 #endif /* _BFD_MACH_O_H_ */