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