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