Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5191 | serge | 1 | /* Mach-O support for BFD. |
2 | Copyright 2011, 2012 |
||
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 |
||
9 | the Free Software Foundation; either version 3 of the License, or |
||
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 |
||
18 | along with this program; if not, write to the Free Software |
||
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
||
20 | MA 02110-1301, USA. */ |
||
21 | |||
22 | #ifndef _MACH_O_EXTERNAL_H |
||
23 | #define _MACH_O_EXTERNAL_H |
||
24 | |||
25 | struct mach_o_header_external |
||
26 | { |
||
27 | unsigned char magic[4]; /* Magic number. */ |
||
28 | unsigned char cputype[4]; /* CPU that this object is for. */ |
||
29 | unsigned char cpusubtype[4]; /* CPU subtype. */ |
||
30 | unsigned char filetype[4]; /* Type of file. */ |
||
31 | unsigned char ncmds[4]; /* Number of load commands. */ |
||
32 | unsigned char sizeofcmds[4]; /* Total size of load commands. */ |
||
33 | unsigned char flags[4]; /* Flags. */ |
||
34 | unsigned char reserved[4]; /* Reserved (on 64-bit version only). */ |
||
35 | }; |
||
36 | |||
37 | #define BFD_MACH_O_HEADER_SIZE 28 |
||
38 | #define BFD_MACH_O_HEADER_64_SIZE 32 |
||
39 | |||
40 | /* 32-bit section header. */ |
||
41 | |||
42 | struct mach_o_section_32_external |
||
43 | { |
||
44 | unsigned char sectname[16]; /* Section name. */ |
||
45 | unsigned char segname[16]; /* Segment that the section belongs to. */ |
||
46 | unsigned char addr[4]; /* Address of this section in memory. */ |
||
47 | unsigned char size[4]; /* Size in bytes of this section. */ |
||
48 | unsigned char offset[4]; /* File offset of this section. */ |
||
49 | unsigned char align[4]; /* log2 of this section's alignment. */ |
||
50 | unsigned char reloff[4]; /* File offset of this section's relocs. */ |
||
51 | unsigned char nreloc[4]; /* Number of relocs for this section. */ |
||
52 | unsigned char flags[4]; /* Section flags/attributes. */ |
||
53 | unsigned char reserved1[4]; |
||
54 | unsigned char reserved2[4]; |
||
55 | }; |
||
56 | #define BFD_MACH_O_SECTION_SIZE 68 |
||
57 | |||
58 | /* 64-bit section header. */ |
||
59 | |||
60 | struct mach_o_section_64_external |
||
61 | { |
||
62 | unsigned char sectname[16]; /* Section name. */ |
||
63 | unsigned char segname[16]; /* Segment that the section belongs to. */ |
||
64 | unsigned char addr[8]; /* Address of this section in memory. */ |
||
65 | unsigned char size[8]; /* Size in bytes of this section. */ |
||
66 | unsigned char offset[4]; /* File offset of this section. */ |
||
67 | unsigned char align[4]; /* log2 of this section's alignment. */ |
||
68 | unsigned char reloff[4]; /* File offset of this section's relocs. */ |
||
69 | unsigned char nreloc[4]; /* Number of relocs for this section. */ |
||
70 | unsigned char flags[4]; /* Section flags/attributes. */ |
||
71 | unsigned char reserved1[4]; |
||
72 | unsigned char reserved2[4]; |
||
73 | unsigned char reserved3[4]; |
||
74 | }; |
||
75 | #define BFD_MACH_O_SECTION_64_SIZE 80 |
||
76 | |||
77 | struct mach_o_load_command_external |
||
78 | { |
||
79 | unsigned char cmd[4]; /* The type of load command. */ |
||
80 | unsigned char cmdsize[4]; /* Size in bytes of entire command. */ |
||
81 | }; |
||
82 | #define BFD_MACH_O_LC_SIZE 8 |
||
83 | |||
84 | struct mach_o_segment_command_32_external |
||
85 | { |
||
86 | unsigned char segname[16]; /* Name of this segment. */ |
||
87 | unsigned char vmaddr[4]; /* Virtual memory address of this segment. */ |
||
88 | unsigned char vmsize[4]; /* Size there, in bytes. */ |
||
89 | unsigned char fileoff[4]; /* Offset in bytes of the data to be mapped. */ |
||
90 | unsigned char filesize[4]; /* Size in bytes on disk. */ |
||
91 | unsigned char maxprot[4]; /* Maximum permitted vm protection. */ |
||
92 | unsigned char initprot[4]; /* Initial vm protection. */ |
||
93 | unsigned char nsects[4]; /* Number of sections in this segment. */ |
||
94 | unsigned char flags[4]; /* Flags that affect the loading. */ |
||
95 | }; |
||
96 | #define BFD_MACH_O_LC_SEGMENT_SIZE 56 /* Include the header. */ |
||
97 | |||
98 | struct mach_o_segment_command_64_external |
||
99 | { |
||
100 | unsigned char segname[16]; /* Name of this segment. */ |
||
101 | unsigned char vmaddr[8]; /* Virtual memory address of this segment. */ |
||
102 | unsigned char vmsize[8]; /* Size there, in bytes. */ |
||
103 | unsigned char fileoff[8]; /* Offset in bytes of the data to be mapped. */ |
||
104 | unsigned char filesize[8]; /* Size in bytes on disk. */ |
||
105 | unsigned char maxprot[4]; /* Maximum permitted vm protection. */ |
||
106 | unsigned char initprot[4]; /* Initial vm protection. */ |
||
107 | unsigned char nsects[4]; /* Number of sections in this segment. */ |
||
108 | unsigned char flags[4]; /* Flags that affect the loading. */ |
||
109 | }; |
||
110 | #define BFD_MACH_O_LC_SEGMENT_64_SIZE 72 /* Include the header. */ |
||
111 | |||
112 | struct mach_o_reloc_info_external |
||
113 | { |
||
114 | unsigned char r_address[4]; |
||
115 | unsigned char r_symbolnum[4]; |
||
116 | }; |
||
117 | #define BFD_MACH_O_RELENT_SIZE 8 |
||
118 | |||
119 | /* Relocations are based on 'address' being a section offset and an assumption |
||
120 | that sections are never more than 2^24-1 bytes in size. Relocation data |
||
121 | also carry information on type/size/PC-relative/extern and whether scattered |
||
122 | or not [stored in the MSB of the r_address]. */ |
||
123 | |||
124 | #define BFD_MACH_O_SR_SCATTERED 0x80000000 |
||
125 | |||
126 | /* For a non-scattered reloc, the relocation info is found in r_symbolnum. |
||
127 | Bytes 1 to 3 contain the symbol number (0xffffff, in a non-scattered PAIR). |
||
128 | Byte 4 contains the relocation info - but with differing bit-positions |
||
129 | dependent on target endian-ness - as below. */ |
||
130 | |||
131 | #define BFD_MACH_O_LE_PCREL 0x01 |
||
132 | #define BFD_MACH_O_LE_LENGTH_SHIFT 1 |
||
133 | #define BFD_MACH_O_LE_EXTERN 0x08 |
||
134 | #define BFD_MACH_O_LE_TYPE_SHIFT 4 |
||
135 | |||
136 | #define BFD_MACH_O_BE_PCREL 0x80 |
||
137 | #define BFD_MACH_O_BE_LENGTH_SHIFT 5 |
||
138 | #define BFD_MACH_O_BE_EXTERN 0x10 |
||
139 | #define BFD_MACH_O_BE_TYPE_SHIFT 0 |
||
140 | |||
141 | /* The field sizes are the same for both BE and LE. */ |
||
142 | #define BFD_MACH_O_LENGTH_MASK 0x03 |
||
143 | #define BFD_MACH_O_TYPE_MASK 0x0f |
||
144 | |||
145 | /* For a scattered reloc entry the info is contained in r_address. There |
||
146 | is no need to discriminate on target endian-ness, since the design was |
||
147 | arranged to produce the same layout on both. Scattered relocations are |
||
148 | only used for local items, therefore there is no 'extern' field. */ |
||
149 | |||
150 | #define BFD_MACH_O_SR_PCREL 0x40000000 |
||
151 | #define BFD_MACH_O_GET_SR_LENGTH(s) (((s) >> 28) & 0x3) |
||
152 | #define BFD_MACH_O_GET_SR_TYPE(s) (((s) >> 24) & 0x0f) |
||
153 | #define BFD_MACH_O_GET_SR_ADDRESS(s) ((s) & 0x00ffffff) |
||
154 | #define BFD_MACH_O_SET_SR_LENGTH(l) (((l) & 0x3) << 28) |
||
155 | #define BFD_MACH_O_SET_SR_TYPE(t) (((t) & 0xf) << 24) |
||
156 | #define BFD_MACH_O_SET_SR_ADDRESS(s) ((s) & 0x00ffffff) |
||
157 | |||
158 | struct mach_o_symtab_command_external |
||
159 | { |
||
160 | unsigned char symoff[4]; /* File offset of the symbol table. */ |
||
161 | unsigned char nsyms[4]; /* Number of symbols. */ |
||
162 | unsigned char stroff[4]; /* File offset of the string table. */ |
||
163 | unsigned char strsize[4]; /* String table size. */ |
||
164 | }; |
||
165 | |||
166 | struct mach_o_nlist_external |
||
167 | { |
||
168 | unsigned char n_strx[4]; |
||
169 | unsigned char n_type[1]; |
||
170 | unsigned char n_sect[1]; |
||
171 | unsigned char n_desc[2]; |
||
172 | unsigned char n_value[4]; |
||
173 | }; |
||
174 | #define BFD_MACH_O_NLIST_SIZE 12 |
||
175 | |||
176 | struct mach_o_nlist_64_external |
||
177 | { |
||
178 | unsigned char n_strx[4]; |
||
179 | unsigned char n_type[1]; |
||
180 | unsigned char n_sect[1]; |
||
181 | unsigned char n_desc[2]; |
||
182 | unsigned char n_value[8]; |
||
183 | }; |
||
184 | #define BFD_MACH_O_NLIST_64_SIZE 16 |
||
185 | |||
186 | struct mach_o_thread_command_external |
||
187 | { |
||
188 | unsigned char flavour[4]; |
||
189 | unsigned char count[4]; |
||
190 | }; |
||
191 | |||
192 | /* For commands that just have a string or a path. */ |
||
193 | struct mach_o_str_command_external |
||
194 | { |
||
195 | unsigned char str[4]; |
||
196 | }; |
||
197 | |||
198 | struct mach_o_dylib_command_external |
||
199 | { |
||
200 | unsigned char name[4]; |
||
201 | unsigned char timestamp[4]; |
||
202 | unsigned char current_version[4]; |
||
203 | unsigned char compatibility_version[4]; |
||
204 | }; |
||
205 | |||
206 | struct mach_o_dysymtab_command_external |
||
207 | { |
||
208 | unsigned char ilocalsym[4]; /* Index of. */ |
||
209 | unsigned char nlocalsym[4]; /* Number of. */ |
||
210 | unsigned char iextdefsym[4]; |
||
211 | unsigned char nextdefsym[4]; |
||
212 | unsigned char iundefsym[4]; |
||
213 | unsigned char nundefsym[4]; |
||
214 | unsigned char tocoff[4]; |
||
215 | unsigned char ntoc[4]; |
||
216 | unsigned char modtaboff[4]; |
||
217 | unsigned char nmodtab[4]; |
||
218 | unsigned char extrefsymoff[4]; |
||
219 | unsigned char nextrefsyms[4]; |
||
220 | unsigned char indirectsymoff[4]; |
||
221 | unsigned char nindirectsyms[4]; |
||
222 | unsigned char extreloff[4]; |
||
223 | unsigned char nextrel[4]; |
||
224 | unsigned char locreloff[4]; |
||
225 | unsigned char nlocrel[4]; |
||
226 | }; |
||
227 | |||
228 | struct mach_o_dylib_module_external |
||
229 | { |
||
230 | unsigned char module_name[4]; |
||
231 | unsigned char iextdefsym[4]; |
||
232 | unsigned char nextdefsym[4]; |
||
233 | unsigned char irefsym[4]; |
||
234 | unsigned char nrefsym[4]; |
||
235 | unsigned char ilocalsym[4]; |
||
236 | unsigned char nlocalsym[4]; |
||
237 | unsigned char iextrel[4]; |
||
238 | unsigned char nextrel[4]; |
||
239 | unsigned char iinit_iterm[4]; |
||
240 | unsigned char ninit_nterm[4]; |
||
241 | unsigned char objc_module_info_addr[4]; |
||
242 | unsigned char objc_module_info_size[4]; |
||
243 | }; |
||
244 | #define BFD_MACH_O_DYLIB_MODULE_SIZE 52 |
||
245 | |||
246 | struct mach_o_dylib_module_64_external |
||
247 | { |
||
248 | unsigned char module_name[4]; |
||
249 | unsigned char iextdefsym[4]; |
||
250 | unsigned char nextdefsym[4]; |
||
251 | unsigned char irefsym[4]; |
||
252 | unsigned char nrefsym[4]; |
||
253 | unsigned char ilocalsym[4]; |
||
254 | unsigned char nlocalsym[4]; |
||
255 | unsigned char iextrel[4]; |
||
256 | unsigned char nextrel[4]; |
||
257 | unsigned char iinit_iterm[4]; |
||
258 | unsigned char ninit_nterm[4]; |
||
259 | unsigned char objc_module_info_size[4]; |
||
260 | unsigned char objc_module_info_addr[8]; |
||
261 | }; |
||
262 | #define BFD_MACH_O_DYLIB_MODULE_64_SIZE 56 |
||
263 | |||
264 | struct mach_o_dylib_table_of_contents_external |
||
265 | { |
||
266 | unsigned char symbol_index[4]; |
||
267 | unsigned char module_index[4]; |
||
268 | }; |
||
269 | #define BFD_MACH_O_TABLE_OF_CONTENT_SIZE 8 |
||
270 | |||
271 | struct mach_o_linkedit_data_command_external |
||
272 | { |
||
273 | unsigned char dataoff[4]; |
||
274 | unsigned char datasize[4]; |
||
275 | }; |
||
276 | |||
277 | struct mach_o_dyld_info_command_external |
||
278 | { |
||
279 | unsigned char rebase_off[4]; |
||
280 | unsigned char rebase_size[4]; |
||
281 | unsigned char bind_off[4]; |
||
282 | unsigned char bind_size[4]; |
||
283 | unsigned char weak_bind_off[4]; |
||
284 | unsigned char weak_bind_size[4]; |
||
285 | unsigned char lazy_bind_off[4]; |
||
286 | unsigned char lazy_bind_size[4]; |
||
287 | unsigned char export_off[4]; |
||
288 | unsigned char export_size[4]; |
||
289 | }; |
||
290 | |||
291 | struct mach_o_version_min_command_external |
||
292 | { |
||
293 | unsigned char version[4]; |
||
294 | unsigned char reserved[4]; |
||
295 | }; |
||
296 | |||
297 | struct mach_o_encryption_info_command_external |
||
298 | { |
||
299 | unsigned char cryptoff[4]; /* File offset of the encrypted area. */ |
||
300 | unsigned char cryptsize[4]; /* Size of the encrypted area. */ |
||
301 | unsigned char cryptid[4]; /* Encryption method. */ |
||
302 | }; |
||
303 | |||
304 | struct mach_o_fvmlib_command_external |
||
305 | { |
||
306 | unsigned char name[4]; /* Offset of the name. */ |
||
307 | unsigned char minor_version[4]; |
||
308 | unsigned char header_addr[4]; |
||
309 | }; |
||
310 | |||
311 | struct mach_o_entry_point_command_external |
||
312 | { |
||
313 | unsigned char entryoff[8]; /* File offset of the entry point. */ |
||
314 | unsigned char stacksize[8]; /* Initial stack size, if no null. */ |
||
315 | }; |
||
316 | |||
317 | struct mach_o_source_version_command_external |
||
318 | { |
||
319 | unsigned char version[8]; /* Version A.B.C.D.E, with 10 bits for B-E, |
||
320 | and 24 bits for A. */ |
||
321 | }; |
||
322 | |||
323 | /* The LD_DATA_IN_CODE command use a linkedit_data_command that points to |
||
324 | a table of entries. */ |
||
325 | |||
326 | struct mach_o_data_in_code_entry_external |
||
327 | { |
||
328 | unsigned char offset[4]; /* Offset from the mach_header. */ |
||
329 | unsigned char length[2]; /* Number of bytes. */ |
||
330 | unsigned char kind[2]; /* Kind. See BFD_MACH_O_DICE_ values. */ |
||
331 | }; |
||
332 | |||
333 | struct mach_o_fat_header_external |
||
334 | { |
||
335 | unsigned char magic[4]; |
||
336 | unsigned char nfat_arch[4]; /* Number of components. */ |
||
337 | }; |
||
338 | |||
339 | struct mach_o_fat_arch_external |
||
340 | { |
||
341 | unsigned char cputype[4]; |
||
342 | unsigned char cpusubtype[4]; |
||
343 | unsigned char offset[4]; /* File offset of the member. */ |
||
344 | unsigned char size[4]; /* Size of the member. */ |
||
345 | unsigned char align[4]; /* Power of 2. */ |
||
346 | }; |
||
347 | |||
348 | #endif /* _MACH_O_EXTERNAL_H */><>><> |