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