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