1 /* Mach-O support for BFD. 2 Copyright 2011 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 struct mach_o_symtab_command_external 120 { 121 unsigned char symoff[4]; 122 unsigned char nsyms[4]; 123 unsigned char stroff[4]; 124 unsigned char strsize[4]; 125 }; 126 127 struct mach_o_nlist_external 128 { 129 unsigned char n_strx[4]; 130 unsigned char n_type[1]; 131 unsigned char n_sect[1]; 132 unsigned char n_desc[2]; 133 unsigned char n_value[4]; 134 }; 135 #define BFD_MACH_O_NLIST_SIZE 12 136 137 struct mach_o_nlist_64_external 138 { 139 unsigned char n_strx[4]; 140 unsigned char n_type[1]; 141 unsigned char n_sect[1]; 142 unsigned char n_desc[2]; 143 unsigned char n_value[8]; 144 }; 145 #define BFD_MACH_O_NLIST_64_SIZE 16 146 147 struct mach_o_thread_command_external 148 { 149 unsigned char flavour[4]; 150 unsigned char count[4]; 151 }; 152 153 /* For commands that just have a string or a path. */ 154 struct mach_o_str_command_external 155 { 156 unsigned char str[4]; 157 }; 158 159 struct mach_o_dylib_command_external 160 { 161 unsigned char name[4]; 162 unsigned char timestamp[4]; 163 unsigned char current_version[4]; 164 unsigned char compatibility_version[4]; 165 }; 166 167 struct mach_o_dysymtab_command_external 168 { 169 unsigned char ilocalsym[4]; /* Index of. */ 170 unsigned char nlocalsym[4]; /* Number of. */ 171 unsigned char iextdefsym[4]; 172 unsigned char nextdefsym[4]; 173 unsigned char iundefsym[4]; 174 unsigned char nundefsym[4]; 175 unsigned char tocoff[4]; 176 unsigned char ntoc[4]; 177 unsigned char modtaboff[4]; 178 unsigned char nmodtab[4]; 179 unsigned char extrefsymoff[4]; 180 unsigned char nextrefsyms[4]; 181 unsigned char indirectsymoff[4]; 182 unsigned char nindirectsyms[4]; 183 unsigned char extreloff[4]; 184 unsigned char nextrel[4]; 185 unsigned char locreloff[4]; 186 unsigned char nlocrel[4]; 187 }; 188 189 struct mach_o_dylib_module_external 190 { 191 unsigned char module_name[4]; 192 unsigned char iextdefsym[4]; 193 unsigned char nextdefsym[4]; 194 unsigned char irefsym[4]; 195 unsigned char nrefsym[4]; 196 unsigned char ilocalsym[4]; 197 unsigned char nlocalsym[4]; 198 unsigned char iextrel[4]; 199 unsigned char nextrel[4]; 200 unsigned char iinit_iterm[4]; 201 unsigned char ninit_nterm[4]; 202 unsigned char objc_module_info_addr[4]; 203 unsigned char objc_module_info_size[4]; 204 }; 205 #define BFD_MACH_O_DYLIB_MODULE_SIZE 52 206 207 struct mach_o_dylib_module_64_external 208 { 209 unsigned char module_name[4]; 210 unsigned char iextdefsym[4]; 211 unsigned char nextdefsym[4]; 212 unsigned char irefsym[4]; 213 unsigned char nrefsym[4]; 214 unsigned char ilocalsym[4]; 215 unsigned char nlocalsym[4]; 216 unsigned char iextrel[4]; 217 unsigned char nextrel[4]; 218 unsigned char iinit_iterm[4]; 219 unsigned char ninit_nterm[4]; 220 unsigned char objc_module_info_size[4]; 221 unsigned char objc_module_info_addr[8]; 222 }; 223 #define BFD_MACH_O_DYLIB_MODULE_64_SIZE 56 224 225 struct mach_o_dylib_table_of_contents_external 226 { 227 unsigned char symbol_index[4]; 228 unsigned char module_index[4]; 229 }; 230 #define BFD_MACH_O_TABLE_OF_CONTENT_SIZE 8 231 232 struct mach_o_linkedit_data_command_external 233 { 234 unsigned char dataoff[4]; 235 unsigned char datasize[4]; 236 }; 237 238 struct mach_o_dyld_info_command_external 239 { 240 unsigned char rebase_off[4]; 241 unsigned char rebase_size[4]; 242 unsigned char bind_off[4]; 243 unsigned char bind_size[4]; 244 unsigned char weak_bind_off[4]; 245 unsigned char weak_bind_size[4]; 246 unsigned char lazy_bind_off[4]; 247 unsigned char lazy_bind_size[4]; 248 unsigned char export_off[4]; 249 unsigned char export_size[4]; 250 }; 251 252 struct mach_o_version_min_command_external 253 { 254 unsigned char version[4]; 255 unsigned char reserved[4]; 256 }; 257 258 struct mach_o_fat_header_external 259 { 260 unsigned char magic[4]; 261 unsigned char nfat_arch[4]; /* Number of components. */ 262 }; 263 264 struct mach_o_fat_arch_external 265 { 266 unsigned char cputype[4]; 267 unsigned char cpusubtype[4]; 268 unsigned char offset[4]; /* File offset of the member. */ 269 unsigned char size[4]; /* Size of the member. */ 270 unsigned char align[4]; /* Power of 2. */ 271 }; 272 273 #endif /* _MACH_O_EXTERNAL_H */ 274