1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package xcoff 6 7 // File Header. 8 type FileHeader32 struct { 9 Fmagic uint16 // Target machine 10 Fnscns uint16 // Number of sections 11 Ftimedat uint32 // Time and date of file creation 12 Fsymptr uint32 // Byte offset to symbol table start 13 Fnsyms uint32 // Number of entries in symbol table 14 Fopthdr uint16 // Number of bytes in optional header 15 Fflags uint16 // Flags 16 } 17 18 type FileHeader64 struct { 19 Fmagic uint16 // Target machine 20 Fnscns uint16 // Number of sections 21 Ftimedat uint32 // Time and date of file creation 22 Fsymptr uint64 // Byte offset to symbol table start 23 Fopthdr uint16 // Number of bytes in optional header 24 Fflags uint16 // Flags 25 Fnsyms uint32 // Number of entries in symbol table 26 } 27 28 const ( 29 FILHSZ_32 = 20 30 FILHSZ_64 = 24 31 ) 32 const ( 33 U802TOCMAGIC = 0737 // AIX 32-bit XCOFF 34 U64_TOCMAGIC = 0767 // AIX 64-bit XCOFF 35 ) 36 37 // Flags that describe the type of the object file. 38 const ( 39 F_RELFLG = 0x0001 40 F_EXEC = 0x0002 41 F_LNNO = 0x0004 42 F_FDPR_PROF = 0x0010 43 F_FDPR_OPTI = 0x0020 44 F_DSA = 0x0040 45 F_VARPG = 0x0100 46 F_DYNLOAD = 0x1000 47 F_SHROBJ = 0x2000 48 F_LOADONLY = 0x4000 49 ) 50 51 // Section Header. 52 type SectionHeader32 struct { 53 Sname [8]byte // Section name 54 Spaddr uint32 // Physical address 55 Svaddr uint32 // Virtual address 56 Ssize uint32 // Section size 57 Sscnptr uint32 // Offset in file to raw data for section 58 Srelptr uint32 // Offset in file to relocation entries for section 59 Slnnoptr uint32 // Offset in file to line number entries for section 60 Snreloc uint16 // Number of relocation entries 61 Snlnno uint16 // Number of line number entries 62 Sflags uint32 // Flags to define the section type 63 } 64 65 type SectionHeader64 struct { 66 Sname [8]byte // Section name 67 Spaddr uint64 // Physical address 68 Svaddr uint64 // Virtual address 69 Ssize uint64 // Section size 70 Sscnptr uint64 // Offset in file to raw data for section 71 Srelptr uint64 // Offset in file to relocation entries for section 72 Slnnoptr uint64 // Offset in file to line number entries for section 73 Snreloc uint32 // Number of relocation entries 74 Snlnno uint32 // Number of line number entries 75 Sflags uint32 // Flags to define the section type 76 Spad uint32 // Needs to be 72 bytes long 77 } 78 79 // Flags defining the section type. 80 const ( 81 STYP_DWARF = 0x0010 82 STYP_TEXT = 0x0020 83 STYP_DATA = 0x0040 84 STYP_BSS = 0x0080 85 STYP_EXCEPT = 0x0100 86 STYP_INFO = 0x0200 87 STYP_TDATA = 0x0400 88 STYP_TBSS = 0x0800 89 STYP_LOADER = 0x1000 90 STYP_DEBUG = 0x2000 91 STYP_TYPCHK = 0x4000 92 STYP_OVRFLO = 0x8000 93 ) 94 const ( 95 SSUBTYP_DWINFO = 0x10000 // DWARF info section 96 SSUBTYP_DWLINE = 0x20000 // DWARF line-number section 97 SSUBTYP_DWPBNMS = 0x30000 // DWARF public names section 98 SSUBTYP_DWPBTYP = 0x40000 // DWARF public types section 99 SSUBTYP_DWARNGE = 0x50000 // DWARF aranges section 100 SSUBTYP_DWABREV = 0x60000 // DWARF abbreviation section 101 SSUBTYP_DWSTR = 0x70000 // DWARF strings section 102 SSUBTYP_DWRNGES = 0x80000 // DWARF ranges section 103 SSUBTYP_DWLOC = 0x90000 // DWARF location lists section 104 SSUBTYP_DWFRAME = 0xA0000 // DWARF frames section 105 SSUBTYP_DWMAC = 0xB0000 // DWARF macros section 106 ) 107 108 // Symbol Table Entry. 109 type SymEnt32 struct { 110 Nname [8]byte // Symbol name 111 Nvalue uint32 // Symbol value 112 Nscnum uint16 // Section number of symbol 113 Ntype uint16 // Basic and derived type specification 114 Nsclass uint8 // Storage class of symbol 115 Nnumaux uint8 // Number of auxiliary entries 116 } 117 118 type SymEnt64 struct { 119 Nvalue uint64 // Symbol value 120 Noffset uint32 // Offset of the name in string table or .debug section 121 Nscnum uint16 // Section number of symbol 122 Ntype uint16 // Basic and derived type specification 123 Nsclass uint8 // Storage class of symbol 124 Nnumaux uint8 // Number of auxiliary entries 125 } 126 127 const SYMESZ = 18 128 129 const ( 130 // Nscnum 131 N_DEBUG = -2 132 N_ABS = -1 133 N_UNDEF = 0 134 135 //Ntype 136 SYM_V_INTERNAL = 0x1000 137 SYM_V_HIDDEN = 0x2000 138 SYM_V_PROTECTED = 0x3000 139 SYM_V_EXPORTED = 0x4000 140 SYM_TYPE_FUNC = 0x0020 // is function 141 ) 142 143 // Storage Class. 144 const ( 145 C_NULL = 0 // Symbol table entry marked for deletion 146 C_EXT = 2 // External symbol 147 C_STAT = 3 // Static symbol 148 C_BLOCK = 100 // Beginning or end of inner block 149 C_FCN = 101 // Beginning or end of function 150 C_FILE = 103 // Source file name and compiler information 151 C_HIDEXT = 107 // Unnamed external symbol 152 C_BINCL = 108 // Beginning of include file 153 C_EINCL = 109 // End of include file 154 C_WEAKEXT = 111 // Weak external symbol 155 C_DWARF = 112 // DWARF symbol 156 C_GSYM = 128 // Global variable 157 C_LSYM = 129 // Automatic variable allocated on stack 158 C_PSYM = 130 // Argument to subroutine allocated on stack 159 C_RSYM = 131 // Register variable 160 C_RPSYM = 132 // Argument to function or procedure stored in register 161 C_STSYM = 133 // Statically allocated symbol 162 C_BCOMM = 135 // Beginning of common block 163 C_ECOML = 136 // Local member of common block 164 C_ECOMM = 137 // End of common block 165 C_DECL = 140 // Declaration of object 166 C_ENTRY = 141 // Alternate entry 167 C_FUN = 142 // Function or procedure 168 C_BSTAT = 143 // Beginning of static block 169 C_ESTAT = 144 // End of static block 170 C_GTLS = 145 // Global thread-local variable 171 C_STTLS = 146 // Static thread-local variable 172 ) 173 174 // File Auxiliary Entry 175 type AuxFile64 struct { 176 Xfname [8]byte // Name or offset inside string table 177 Xftype uint8 // Source file string type 178 Xauxtype uint8 // Type of auxiliary entry 179 } 180 181 // Function Auxiliary Entry 182 type AuxFcn32 struct { 183 Xexptr uint32 // File offset to exception table entry 184 Xfsize uint32 // Size of function in bytes 185 Xlnnoptr uint32 // File pointer to line number 186 Xendndx uint32 // Symbol table index of next entry 187 Xpad uint16 // Unused 188 } 189 type AuxFcn64 struct { 190 Xlnnoptr uint64 // File pointer to line number 191 Xfsize uint32 // Size of function in bytes 192 Xendndx uint32 // Symbol table index of next entry 193 Xpad uint8 // Unused 194 Xauxtype uint8 // Type of auxiliary entry 195 } 196 197 type AuxSect64 struct { 198 Xscnlen uint64 // section length 199 Xnreloc uint64 // Num RLDs 200 pad uint8 201 Xauxtype uint8 // Type of auxiliary entry 202 } 203 204 // csect Auxiliary Entry. 205 type AuxCSect32 struct { 206 Xscnlen uint32 // Length or symbol table index 207 Xparmhash uint32 // Offset of parameter type-check string 208 Xsnhash uint16 // .typchk section number 209 Xsmtyp uint8 // Symbol alignment and type 210 Xsmclas uint8 // Storage-mapping class 211 Xstab uint32 // Reserved 212 Xsnstab uint16 // Reserved 213 } 214 215 type AuxCSect64 struct { 216 Xscnlenlo uint32 // Lower 4 bytes of length or symbol table index 217 Xparmhash uint32 // Offset of parameter type-check string 218 Xsnhash uint16 // .typchk section number 219 Xsmtyp uint8 // Symbol alignment and type 220 Xsmclas uint8 // Storage-mapping class 221 Xscnlenhi uint32 // Upper 4 bytes of length or symbol table index 222 Xpad uint8 // Unused 223 Xauxtype uint8 // Type of auxiliary entry 224 } 225 226 // Auxiliary type 227 const ( 228 _AUX_EXCEPT = 255 229 _AUX_FCN = 254 230 _AUX_SYM = 253 231 _AUX_FILE = 252 232 _AUX_CSECT = 251 233 _AUX_SECT = 250 234 ) 235 236 // Symbol type field. 237 const ( 238 XTY_ER = 0 // External reference 239 XTY_SD = 1 // Section definition 240 XTY_LD = 2 // Label definition 241 XTY_CM = 3 // Common csect definition 242 ) 243 244 // Defines for File auxiliary definitions: x_ftype field of x_file 245 const ( 246 XFT_FN = 0 // Source File Name 247 XFT_CT = 1 // Compile Time Stamp 248 XFT_CV = 2 // Compiler Version Number 249 XFT_CD = 128 // Compiler Defined Information 250 ) 251 252 // Storage-mapping class. 253 const ( 254 XMC_PR = 0 // Program code 255 XMC_RO = 1 // Read-only constant 256 XMC_DB = 2 // Debug dictionary table 257 XMC_TC = 3 // TOC entry 258 XMC_UA = 4 // Unclassified 259 XMC_RW = 5 // Read/Write data 260 XMC_GL = 6 // Global linkage 261 XMC_XO = 7 // Extended operation 262 XMC_SV = 8 // 32-bit supervisor call descriptor 263 XMC_BS = 9 // BSS class 264 XMC_DS = 10 // Function descriptor 265 XMC_UC = 11 // Unnamed FORTRAN common 266 XMC_TC0 = 15 // TOC anchor 267 XMC_TD = 16 // Scalar data entry in the TOC 268 XMC_SV64 = 17 // 64-bit supervisor call descriptor 269 XMC_SV3264 = 18 // Supervisor call descriptor for both 32-bit and 64-bit 270 XMC_TL = 20 // Read/Write thread-local data 271 XMC_UL = 21 // Read/Write thread-local data (.tbss) 272 XMC_TE = 22 // TOC entry 273 ) 274 275 // Loader Header. 276 type LoaderHeader32 struct { 277 Lversion uint32 // Loader section version number 278 Lnsyms uint32 // Number of symbol table entries 279 Lnreloc uint32 // Number of relocation table entries 280 Listlen uint32 // Length of import file ID string table 281 Lnimpid uint32 // Number of import file IDs 282 Limpoff uint32 // Offset to start of import file IDs 283 Lstlen uint32 // Length of string table 284 Lstoff uint32 // Offset to start of string table 285 } 286 287 type LoaderHeader64 struct { 288 Lversion uint32 // Loader section version number 289 Lnsyms uint32 // Number of symbol table entries 290 Lnreloc uint32 // Number of relocation table entries 291 Listlen uint32 // Length of import file ID string table 292 Lnimpid uint32 // Number of import file IDs 293 Lstlen uint32 // Length of string table 294 Limpoff uint64 // Offset to start of import file IDs 295 Lstoff uint64 // Offset to start of string table 296 Lsymoff uint64 // Offset to start of symbol table 297 Lrldoff uint64 // Offset to start of relocation entries 298 } 299 300 const ( 301 LDHDRSZ_32 = 32 302 LDHDRSZ_64 = 56 303 ) 304 305 // Loader Symbol. 306 type LoaderSymbol32 struct { 307 Lname [8]byte // Symbol name or byte offset into string table 308 Lvalue uint32 // Address field 309 Lscnum uint16 // Section number containing symbol 310 Lsmtype uint8 // Symbol type, export, import flags 311 Lsmclas uint8 // Symbol storage class 312 Lifile uint32 // Import file ID; ordinal of import file IDs 313 Lparm uint32 // Parameter type-check field 314 } 315 316 type LoaderSymbol64 struct { 317 Lvalue uint64 // Address field 318 Loffset uint32 // Byte offset into string table of symbol name 319 Lscnum uint16 // Section number containing symbol 320 Lsmtype uint8 // Symbol type, export, import flags 321 Lsmclas uint8 // Symbol storage class 322 Lifile uint32 // Import file ID; ordinal of import file IDs 323 Lparm uint32 // Parameter type-check field 324 } 325 326 type Reloc32 struct { 327 Rvaddr uint32 // (virtual) address of reference 328 Rsymndx uint32 // Index into symbol table 329 Rsize uint8 // Sign and reloc bit len 330 Rtype uint8 // Toc relocation type 331 } 332 333 type Reloc64 struct { 334 Rvaddr uint64 // (virtual) address of reference 335 Rsymndx uint32 // Index into symbol table 336 Rsize uint8 // Sign and reloc bit len 337 Rtype uint8 // Toc relocation type 338 } 339 340 const ( 341 R_POS = 0x00 // A(sym) Positive Relocation 342 R_NEG = 0x01 // -A(sym) Negative Relocation 343 R_REL = 0x02 // A(sym-*) Relative to self 344 R_TOC = 0x03 // A(sym-TOC) Relative to TOC 345 R_TRL = 0x12 // A(sym-TOC) TOC Relative indirect load. 346 347 R_TRLA = 0x13 // A(sym-TOC) TOC Rel load address. modifiable inst 348 R_GL = 0x05 // A(external TOC of sym) Global Linkage 349 R_TCL = 0x06 // A(local TOC of sym) Local object TOC address 350 R_RL = 0x0C // A(sym) Pos indirect load. modifiable instruction 351 R_RLA = 0x0D // A(sym) Pos Load Address. modifiable instruction 352 R_REF = 0x0F // AL0(sym) Non relocating ref. No garbage collect 353 R_BA = 0x08 // A(sym) Branch absolute. Cannot modify instruction 354 R_RBA = 0x18 // A(sym) Branch absolute. modifiable instruction 355 R_BR = 0x0A // A(sym-*) Branch rel to self. non modifiable 356 R_RBR = 0x1A // A(sym-*) Branch rel to self. modifiable instr 357 358 R_TLS = 0x20 // General-dynamic reference to TLS symbol 359 R_TLS_IE = 0x21 // Initial-exec reference to TLS symbol 360 R_TLS_LD = 0x22 // Local-dynamic reference to TLS symbol 361 R_TLS_LE = 0x23 // Local-exec reference to TLS symbol 362 R_TLSM = 0x24 // Module reference to TLS symbol 363 R_TLSML = 0x25 // Module reference to local (own) module 364 365 R_TOCU = 0x30 // Relative to TOC - high order bits 366 R_TOCL = 0x31 // Relative to TOC - low order bits 367 ) 368