1 /**************************** coff.h ************************************* 2 * Author: Agner Fog 3 * Date created: 2006-07-15 4 * Last modified: 2008-06-04 5 * Project: objconv 6 * Module: coff.h 7 * Description: 8 * Header file for definition of structures in MS Windows COFF Intel x86 (PE) 9 * object file format. 10 * 11 * Copyright 2006-2008 GNU General Public License http://www.gnu.org/licenses 12 * Parts (c) 1995 DJ Delorie GNU General Public License 13 *****************************************************************************/ 14 15 /***************************************************************************** 16 * Note: The COFF data structures do not fit the default alignment of modern 17 * compilers. All structures should be compiled without any alignment padding. 18 * The specification of structure packing is not standardized among compilers. 19 * You may remove or replace the #pragma pack directives if you make sure that 20 * you never use the sizeof() operator or pointer arithmetics on any of the 21 * structures that need packing. See coff.cpp for examples. 22 *****************************************************************************/ 23 24 #ifndef PECOFF_H 25 #define PECOFF_H 26 27 /********************** FILE HEADER **********************/ 28 29 struct SCOFF_FileHeader { 30 uint16_t Machine; // Machine ID (magic number) 31 uint16_t NumberOfSections; // number of sections 32 uint32_t TimeDateStamp; // time & date stamp 33 uint32_t PSymbolTable; // file pointer to symbol table 34 uint32_t NumberOfSymbols; // number of symbol table entries 35 uint16_t SizeOfOptionalHeader; // size of optional header 36 uint16_t Flags; // Flags indicating attributes 37 }; 38 39 // Values of Machine: 40 #define PE_MACHINE_I386 0x14c 41 #define PE_MACHINE_X8664 0x8664 42 43 // Bits for Flags: 44 #define PE_F_RELFLG 0x0001 // relocation info stripped from file 45 #define PE_F_EXEC 0x0002 // file is executable (no unresolved external references) 46 #define PE_F_LNNO 0x0004 // line numbers stripped from file 47 #define PE_F_LSYMS 0x0008 // local symbols stripped from file 48 49 50 // Structure used in optional header 51 struct SCOFF_IMAGE_DATA_DIRECTORY { 52 uint32_t VirtualAddress; // Image relative address of table 53 uint32_t Size; // Size of table 54 }; 55 56 // Extended structure used internally with virtual address translated to section:offset 57 struct SCOFF_ImageDirAddress : public SCOFF_IMAGE_DATA_DIRECTORY { 58 int32_t Section; // Section containing table 59 uint32_t SectionOffset; // Offset relative to section 60 uint32_t FileOffset; // Offset relative to file 61 uint32_t MaxOffset; // Section size - SectionOffset 62 const char * Name; // Name of table 63 }; 64 65 // Optional header 66 union SCOFF_OptionalHeader { 67 // 32 bit version 68 struct { 69 uint16_t Magic; // Magic number 70 uint8_t LinkerMajorVersion; 71 uint8_t LinkerMinorVersion; 72 uint32_t SizeOfCode; 73 uint32_t SizeOfInitializedData; 74 uint32_t SizeOfUninitializedData; 75 uint32_t AddressOfEntryPoint; // Entry point relative to image base 76 uint32_t BaseOfCode; 77 uint32_t BaseOfData; 78 // Windows specific fields 79 int32_t ImageBase; // Image base 80 uint32_t SectionAlignment; 81 uint32_t FileAlignment; 82 uint16_t MajorOperatingSystemVersion; 83 uint16_t MinorOperatingSystemVersion; 84 uint16_t MajorImageVersion; 85 uint16_t MinorImageVersion; 86 uint16_t MajorSubsystemVersion; 87 uint16_t MinorSubsystemVersion; 88 uint32_t Win32VersionValue; // must be 0 89 uint32_t SizeOfImage; 90 uint32_t SizeOfHeaders; 91 uint32_t CheckSum; 92 uint16_t Subsystem; 93 uint16_t DllCharacteristics; 94 uint32_t SizeOfStackReserve; 95 uint32_t SizeOfStackCommit; 96 uint32_t SizeOfHeapReserve; 97 uint32_t SizeOfHeapCommit; 98 uint32_t LoaderFlags; // 0 99 uint32_t NumberOfRvaAndSizes; 100 // Data directories 101 SCOFF_IMAGE_DATA_DIRECTORY ExportTable; 102 SCOFF_IMAGE_DATA_DIRECTORY ImportTable; 103 SCOFF_IMAGE_DATA_DIRECTORY ResourceTable; 104 SCOFF_IMAGE_DATA_DIRECTORY ExceptionTable; 105 SCOFF_IMAGE_DATA_DIRECTORY CertificateTable; 106 SCOFF_IMAGE_DATA_DIRECTORY BaseRelocationTable; 107 SCOFF_IMAGE_DATA_DIRECTORY Debug; 108 SCOFF_IMAGE_DATA_DIRECTORY Architecture; // 0 109 SCOFF_IMAGE_DATA_DIRECTORY GlobalPtr; // 0 110 SCOFF_IMAGE_DATA_DIRECTORY TLSTable; 111 SCOFF_IMAGE_DATA_DIRECTORY LoadConfigTable; 112 SCOFF_IMAGE_DATA_DIRECTORY BoundImportTable; 113 SCOFF_IMAGE_DATA_DIRECTORY ImportAddressTable; 114 SCOFF_IMAGE_DATA_DIRECTORY DelayImportDescriptor; 115 SCOFF_IMAGE_DATA_DIRECTORY CLRRuntimeHeader; 116 SCOFF_IMAGE_DATA_DIRECTORY Reserved; // 0 117 } h32; 118 // 64 bit version 119 struct { 120 uint16_t Magic; // Magic number 121 uint8_t LinkerMajorVersion; 122 uint8_t LinkerMinorVersion; 123 uint32_t SizeOfCode; 124 uint32_t SizeOfInitializedData; 125 uint32_t SizeOfUninitializedData; 126 uint32_t AddressOfEntryPoint; // Entry point relative to image base 127 uint32_t BaseOfCode; 128 // Windows specific fields 129 int64_t ImageBase; // Image base 130 uint32_t SectionAlignment; 131 uint32_t FileAlignment; 132 uint16_t MajorOperatingSystemVersion; 133 uint16_t MinorOperatingSystemVersion; 134 uint16_t MajorImageVersion; 135 uint16_t MinorImageVersion; 136 uint16_t MajorSubsystemVersion; 137 uint16_t MinorSubsystemVersion; 138 uint32_t Win32VersionValue; // must be 0 139 uint32_t SizeOfImage; 140 uint32_t SizeOfHeaders; 141 uint32_t CheckSum; 142 uint16_t Subsystem; 143 uint16_t DllCharacteristics; 144 uint64_t SizeOfStackReserve; 145 uint64_t SizeOfStackCommit; 146 uint64_t SizeOfHeapReserve; 147 uint64_t SizeOfHeapCommit; 148 uint32_t LoaderFlags; // 0 149 uint32_t NumberOfRvaAndSizes; 150 // Data directories 151 SCOFF_IMAGE_DATA_DIRECTORY ExportTable; 152 SCOFF_IMAGE_DATA_DIRECTORY ImportTable; 153 SCOFF_IMAGE_DATA_DIRECTORY ResourceTable; 154 SCOFF_IMAGE_DATA_DIRECTORY ExceptionTable; 155 SCOFF_IMAGE_DATA_DIRECTORY CertificateTable; 156 SCOFF_IMAGE_DATA_DIRECTORY BaseRelocationTable; 157 SCOFF_IMAGE_DATA_DIRECTORY Debug; 158 SCOFF_IMAGE_DATA_DIRECTORY Architecture; // 0 159 SCOFF_IMAGE_DATA_DIRECTORY GlobalPtr; // 0 160 SCOFF_IMAGE_DATA_DIRECTORY TLSTable; 161 SCOFF_IMAGE_DATA_DIRECTORY LoadConfigTable; 162 SCOFF_IMAGE_DATA_DIRECTORY BoundImportTable; 163 SCOFF_IMAGE_DATA_DIRECTORY ImportAddressTable; 164 SCOFF_IMAGE_DATA_DIRECTORY DelayImportDescriptor; 165 SCOFF_IMAGE_DATA_DIRECTORY CLRRuntimeHeader; 166 SCOFF_IMAGE_DATA_DIRECTORY Reserved; // 0 167 } h64; 168 }; 169 170 // Value of Magic for optional header 171 #define COFF_Magic_PE32 0x10B 172 #define COFF_Magic_PE64 0x20B 173 174 // Export directory table 175 struct SCOFF_ExportDirectory { 176 uint32_t Flags; 177 uint32_t DateTime; 178 uint16_t VersionMajor; 179 uint16_t VersionMinor; 180 uint32_t DLLNameRVA; // Image-relative address of DLL name 181 uint32_t OrdinalBase; // Ordinal number of first export 182 uint32_t AddressTableEntries; // Number of entries in export address table 183 uint32_t NamePointerEntries; // Number of entries in name pointer table 184 uint32_t ExportAddressTableRVA; // Image-relative address of export address table 185 uint32_t NamePointerTableRVA; // Image-relative address of export name pointer table 186 uint32_t OrdinalTableRVA; // Image-relative address of ordinal table 187 }; 188 189 // Import directory table 190 struct SCOFF_ImportDirectory { 191 uint32_t ImportLookupTableRVA; // Image-relative address of import lookup table 192 uint32_t DateTime; 193 uint32_t ForwarderChain; 194 uint32_t DLLNameRVA; // Image-relative address of DLL name string 195 uint32_t ImportAddressTableRVA; // Image-relative address of import address table 196 }; 197 198 // Import hint/name table entry 199 struct SCOFF_ImportHintName { 200 uint16_t Hint; // Index into export name pointer table 201 char Name[2]; // Variable length 202 }; 203 204 // Base relocation block header 205 struct SCOFF_BaseRelocationBlock { 206 uint32_t PageRVA; // Image-relative base to add to offset 207 uint32_t BlockSize; // Size of SCOFF_BaseRelocationBlock plus all SCOFF_BaseRelocation 208 }; 209 210 // Base relocation block entry 211 struct SCOFF_BaseRelocation { 212 uint16_t Offset:12; // Offset relative to PageRVA 213 uint16_t Type:4; // Base relocation type 214 }; 215 216 // Base relocation types 217 #define COFF_REL_BASED_ABSOLUTE 0 // Ignore 218 #define COFF_REL_BASED_HIGH 1 // High 16 bits 219 #define COFF_REL_BASED_LOW 2 // Low 16 bits 220 #define COFF_REL_BASED_HIGHLOW 3 // 32 bits 221 #define COFF_REL_BASED_HIGHADJ 4 // Two consecutive records: 16 bits high, 16 bits low 222 #define COFF_REL_BASED_DIR64 10 // 64 bits 223 224 225 /********************** SECTION HEADER **********************/ 226 227 struct SCOFF_SectionHeader { 228 char Name[8]; // section name 229 uint32_t VirtualSize; // size of section when loaded. (Should be 0 for object files, but it seems to be accumulated size of all sections) 230 uint32_t VirtualAddress; // subtracted from offsets during relocation. preferably 0 231 uint32_t SizeOfRawData; // section size in file 232 uint32_t PRawData; // file to raw data for section 233 uint32_t PRelocations; // file to relocation entries 234 uint32_t PLineNumbers; // file to line number entries 235 uint16_t NRelocations; // number of relocation entries 236 uint16_t NLineNumbers; // number of line number entries 237 uint32_t Flags; // flags 238 }; 239 240 // Section flags values 241 #define PE_SCN_CNT_CODE 0x00000020 // section contains executable code 242 #define PE_SCN_CNT_INIT_DATA 0x00000040 // section contains initialized data 243 #define PE_SCN_CNT_UNINIT_DATA 0x00000080 // section contains unintialized data 244 #define PE_SCN_LNK_INFO 0x00000200 // section contains comments or .drectve 245 #define PE_SCN_LNK_REMOVE 0x00000800 // will not be part of the image. object files only 246 #define PE_SCN_LNK_COMDAT 0x00001000 // section contains communal data 247 #define PE_SCN_ALIGN_1 0x00100000 // Align data by 1 248 #define PE_SCN_ALIGN_2 0x00200000 // Align data by 2 249 #define PE_SCN_ALIGN_4 0x00300000 // Align data by 4 250 #define PE_SCN_ALIGN_8 0x00400000 // Align data by 8 251 #define PE_SCN_ALIGN_16 0x00500000 // Align data by 16 252 #define PE_SCN_ALIGN_32 0x00600000 // Align data by 32 253 #define PE_SCN_ALIGN_64 0x00700000 // Align data by 64 254 #define PE_SCN_ALIGN_128 0x00800000 // Align data by 128 255 #define PE_SCN_ALIGN_256 0x00900000 // Align data by 256 256 #define PE_SCN_ALIGN_512 0x00a00000 // Align data by 512 257 #define PE_SCN_ALIGN_1024 0x00b00000 // Align data by 1024 258 #define PE_SCN_ALIGN_2048 0x00c00000 // Align data by 2048 259 #define PE_SCN_ALIGN_4096 0x00d00000 // Align data by 4096 260 #define PE_SCN_ALIGN_8192 0x00e00000 // Align data by 8192 261 #define PE_SCN_ALIGN_MASK 0x00f00000 // Mask for extracting alignment info 262 #define PE_SCN_LNK_NRELOC_OVFL 0x01000000 // section contains extended relocations 263 #define PE_SCN_MEM_DISCARDABLE 0x02000000 // section is discardable 264 #define PE_SCN_MEM_NOT_CACHED 0x04000000 // section cannot be cached 265 #define PE_SCN_MEM_NOT_PAGED 0x08000000 // section is not pageable 266 #define PE_SCN_MEM_SHARED 0x10000000 // section can be shared 267 #define PE_SCN_MEM_EXECUTE 0x20000000 // section is executable 268 #define PE_SCN_MEM_READ 0x40000000 // section is readable 269 #define PE_SCN_MEM_WRITE 0x80000000 // section is writeable 270 271 /* names of "special" sections 272 #define _TEXT ".text" 273 #define _DATA ".data" 274 #define _BSS ".bss" 275 #define _COMMENT ".comment" 276 #define _LIB ".lib" */ 277 278 /********************** LINE NUMBERS **********************/ 279 280 /* 1 line number entry for every "breakpointable" source line in a section. 281 * Line numbers are grouped on a per function basis; first entry in a function 282 * grouping will have l_lnno = 0 and in place of physical address will be the 283 * symbol table index of the function name. 284 */ 285 //#pragma pack(push, 1) 286 struct SCOFF_LineNumbers { 287 union { 288 uint32_t Fname; // function name symbol table index, if Line == 0 289 uint32_t Addr; // section-relative address of code that corresponds to line 290 }; 291 uint16_t Line; // line number 292 }; 293 294 // Warning: Size does not fit standard alignment! 295 // Use SIZE_SCOFF_LineNumbers instead of sizeof(SCOFF_LineNumbers) 296 #define SIZE_SCOFF_LineNumbers 6 // Size of SCOFF_LineNumbers packed 297 298 //#pragma pack(pop) 299 300 301 /******** Symbol table entry and auxiliary Symbol table entry ********/ 302 //#pragma pack(push, 1) //__attribute__((packed)); 303 304 union SCOFF_SymTableEntry { 305 // Normal symbol table entry 306 struct { 307 char Name[8]; 308 uint32_t Value; 309 int16_t SectionNumber; 310 uint16_t Type; 311 uint8_t StorageClass; 312 uint8_t NumAuxSymbols; 313 } s; 314 // Auxiliary symbol table entry types: 315 316 // Function definition 317 struct { 318 uint32_t TagIndex; // Index to .bf entry 319 uint32_t TotalSize; // Size of function code 320 uint32_t PointerToLineNumber; // Pointer to line number entry 321 uint32_t PointerToNextFunction; // Symbol table index of next function 322 uint16_t x_tvndx; // Unused 323 } func; 324 325 // .bf abd .ef 326 struct { 327 uint32_t Unused1; 328 uint16_t SourceLineNumber; // Line number in source file 329 uint16_t Unused2; 330 uint32_t Unused3; // Pointer to line number entry 331 uint32_t PointerToNextFunction; // Symbol table index of next function 332 uint16_t Unused4; // Unused 333 } bfef; 334 335 // Weak external 336 struct { 337 uint32_t TagIndex; // Symbol table index of alternative symbol2 338 uint32_t Characteristics; // 339 uint32_t Unused1; 340 uint32_t Unused2; 341 uint16_t Unused3; // Unused 342 } weak; 343 344 // File name 345 struct { 346 char FileName[18];// File name 347 } filename; 348 349 // String table index 350 struct { // MS COFF uses multiple aux records rather than a string table entry! 351 uint32_t zeroes; // zeroes if name file name longer than 18 352 uint32_t offset; // string table entry 353 } stringindex; 354 355 // Section definition 356 struct { 357 uint32_t Length; 358 uint16_t NumberOfRelocations; // Line number in source file 359 uint16_t NumberOfLineNumbers; 360 uint32_t CheckSum; // Pointer to line number entry 361 uint16_t Number; // Symbol table index of next function 362 uint8_t Selection; // Unused 363 uint8_t Unused1[3]; 364 } section; 365 }; 366 367 // Warning: Size does not fit standard alignment! 368 // Use SIZE_SCOFF_SymTableEntry instead of sizeof(SCOFF_SymTableEntry) 369 #define SIZE_SCOFF_SymTableEntry 18 // Size of SCOFF_SymTableEntry packed 370 371 // values of weak.Characteristics 372 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 373 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 374 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 375 376 /* 377 #define N_BTMASK (0xf) 378 #define N_TMASK (0x30) 379 #define N_BTSHFT (4) 380 #define N_TSHIFT (2) */ 381 382 //#pragma pack(pop) 383 384 /********************** Section number values for symbol table entries **********************/ 385 386 #define COFF_SECTION_UNDEF ((int16_t)0) // external symbol 387 #define COFF_SECTION_ABSOLUTE ((int16_t)-1) // value of symbol is absolute 388 #define COFF_SECTION_DEBUG ((int16_t)-2) // debugging symbol - value is meaningless 389 #define COFF_SECTION_N_TV ((int16_t)-3) // indicates symbol needs preload transfer vector 390 #define COFF_SECTION_P_TV ((int16_t)-4) // indicates symbol needs postload transfer vector 391 #define COFF_SECTION_REMOVE_ME ((int16_t)-99)// Specific for objconv program: Debug or exception section being removed 392 393 /* 394 * Type of a symbol, in low N bits of the word 395 396 #define T_NULL 0 397 #define T_VOID 1 // function argument (only used by compiler) 398 #define T_CHAR 2 // character 399 #define T_SHORT 3 // short integer 400 #define T_INT 4 // integer 401 #define T_LONG 5 // long integer 402 #define T_FLOAT 6 // floating point 403 #define T_DOUBLE 7 // double word 404 #define T_STRUCT 8 // structure 405 #define T_UNION 9 // union 406 #define T_ENUM 10 // enumeration 407 #define T_MOE 11 // member of enumeration 408 #define T_UCHAR 12 // unsigned character 409 #define T_USHORT 13 // uint16_t 410 #define T_UINT 14 // unsigned integer 411 #define T_ULONG 15 // uint32_t 412 #define T_LNGDBL 16 // long double 413 */ 414 /* 415 * derived types, in n_type 416 417 #define DT_NON (0) // no derived type 418 #define DT_PTR (1) // pointer 419 #define DT_FCN (2) // function 420 #define DT_ARY (3) // array 421 422 #define BTYPE(x) ((x) & N_BTMASK) 423 424 #define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT)) 425 #define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT)) 426 #define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT)) 427 #define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG) 428 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK)) 429 */ 430 /********************** Storage classes for symbol table entries **********************/ 431 432 #define COFF_CLASS_NULL 0 433 #define COFF_CLASS_AUTOMATIC 1 // automatic variable 434 #define COFF_CLASS_EXTERNAL 2 // external symbol 435 #define COFF_CLASS_STATIC 3 // static 436 #define COFF_CLASS_REGISTER 4 // register variable 437 #define COFF_CLASS_EXTERNAL_DEF 5 // external definition 438 #define COFF_CLASS_LABEL 6 // label 439 #define COFF_CLASS_UNDEFINED_LABEL 7 // undefined label 440 #define COFF_CLASS_MEMBER_OF_STRUCTURE 8 // member of structure 441 #define COFF_CLASS_ARGUMENT 9 // function argument 442 #define COFF_CLASS_STRUCTURE_TAG 10 // structure tag 443 #define COFF_CLASS_MEMBER_OF_UNION 11 // member of union 444 #define COFF_CLASS_UNION_TAG 12 // union tag 445 #define COFF_CLASS_TYPE_DEFINITION 13 // type definition 446 #define COFF_CLASS_UNDEFINED_STATIC 14 // undefined static 447 #define COFF_CLASS_ENUM_TAG 15 // enumeration tag 448 #define COFF_CLASS_MEMBER_OF_ENUM 16 // member of enumeration 449 #define COFF_CLASS_REGISTER_PARAM 17 // register parameter 450 #define COFF_CLASS_BIT_FIELD 18 // bit field 451 #define COFF_CLASS_AUTO_ARGUMENT 19 // auto argument 452 #define COFF_CLASS_LASTENTRY 20 // dummy entry (end of block) 453 #define COFF_CLASS_BLOCK 100 // ".bb" or ".eb" 454 #define COFF_CLASS_FUNCTION 101 // ".bf" or ".ef" 455 #define COFF_CLASS_END_OF_STRUCT 102 // end of structure 456 #define COFF_CLASS_FILE 103 // file name 457 #define COFF_CLASS_LINE 104 // line # reformatted as symbol table entry 458 #define COFF_CLASS_SECTION 104 // line # reformatted as symbol table entry 459 #define COFF_CLASS_ALIAS 105 // duplicate tag 460 #define COFF_CLASS_WEAK_EXTERNAL 105 // duplicate tag 461 #define COFF_CLASS_HIDDEN 106 // ext symbol in dmert public lib 462 #define COFF_CLASS_END_OF_FUNCTION 0xff // physical end of function 463 464 /********************** Type for symbol table entries **********************/ 465 #define COFF_TYPE_FUNCTION 0x20 // Symbol is function 466 #define COFF_TYPE_NOT_FUNCTION 0x00 // Symbol is not a function 467 468 469 /********************** Relocation table entry **********************/ 470 //#pragma pack(push, 1) //__attribute__((packed)); 471 472 struct SCOFF_Relocation { 473 uint32_t VirtualAddress; // Section-relative address of relocation source 474 uint32_t SymbolTableIndex; // Zero-based index into symbol table 475 uint16_t Type; // Relocation type 476 }; 477 #define SIZE_SCOFF_Relocation 10 // Size of SCOFF_Relocation packed 478 //#pragma pack(pop) 479 480 481 /********************** Relocation types for 32-bit COFF **********************/ 482 483 #define COFF32_RELOC_ABS 0x00 // Ignored 484 #define COFF32_RELOC_DIR16 0x01 // Not supported 485 #define COFF32_RELOC_REL16 0x02 // Not supported 486 #define COFF32_RELOC_DIR32 0x06 // 32-bit absolute virtual address 487 #define COFF32_RELOC_IMGREL 0x07 // 32-bit image relative virtual address 488 #define COFF32_RELOC_SEG12 0x09 // not supported 489 #define COFF32_RELOC_SECTION 0x0A // 16-bit section index in file 490 #define COFF32_RELOC_SECREL 0x0B // 32-bit section-relative 491 #define COFF32_RELOC_SECREL7 0x0D // 7-bit section-relative 492 #define COFF32_RELOC_TOKEN 0x0C // CLR token 493 #define COFF32_RELOC_REL32 0x14 // 32-bit EIP-relative 494 495 /********************** Relocation types for 64-bit COFF **********************/ 496 // Note: These values are obtained by my own testing. 497 // I haven't found any official values 498 499 #define COFF64_RELOC_ABS 0x00 // Ignored 500 #define COFF64_RELOC_ABS64 0x01 // 64 bit absolute virtual address 501 #define COFF64_RELOC_ABS32 0x02 // 32 bit absolute virtual address 502 #define COFF64_RELOC_IMGREL 0x03 // 32 bit image-relative 503 #define COFF64_RELOC_REL32 0x04 // 32 bit, RIP-relative 504 #define COFF64_RELOC_REL32_1 0x05 // 32 bit, relative to RIP - 1. For instruction with immediate byte operand 505 #define COFF64_RELOC_REL32_2 0x06 // 32 bit, relative to RIP - 2. For instruction with immediate word operand 506 #define COFF64_RELOC_REL32_3 0x07 // 32 bit, relative to RIP - 3. (useless) 507 #define COFF64_RELOC_REL32_4 0x08 // 32 bit, relative to RIP - 4. For instruction with immediate dword operand 508 #define COFF64_RELOC_REL32_5 0x09 // 32 bit, relative to RIP - 5. (useless) 509 #define COFF64_RELOC_SECTION 0x0A // 16-bit section index in file. For debug purpose 510 #define COFF64_RELOC_SECREL 0x0B // 32-bit section-relative 511 #define COFF64_RELOC_SECREL7 0x0C // 7-bit section-relative 512 #define COFF64_RELOC_TOKEN 0x0D // CLR token = 64 bit absolute virtual address. Inline addend ignored 513 #define COFF64_RELOC_SREL32 0x0E // 32 bit signed span dependent 514 #define COFF64_RELOC_PAIR 0x0F // pair after span dependent 515 #define COFF64_RELOC_PPC_REFHI 0x10 // high 16 bits of 32 bit abs addr 516 #define COFF64_RELOC_PPC_REFLO 0x11 // low 16 bits of 32 bit abs addr 517 #define COFF64_RELOC_PPC_PAIR 0x12 // pair after REFHI 518 #define COFF64_RELOC_PPC_SECRELO 0x13 // low 16 bits of section relative 519 #define COFF64_RELOC_PPC_GPREL 0x15 // 16 bit signed relative to GP 520 #define COFF64_RELOC_PPC_TOKEN 0x16 // CLR token 521 522 /********************** Strings **********************/ 523 #define COFF_CONSTRUCTOR_NAME ".CRT$XCU" // Name of constructors segment 524 525 526 // Function prototypes 527 528 // Function to put a name into SCOFF_SymTableEntry. Put name in string table 529 // if longer than 8 characters 530 uint32_t COFF_PutNameInSymbolTable(SCOFF_SymTableEntry & sym, const char * name, CMemoryBuffer & StringTable); 531 532 // Function to put a name into SCOFF_SectionHeader. Put name in string table 533 // if longer than 8 characters 534 void COFF_PutNameInSectionHeader(SCOFF_SectionHeader & sec, const char * name, CMemoryBuffer & StringTable); 535 536 537 #endif // #ifndef PECOFF_H 538