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