1*3d8817e4Smiod /* Mach-O support for BFD. 2*3d8817e4Smiod Copyright 1999, 2000, 2001, 2002, 2003, 2005 3*3d8817e4Smiod Free Software Foundation, Inc. 4*3d8817e4Smiod 5*3d8817e4Smiod This file is part of BFD, the Binary File Descriptor library. 6*3d8817e4Smiod 7*3d8817e4Smiod This program is free software; you can redistribute it and/or modify 8*3d8817e4Smiod it under the terms of the GNU General Public License as published by 9*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or 10*3d8817e4Smiod (at your option) any later version. 11*3d8817e4Smiod 12*3d8817e4Smiod This program is distributed in the hope that it will be useful, 13*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of 14*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*3d8817e4Smiod GNU General Public License for more details. 16*3d8817e4Smiod 17*3d8817e4Smiod You should have received a copy of the GNU General Public License 18*3d8817e4Smiod along with this program; if not, write to the Free Software 19*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 20*3d8817e4Smiod 21*3d8817e4Smiod #ifndef _BFD_MACH_O_H_ 22*3d8817e4Smiod #define _BFD_MACH_O_H_ 23*3d8817e4Smiod 24*3d8817e4Smiod #include "bfd.h" 25*3d8817e4Smiod 26*3d8817e4Smiod #define BFD_MACH_O_N_STAB 0xe0 /* If any of these bits set, a symbolic debugging entry. */ 27*3d8817e4Smiod #define BFD_MACH_O_N_PEXT 0x10 /* Private external symbol bit. */ 28*3d8817e4Smiod #define BFD_MACH_O_N_TYPE 0x0e /* Mask for the type bits. */ 29*3d8817e4Smiod #define BFD_MACH_O_N_EXT 0x01 /* External symbol bit, set for external symbols. */ 30*3d8817e4Smiod #define BFD_MACH_O_N_UNDF 0x00 /* Undefined, n_sect == NO_SECT. */ 31*3d8817e4Smiod #define BFD_MACH_O_N_ABS 0x02 /* Absolute, n_sect == NO_SECT. */ 32*3d8817e4Smiod #define BFD_MACH_O_N_SECT 0x0e /* Defined in section number n_sect. */ 33*3d8817e4Smiod #define BFD_MACH_O_N_PBUD 0x0c /* Prebound undefined (defined in a dylib). */ 34*3d8817e4Smiod #define BFD_MACH_O_N_INDR 0x0a /* Indirect. */ 35*3d8817e4Smiod 36*3d8817e4Smiod typedef enum bfd_mach_o_ppc_thread_flavour 37*3d8817e4Smiod { 38*3d8817e4Smiod BFD_MACH_O_PPC_THREAD_STATE = 1, 39*3d8817e4Smiod BFD_MACH_O_PPC_FLOAT_STATE = 2, 40*3d8817e4Smiod BFD_MACH_O_PPC_EXCEPTION_STATE = 3, 41*3d8817e4Smiod BFD_MACH_O_PPC_VECTOR_STATE = 4 42*3d8817e4Smiod } 43*3d8817e4Smiod bfd_mach_o_ppc_thread_flavour; 44*3d8817e4Smiod 45*3d8817e4Smiod typedef enum bfd_mach_o_i386_thread_flavour 46*3d8817e4Smiod { 47*3d8817e4Smiod BFD_MACH_O_i386_NEW_THREAD_STATE = 1, 48*3d8817e4Smiod BFD_MACH_O_i386_FLOAT_STATE = 2, 49*3d8817e4Smiod BFD_MACH_O_i386_ISA_PORT_MAP_STATE = 3, 50*3d8817e4Smiod BFD_MACH_O_i386_V86_ASSIST_STATE = 4, 51*3d8817e4Smiod BFD_MACH_O_i386_REGS_SEGS_STATE = 5, 52*3d8817e4Smiod BFD_MACH_O_i386_THREAD_SYSCALL_STATE = 6, 53*3d8817e4Smiod BFD_MACH_O_i386_THREAD_STATE_NONE = 7, 54*3d8817e4Smiod BFD_MACH_O_i386_SAVED_STATE = 8, 55*3d8817e4Smiod BFD_MACH_O_i386_THREAD_STATE = -1, 56*3d8817e4Smiod BFD_MACH_O_i386_THREAD_FPSTATE = -2, 57*3d8817e4Smiod BFD_MACH_O_i386_THREAD_EXCEPTSTATE = -3, 58*3d8817e4Smiod BFD_MACH_O_i386_THREAD_CTHREADSTATE = -4, 59*3d8817e4Smiod } 60*3d8817e4Smiod bfd_mach_o_i386_thread_flavour; 61*3d8817e4Smiod 62*3d8817e4Smiod #define BFD_MACH_O_LC_REQ_DYLD 0x80000000 63*3d8817e4Smiod 64*3d8817e4Smiod typedef enum bfd_mach_o_load_command_type 65*3d8817e4Smiod { 66*3d8817e4Smiod BFD_MACH_O_LC_SEGMENT = 0x1, /* File segment to be mapped. */ 67*3d8817e4Smiod BFD_MACH_O_LC_SYMTAB = 0x2, /* Link-edit stab symbol table info (obsolete). */ 68*3d8817e4Smiod BFD_MACH_O_LC_SYMSEG = 0x3, /* Link-edit gdb symbol table info. */ 69*3d8817e4Smiod BFD_MACH_O_LC_THREAD = 0x4, /* Thread. */ 70*3d8817e4Smiod BFD_MACH_O_LC_UNIXTHREAD = 0x5, /* UNIX thread (includes a stack). */ 71*3d8817e4Smiod BFD_MACH_O_LC_LOADFVMLIB = 0x6, /* Load a fixed VM shared library. */ 72*3d8817e4Smiod BFD_MACH_O_LC_IDFVMLIB = 0x7, /* Fixed VM shared library id. */ 73*3d8817e4Smiod BFD_MACH_O_LC_IDENT = 0x8, /* Object identification information (obsolete). */ 74*3d8817e4Smiod BFD_MACH_O_LC_FVMFILE = 0x9, /* Fixed VM file inclusion. */ 75*3d8817e4Smiod BFD_MACH_O_LC_PREPAGE = 0xa, /* Prepage command (internal use). */ 76*3d8817e4Smiod BFD_MACH_O_LC_DYSYMTAB = 0xb, /* Dynamic link-edit symbol table info. */ 77*3d8817e4Smiod BFD_MACH_O_LC_LOAD_DYLIB = 0xc, /* Load a dynamically linked shared library. */ 78*3d8817e4Smiod BFD_MACH_O_LC_ID_DYLIB = 0xd, /* Dynamically linked shared lib identification. */ 79*3d8817e4Smiod BFD_MACH_O_LC_LOAD_DYLINKER = 0xe, /* Load a dynamic linker. */ 80*3d8817e4Smiod BFD_MACH_O_LC_ID_DYLINKER = 0xf, /* Dynamic linker identification. */ 81*3d8817e4Smiod BFD_MACH_O_LC_PREBOUND_DYLIB = 0x10, /* Modules prebound for a dynamically. */ 82*3d8817e4Smiod BFD_MACH_O_LC_ROUTINES = 0x11, /* Image routines. */ 83*3d8817e4Smiod BFD_MACH_O_LC_SUB_FRAMEWORK = 0x12, /* Sub framework. */ 84*3d8817e4Smiod BFD_MACH_O_LC_SUB_UMBRELLA = 0x13, /* Sub umbrella. */ 85*3d8817e4Smiod BFD_MACH_O_LC_SUB_CLIENT = 0x14, /* Sub client. */ 86*3d8817e4Smiod BFD_MACH_O_LC_SUB_LIBRARY = 0x15, /* Sub library. */ 87*3d8817e4Smiod BFD_MACH_O_LC_TWOLEVEL_HINTS = 0x16, /* Two-level namespace lookup hints. */ 88*3d8817e4Smiod BFD_MACH_O_LC_PREBIND_CKSUM = 0x17, /* Prebind checksum. */ 89*3d8817e4Smiod /* Load a dynamically linked shared library that is allowed to be 90*3d8817e4Smiod missing (weak). */ 91*3d8817e4Smiod BFD_MACH_O_LC_LOAD_WEAK_DYLIB = 0x18 92*3d8817e4Smiod } 93*3d8817e4Smiod bfd_mach_o_load_command_type; 94*3d8817e4Smiod 95*3d8817e4Smiod typedef enum bfd_mach_o_cpu_type 96*3d8817e4Smiod { 97*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_VAX = 1, 98*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_MC680x0 = 6, 99*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_I386 = 7, 100*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_MIPS = 8, 101*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_MC98000 = 10, 102*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_HPPA = 11, 103*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_ARM = 12, 104*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_MC88000 = 13, 105*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_SPARC = 14, 106*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_I860 = 15, 107*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_ALPHA = 16, 108*3d8817e4Smiod BFD_MACH_O_CPU_TYPE_POWERPC = 18 109*3d8817e4Smiod } 110*3d8817e4Smiod bfd_mach_o_cpu_type; 111*3d8817e4Smiod 112*3d8817e4Smiod typedef enum bfd_mach_o_filetype 113*3d8817e4Smiod { 114*3d8817e4Smiod BFD_MACH_O_MH_OBJECT = 1, 115*3d8817e4Smiod BFD_MACH_O_MH_EXECUTE = 2, 116*3d8817e4Smiod BFD_MACH_O_MH_FVMLIB = 3, 117*3d8817e4Smiod BFD_MACH_O_MH_CORE = 4, 118*3d8817e4Smiod BFD_MACH_O_MH_PRELOAD = 5, 119*3d8817e4Smiod BFD_MACH_O_MH_DYLIB = 6, 120*3d8817e4Smiod BFD_MACH_O_MH_DYLINKER = 7, 121*3d8817e4Smiod BFD_MACH_O_MH_BUNDLE = 8 122*3d8817e4Smiod } 123*3d8817e4Smiod bfd_mach_o_filetype; 124*3d8817e4Smiod 125*3d8817e4Smiod /* Constants for the type of a section. */ 126*3d8817e4Smiod 127*3d8817e4Smiod typedef enum bfd_mach_o_section_type 128*3d8817e4Smiod { 129*3d8817e4Smiod /* Regular section. */ 130*3d8817e4Smiod BFD_MACH_O_S_REGULAR = 0x0, 131*3d8817e4Smiod 132*3d8817e4Smiod /* Zero fill on demand section. */ 133*3d8817e4Smiod BFD_MACH_O_S_ZEROFILL = 0x1, 134*3d8817e4Smiod 135*3d8817e4Smiod /* Section with only literal C strings. */ 136*3d8817e4Smiod BFD_MACH_O_S_CSTRING_LITERALS = 0x2, 137*3d8817e4Smiod 138*3d8817e4Smiod /* Section with only 4 byte literals. */ 139*3d8817e4Smiod BFD_MACH_O_S_4BYTE_LITERALS = 0x3, 140*3d8817e4Smiod 141*3d8817e4Smiod /* Section with only 8 byte literals. */ 142*3d8817e4Smiod BFD_MACH_O_S_8BYTE_LITERALS = 0x4, 143*3d8817e4Smiod 144*3d8817e4Smiod /* Section with only pointers to literals. */ 145*3d8817e4Smiod BFD_MACH_O_S_LITERAL_POINTERS = 0x5, 146*3d8817e4Smiod 147*3d8817e4Smiod /* For the two types of symbol pointers sections and the symbol stubs 148*3d8817e4Smiod section they have indirect symbol table entries. For each of the 149*3d8817e4Smiod entries in the section the indirect symbol table entries, in 150*3d8817e4Smiod corresponding order in the indirect symbol table, start at the index 151*3d8817e4Smiod stored in the reserved1 field of the section structure. Since the 152*3d8817e4Smiod indirect symbol table entries correspond to the entries in the 153*3d8817e4Smiod section the number of indirect symbol table entries is inferred from 154*3d8817e4Smiod the size of the section divided by the size of the entries in the 155*3d8817e4Smiod section. For symbol pointers sections the size of the entries in 156*3d8817e4Smiod the section is 4 bytes and for symbol stubs sections the byte size 157*3d8817e4Smiod of the stubs is stored in the reserved2 field of the section 158*3d8817e4Smiod structure. */ 159*3d8817e4Smiod 160*3d8817e4Smiod /* Section with only non-lazy symbol pointers. */ 161*3d8817e4Smiod BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS = 0x6, 162*3d8817e4Smiod 163*3d8817e4Smiod /* Section with only lazy symbol pointers. */ 164*3d8817e4Smiod BFD_MACH_O_S_LAZY_SYMBOL_POINTERS = 0x7, 165*3d8817e4Smiod 166*3d8817e4Smiod /* Section with only symbol stubs, byte size of stub in the reserved2 field. */ 167*3d8817e4Smiod BFD_MACH_O_S_SYMBOL_STUBS = 0x8, 168*3d8817e4Smiod 169*3d8817e4Smiod /* Section with only function pointers for initialization. */ 170*3d8817e4Smiod BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9 171*3d8817e4Smiod } 172*3d8817e4Smiod bfd_mach_o_section_type; 173*3d8817e4Smiod 174*3d8817e4Smiod typedef unsigned long bfd_mach_o_cpu_subtype; 175*3d8817e4Smiod 176*3d8817e4Smiod typedef struct bfd_mach_o_header 177*3d8817e4Smiod { 178*3d8817e4Smiod unsigned long magic; 179*3d8817e4Smiod unsigned long cputype; 180*3d8817e4Smiod unsigned long cpusubtype; 181*3d8817e4Smiod unsigned long filetype; 182*3d8817e4Smiod unsigned long ncmds; 183*3d8817e4Smiod unsigned long sizeofcmds; 184*3d8817e4Smiod unsigned long flags; 185*3d8817e4Smiod enum bfd_endian byteorder; 186*3d8817e4Smiod } 187*3d8817e4Smiod bfd_mach_o_header; 188*3d8817e4Smiod 189*3d8817e4Smiod typedef struct bfd_mach_o_section 190*3d8817e4Smiod { 191*3d8817e4Smiod asection *bfdsection; 192*3d8817e4Smiod char sectname[16 + 1]; 193*3d8817e4Smiod char segname[16 + 1]; 194*3d8817e4Smiod bfd_vma addr; 195*3d8817e4Smiod bfd_vma size; 196*3d8817e4Smiod bfd_vma offset; 197*3d8817e4Smiod unsigned long align; 198*3d8817e4Smiod bfd_vma reloff; 199*3d8817e4Smiod unsigned long nreloc; 200*3d8817e4Smiod unsigned long flags; 201*3d8817e4Smiod unsigned long reserved1; 202*3d8817e4Smiod unsigned long reserved2; 203*3d8817e4Smiod } 204*3d8817e4Smiod bfd_mach_o_section; 205*3d8817e4Smiod 206*3d8817e4Smiod typedef struct bfd_mach_o_segment_command 207*3d8817e4Smiod { 208*3d8817e4Smiod char segname[16]; 209*3d8817e4Smiod bfd_vma vmaddr; 210*3d8817e4Smiod bfd_vma vmsize; 211*3d8817e4Smiod bfd_vma fileoff; 212*3d8817e4Smiod unsigned long filesize; 213*3d8817e4Smiod unsigned long nsects; 214*3d8817e4Smiod unsigned long flags; 215*3d8817e4Smiod bfd_mach_o_section *sections; 216*3d8817e4Smiod asection *segment; 217*3d8817e4Smiod } 218*3d8817e4Smiod bfd_mach_o_segment_command; 219*3d8817e4Smiod 220*3d8817e4Smiod typedef struct bfd_mach_o_symtab_command 221*3d8817e4Smiod { 222*3d8817e4Smiod unsigned long symoff; 223*3d8817e4Smiod unsigned long nsyms; 224*3d8817e4Smiod unsigned long stroff; 225*3d8817e4Smiod unsigned long strsize; 226*3d8817e4Smiod asymbol *symbols; 227*3d8817e4Smiod char *strtab; 228*3d8817e4Smiod asection *stabs_segment; 229*3d8817e4Smiod asection *stabstr_segment; 230*3d8817e4Smiod } 231*3d8817e4Smiod bfd_mach_o_symtab_command; 232*3d8817e4Smiod 233*3d8817e4Smiod /* This is the second set of the symbolic information which is used to support 234*3d8817e4Smiod the data structures for the dynamically link editor. 235*3d8817e4Smiod 236*3d8817e4Smiod The original set of symbolic information in the symtab_command which contains 237*3d8817e4Smiod the symbol and string tables must also be present when this load command is 238*3d8817e4Smiod present. When this load command is present the symbol table is organized 239*3d8817e4Smiod into three groups of symbols: 240*3d8817e4Smiod local symbols (static and debugging symbols) - grouped by module 241*3d8817e4Smiod defined external symbols - grouped by module (sorted by name if not lib) 242*3d8817e4Smiod undefined external symbols (sorted by name) 243*3d8817e4Smiod In this load command there are offsets and counts to each of the three groups 244*3d8817e4Smiod of symbols. 245*3d8817e4Smiod 246*3d8817e4Smiod This load command contains a the offsets and sizes of the following new 247*3d8817e4Smiod symbolic information tables: 248*3d8817e4Smiod table of contents 249*3d8817e4Smiod module table 250*3d8817e4Smiod reference symbol table 251*3d8817e4Smiod indirect symbol table 252*3d8817e4Smiod The first three tables above (the table of contents, module table and 253*3d8817e4Smiod reference symbol table) are only present if the file is a dynamically linked 254*3d8817e4Smiod shared library. For executable and object modules, which are files 255*3d8817e4Smiod containing only one module, the information that would be in these three 256*3d8817e4Smiod tables is determined as follows: 257*3d8817e4Smiod table of contents - the defined external symbols are sorted by name 258*3d8817e4Smiod module table - the file contains only one module so everything in the 259*3d8817e4Smiod file is part of the module. 260*3d8817e4Smiod reference symbol table - is the defined and undefined external symbols 261*3d8817e4Smiod 262*3d8817e4Smiod For dynamically linked shared library files this load command also contains 263*3d8817e4Smiod offsets and sizes to the pool of relocation entries for all sections 264*3d8817e4Smiod separated into two groups: 265*3d8817e4Smiod external relocation entries 266*3d8817e4Smiod local relocation entries 267*3d8817e4Smiod For executable and object modules the relocation entries continue to hang 268*3d8817e4Smiod off the section structures. */ 269*3d8817e4Smiod 270*3d8817e4Smiod typedef struct bfd_mach_o_dysymtab_command 271*3d8817e4Smiod { 272*3d8817e4Smiod /* The symbols indicated by symoff and nsyms of the LC_SYMTAB load command 273*3d8817e4Smiod are grouped into the following three groups: 274*3d8817e4Smiod local symbols (further grouped by the module they are from) 275*3d8817e4Smiod defined external symbols (further grouped by the module they are from) 276*3d8817e4Smiod undefined symbols 277*3d8817e4Smiod 278*3d8817e4Smiod The local symbols are used only for debugging. The dynamic binding 279*3d8817e4Smiod process may have to use them to indicate to the debugger the local 280*3d8817e4Smiod symbols for a module that is being bound. 281*3d8817e4Smiod 282*3d8817e4Smiod The last two groups are used by the dynamic binding process to do the 283*3d8817e4Smiod binding (indirectly through the module table and the reference symbol 284*3d8817e4Smiod table when this is a dynamically linked shared library file). */ 285*3d8817e4Smiod 286*3d8817e4Smiod unsigned long ilocalsym; /* Index to local symbols. */ 287*3d8817e4Smiod unsigned long nlocalsym; /* Number of local symbols. */ 288*3d8817e4Smiod unsigned long iextdefsym; /* Index to externally defined symbols. */ 289*3d8817e4Smiod unsigned long nextdefsym; /* Number of externally defined symbols. */ 290*3d8817e4Smiod unsigned long iundefsym; /* Index to undefined symbols. */ 291*3d8817e4Smiod unsigned long nundefsym; /* Number of undefined symbols. */ 292*3d8817e4Smiod 293*3d8817e4Smiod /* For the for the dynamic binding process to find which module a symbol 294*3d8817e4Smiod is defined in the table of contents is used (analogous to the ranlib 295*3d8817e4Smiod structure in an archive) which maps defined external symbols to modules 296*3d8817e4Smiod they are defined in. This exists only in a dynamically linked shared 297*3d8817e4Smiod library file. For executable and object modules the defined external 298*3d8817e4Smiod symbols are sorted by name and is use as the table of contents. */ 299*3d8817e4Smiod 300*3d8817e4Smiod unsigned long tocoff; /* File offset to table of contents. */ 301*3d8817e4Smiod unsigned long ntoc; /* Number of entries in table of contents. */ 302*3d8817e4Smiod 303*3d8817e4Smiod /* To support dynamic binding of "modules" (whole object files) the symbol 304*3d8817e4Smiod table must reflect the modules that the file was created from. This is 305*3d8817e4Smiod done by having a module table that has indexes and counts into the merged 306*3d8817e4Smiod tables for each module. The module structure that these two entries 307*3d8817e4Smiod refer to is described below. This exists only in a dynamically linked 308*3d8817e4Smiod shared library file. For executable and object modules the file only 309*3d8817e4Smiod contains one module so everything in the file belongs to the module. */ 310*3d8817e4Smiod 311*3d8817e4Smiod unsigned long modtaboff; /* File offset to module table. */ 312*3d8817e4Smiod unsigned long nmodtab; /* Number of module table entries. */ 313*3d8817e4Smiod 314*3d8817e4Smiod /* To support dynamic module binding the module structure for each module 315*3d8817e4Smiod indicates the external references (defined and undefined) each module 316*3d8817e4Smiod makes. For each module there is an offset and a count into the 317*3d8817e4Smiod reference symbol table for the symbols that the module references. 318*3d8817e4Smiod This exists only in a dynamically linked shared library file. For 319*3d8817e4Smiod executable and object modules the defined external symbols and the 320*3d8817e4Smiod undefined external symbols indicates the external references. */ 321*3d8817e4Smiod 322*3d8817e4Smiod unsigned long extrefsymoff; /* Offset to referenced symbol table. */ 323*3d8817e4Smiod unsigned long nextrefsyms; /* Number of referenced symbol table entries. */ 324*3d8817e4Smiod 325*3d8817e4Smiod /* The sections that contain "symbol pointers" and "routine stubs" have 326*3d8817e4Smiod indexes and (implied counts based on the size of the section and fixed 327*3d8817e4Smiod size of the entry) into the "indirect symbol" table for each pointer 328*3d8817e4Smiod and stub. For every section of these two types the index into the 329*3d8817e4Smiod indirect symbol table is stored in the section header in the field 330*3d8817e4Smiod reserved1. An indirect symbol table entry is simply a 32bit index into 331*3d8817e4Smiod the symbol table to the symbol that the pointer or stub is referring to. 332*3d8817e4Smiod The indirect symbol table is ordered to match the entries in the section. */ 333*3d8817e4Smiod 334*3d8817e4Smiod unsigned long indirectsymoff; /* File offset to the indirect symbol table. */ 335*3d8817e4Smiod unsigned long nindirectsyms; /* Number of indirect symbol table entries. */ 336*3d8817e4Smiod 337*3d8817e4Smiod /* To support relocating an individual module in a library file quickly the 338*3d8817e4Smiod external relocation entries for each module in the library need to be 339*3d8817e4Smiod accessed efficiently. Since the relocation entries can't be accessed 340*3d8817e4Smiod through the section headers for a library file they are separated into 341*3d8817e4Smiod groups of local and external entries further grouped by module. In this 342*3d8817e4Smiod case the presents of this load command who's extreloff, nextrel, 343*3d8817e4Smiod locreloff and nlocrel fields are non-zero indicates that the relocation 344*3d8817e4Smiod entries of non-merged sections are not referenced through the section 345*3d8817e4Smiod structures (and the reloff and nreloc fields in the section headers are 346*3d8817e4Smiod set to zero). 347*3d8817e4Smiod 348*3d8817e4Smiod Since the relocation entries are not accessed through the section headers 349*3d8817e4Smiod this requires the r_address field to be something other than a section 350*3d8817e4Smiod offset to identify the item to be relocated. In this case r_address is 351*3d8817e4Smiod set to the offset from the vmaddr of the first LC_SEGMENT command. 352*3d8817e4Smiod 353*3d8817e4Smiod The relocation entries are grouped by module and the module table 354*3d8817e4Smiod entries have indexes and counts into them for the group of external 355*3d8817e4Smiod relocation entries for that the module. 356*3d8817e4Smiod 357*3d8817e4Smiod For sections that are merged across modules there must not be any 358*3d8817e4Smiod remaining external relocation entries for them (for merged sections 359*3d8817e4Smiod remaining relocation entries must be local). */ 360*3d8817e4Smiod 361*3d8817e4Smiod unsigned long extreloff; /* Offset to external relocation entries. */ 362*3d8817e4Smiod unsigned long nextrel; /* Number of external relocation entries. */ 363*3d8817e4Smiod 364*3d8817e4Smiod /* All the local relocation entries are grouped together (they are not 365*3d8817e4Smiod grouped by their module since they are only used if the object is moved 366*3d8817e4Smiod from it statically link edited address). */ 367*3d8817e4Smiod 368*3d8817e4Smiod unsigned long locreloff; /* Offset to local relocation entries. */ 369*3d8817e4Smiod unsigned long nlocrel; /* Number of local relocation entries. */ 370*3d8817e4Smiod } 371*3d8817e4Smiod bfd_mach_o_dysymtab_command; 372*3d8817e4Smiod 373*3d8817e4Smiod /* An indirect symbol table entry is simply a 32bit index into the symbol table 374*3d8817e4Smiod to the symbol that the pointer or stub is refering to. Unless it is for a 375*3d8817e4Smiod non-lazy symbol pointer section for a defined symbol which strip(1) as 376*3d8817e4Smiod removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the 377*3d8817e4Smiod symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. */ 378*3d8817e4Smiod 379*3d8817e4Smiod #define INDIRECT_SYMBOL_LOCAL 0x80000000 380*3d8817e4Smiod #define INDIRECT_SYMBOL_ABS 0x40000000 381*3d8817e4Smiod 382*3d8817e4Smiod typedef struct bfd_mach_o_thread_flavour 383*3d8817e4Smiod { 384*3d8817e4Smiod unsigned long flavour; 385*3d8817e4Smiod bfd_vma offset; 386*3d8817e4Smiod unsigned long size; 387*3d8817e4Smiod } 388*3d8817e4Smiod bfd_mach_o_thread_flavour; 389*3d8817e4Smiod 390*3d8817e4Smiod typedef struct bfd_mach_o_thread_command 391*3d8817e4Smiod { 392*3d8817e4Smiod unsigned long nflavours; 393*3d8817e4Smiod bfd_mach_o_thread_flavour *flavours; 394*3d8817e4Smiod asection *section; 395*3d8817e4Smiod } 396*3d8817e4Smiod bfd_mach_o_thread_command; 397*3d8817e4Smiod 398*3d8817e4Smiod typedef struct bfd_mach_o_dylinker_command 399*3d8817e4Smiod { 400*3d8817e4Smiod unsigned long cmd; /* LC_ID_DYLIB or LC_LOAD_DYLIB. */ 401*3d8817e4Smiod unsigned long cmdsize; /* Includes pathname string. */ 402*3d8817e4Smiod unsigned long name_offset; /* Offset to library's path name. */ 403*3d8817e4Smiod unsigned long name_len; /* Offset to library's path name. */ 404*3d8817e4Smiod asection *section; 405*3d8817e4Smiod } 406*3d8817e4Smiod bfd_mach_o_dylinker_command; 407*3d8817e4Smiod 408*3d8817e4Smiod typedef struct bfd_mach_o_dylib_command 409*3d8817e4Smiod { 410*3d8817e4Smiod unsigned long cmd; /* LC_ID_DYLIB or LC_LOAD_DYLIB. */ 411*3d8817e4Smiod unsigned long cmdsize; /* Includes pathname string. */ 412*3d8817e4Smiod unsigned long name_offset; /* Offset to library's path name. */ 413*3d8817e4Smiod unsigned long name_len; /* Offset to library's path name. */ 414*3d8817e4Smiod unsigned long timestamp; /* Library's build time stamp. */ 415*3d8817e4Smiod unsigned long current_version; /* Library's current version number. */ 416*3d8817e4Smiod unsigned long compatibility_version; /* Library's compatibility vers number. */ 417*3d8817e4Smiod asection *section; 418*3d8817e4Smiod } 419*3d8817e4Smiod bfd_mach_o_dylib_command; 420*3d8817e4Smiod 421*3d8817e4Smiod typedef struct bfd_mach_o_prebound_dylib_command 422*3d8817e4Smiod { 423*3d8817e4Smiod unsigned long cmd; /* LC_PREBOUND_DYLIB. */ 424*3d8817e4Smiod unsigned long cmdsize; /* Includes strings. */ 425*3d8817e4Smiod unsigned long name; /* Library's path name. */ 426*3d8817e4Smiod unsigned long nmodules; /* Number of modules in library. */ 427*3d8817e4Smiod unsigned long linked_modules; /* Bit vector of linked modules. */ 428*3d8817e4Smiod asection *section; 429*3d8817e4Smiod } 430*3d8817e4Smiod bfd_mach_o_prebound_dylib_command; 431*3d8817e4Smiod 432*3d8817e4Smiod typedef struct bfd_mach_o_load_command 433*3d8817e4Smiod { 434*3d8817e4Smiod bfd_mach_o_load_command_type type; 435*3d8817e4Smiod unsigned int type_required; 436*3d8817e4Smiod bfd_vma offset; 437*3d8817e4Smiod bfd_vma len; 438*3d8817e4Smiod union 439*3d8817e4Smiod { 440*3d8817e4Smiod bfd_mach_o_segment_command segment; 441*3d8817e4Smiod bfd_mach_o_symtab_command symtab; 442*3d8817e4Smiod bfd_mach_o_dysymtab_command dysymtab; 443*3d8817e4Smiod bfd_mach_o_thread_command thread; 444*3d8817e4Smiod bfd_mach_o_dylib_command dylib; 445*3d8817e4Smiod bfd_mach_o_dylinker_command dylinker; 446*3d8817e4Smiod bfd_mach_o_prebound_dylib_command prebound_dylib; 447*3d8817e4Smiod } 448*3d8817e4Smiod command; 449*3d8817e4Smiod } 450*3d8817e4Smiod bfd_mach_o_load_command; 451*3d8817e4Smiod 452*3d8817e4Smiod typedef struct mach_o_data_struct 453*3d8817e4Smiod { 454*3d8817e4Smiod bfd_mach_o_header header; 455*3d8817e4Smiod bfd_mach_o_load_command *commands; 456*3d8817e4Smiod unsigned long nsymbols; 457*3d8817e4Smiod asymbol *symbols; 458*3d8817e4Smiod unsigned long nsects; 459*3d8817e4Smiod bfd_mach_o_section **sections; 460*3d8817e4Smiod bfd *ibfd; 461*3d8817e4Smiod } 462*3d8817e4Smiod mach_o_data_struct; 463*3d8817e4Smiod 464*3d8817e4Smiod typedef struct mach_o_data_struct bfd_mach_o_data_struct; 465*3d8817e4Smiod 466*3d8817e4Smiod bfd_boolean bfd_mach_o_valid (bfd *); 467*3d8817e4Smiod int bfd_mach_o_scan_read_symtab_symbol (bfd *, bfd_mach_o_symtab_command *, asymbol *, unsigned long); 468*3d8817e4Smiod int bfd_mach_o_scan_read_symtab_strtab (bfd *, bfd_mach_o_symtab_command *); 469*3d8817e4Smiod int bfd_mach_o_scan_read_symtab_symbols (bfd *, bfd_mach_o_symtab_command *); 470*3d8817e4Smiod int bfd_mach_o_scan_read_dysymtab_symbol (bfd *, bfd_mach_o_dysymtab_command *, bfd_mach_o_symtab_command *, asymbol *, unsigned long); 471*3d8817e4Smiod int bfd_mach_o_scan_start_address (bfd *); 472*3d8817e4Smiod int bfd_mach_o_scan (bfd *, bfd_mach_o_header *, bfd_mach_o_data_struct *); 473*3d8817e4Smiod bfd_boolean bfd_mach_o_mkobject (bfd *); 474*3d8817e4Smiod const bfd_target * bfd_mach_o_object_p (bfd *); 475*3d8817e4Smiod const bfd_target * bfd_mach_o_core_p (bfd *); 476*3d8817e4Smiod const bfd_target * bfd_mach_o_archive_p (bfd *); 477*3d8817e4Smiod bfd * bfd_mach_o_openr_next_archived_file (bfd *, bfd *); 478*3d8817e4Smiod int bfd_mach_o_lookup_section (bfd *, asection *, bfd_mach_o_load_command **, bfd_mach_o_section **); 479*3d8817e4Smiod int bfd_mach_o_lookup_command (bfd *, bfd_mach_o_load_command_type, bfd_mach_o_load_command **); 480*3d8817e4Smiod unsigned long bfd_mach_o_stack_addr (enum bfd_mach_o_cpu_type); 481*3d8817e4Smiod int bfd_mach_o_core_fetch_environment (bfd *, unsigned char **, unsigned int *); 482*3d8817e4Smiod char * bfd_mach_o_core_file_failing_command (bfd *); 483*3d8817e4Smiod int bfd_mach_o_core_file_failing_signal (bfd *); 484*3d8817e4Smiod bfd_boolean bfd_mach_o_core_file_matches_executable_p (bfd *, bfd *); 485*3d8817e4Smiod 486*3d8817e4Smiod extern const bfd_target mach_o_be_vec; 487*3d8817e4Smiod extern const bfd_target mach_o_le_vec; 488*3d8817e4Smiod extern const bfd_target mach_o_fat_vec; 489*3d8817e4Smiod 490*3d8817e4Smiod #endif /* _BFD_MACH_O_H_ */ 491