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