1 //===-- llvm/Support/COFF.h -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file contains an definitions used in Windows COFF Files. 11 // 12 // Structures and enums defined within this file where created using 13 // information from Microsoft's publicly available PE/COFF format document: 14 // 15 // Microsoft Portable Executable and Common Object File Format Specification 16 // Revision 8.1 - February 15, 2008 17 // 18 // As of 5/2/2010, hosted by Microsoft at: 19 // http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx 20 // 21 //===----------------------------------------------------------------------===// 22 23 #ifndef LLVM_SUPPORT_WIN_COFF_H 24 #define LLVM_SUPPORT_WIN_COFF_H 25 26 #include "llvm/Support/DataTypes.h" 27 #include <cassert> 28 #include <cstring> 29 30 namespace llvm { 31 namespace COFF { 32 33 // Sizes in bytes of various things in the COFF format. 34 enum { 35 HeaderSize = 20, 36 NameSize = 8, 37 SymbolSize = 18, 38 SectionSize = 40, 39 RelocationSize = 10 40 }; 41 42 struct header { 43 uint16_t Machine; 44 uint16_t NumberOfSections; 45 uint32_t TimeDateStamp; 46 uint32_t PointerToSymbolTable; 47 uint32_t NumberOfSymbols; 48 uint16_t SizeOfOptionalHeader; 49 uint16_t Characteristics; 50 }; 51 52 enum MachineTypes { 53 IMAGE_FILE_MACHINE_UNKNOWN = 0x0, 54 IMAGE_FILE_MACHINE_AM33 = 0x13, 55 IMAGE_FILE_MACHINE_AMD64 = 0x8664, 56 IMAGE_FILE_MACHINE_ARM = 0x1C0, 57 IMAGE_FILE_MACHINE_ARMV7 = 0x1C4, 58 IMAGE_FILE_MACHINE_EBC = 0xEBC, 59 IMAGE_FILE_MACHINE_I386 = 0x14C, 60 IMAGE_FILE_MACHINE_IA64 = 0x200, 61 IMAGE_FILE_MACHINE_M32R = 0x9041, 62 IMAGE_FILE_MACHINE_MIPS16 = 0x266, 63 IMAGE_FILE_MACHINE_MIPSFPU = 0x366, 64 IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466, 65 IMAGE_FILE_MACHINE_POWERPC = 0x1F0, 66 IMAGE_FILE_MACHINE_POWERPCFP = 0x1F1, 67 IMAGE_FILE_MACHINE_R4000 = 0x166, 68 IMAGE_FILE_MACHINE_SH3 = 0x1A2, 69 IMAGE_FILE_MACHINE_SH3DSP = 0x1A3, 70 IMAGE_FILE_MACHINE_SH4 = 0x1A6, 71 IMAGE_FILE_MACHINE_SH5 = 0x1A8, 72 IMAGE_FILE_MACHINE_THUMB = 0x1C2, 73 IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 74 }; 75 76 enum Characteristics { 77 /// The file does not contain base relocations and must be loaded at its 78 /// preferred base. If this cannot be done, the loader will error. 79 IMAGE_FILE_RELOCS_STRIPPED = 0x0001, 80 /// The file is valid and can be run. 81 IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002, 82 /// COFF line numbers have been stripped. This is deprecated and should be 83 /// 0. 84 IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004, 85 /// COFF symbol table entries for local symbols have been removed. This is 86 /// deprecated and should be 0. 87 IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008, 88 /// Aggressively trim working set. This is deprecated and must be 0. 89 IMAGE_FILE_AGGRESSIVE_WS_TRIM = 0x0010, 90 /// Image can handle > 2GiB addresses. 91 IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020, 92 /// Little endian: the LSB precedes the MSB in memory. This is deprecated 93 /// and should be 0. 94 IMAGE_FILE_BYTES_REVERSED_LO = 0x0080, 95 /// Machine is based on a 32bit word architecture. 96 IMAGE_FILE_32BIT_MACHINE = 0x0100, 97 /// Debugging info has been removed. 98 IMAGE_FILE_DEBUG_STRIPPED = 0x0200, 99 /// If the image is on removable media, fully load it and copy it to swap. 100 IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400, 101 /// If the image is on network media, fully load it and copy it to swap. 102 IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800, 103 /// The image file is a system file, not a user program. 104 IMAGE_FILE_SYSTEM = 0x1000, 105 /// The image file is a DLL. 106 IMAGE_FILE_DLL = 0x2000, 107 /// This file should only be run on a uniprocessor machine. 108 IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000, 109 /// Big endian: the MSB precedes the LSB in memory. This is deprecated 110 /// and should be 0. 111 IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 112 }; 113 114 struct symbol { 115 char Name[NameSize]; 116 uint32_t Value; 117 uint16_t Type; 118 uint8_t StorageClass; 119 uint16_t SectionNumber; 120 uint8_t NumberOfAuxSymbols; 121 }; 122 123 enum SymbolFlags { 124 SF_TypeMask = 0x0000FFFF, 125 SF_TypeShift = 0, 126 127 SF_ClassMask = 0x00FF0000, 128 SF_ClassShift = 16, 129 130 SF_WeakExternal = 0x01000000 131 }; 132 133 enum SymbolSectionNumber { 134 IMAGE_SYM_DEBUG = -2, 135 IMAGE_SYM_ABSOLUTE = -1, 136 IMAGE_SYM_UNDEFINED = 0 137 }; 138 139 /// Storage class tells where and what the symbol represents 140 enum SymbolStorageClass { 141 IMAGE_SYM_CLASS_END_OF_FUNCTION = -1, ///< Physical end of function 142 IMAGE_SYM_CLASS_NULL = 0, ///< No symbol 143 IMAGE_SYM_CLASS_AUTOMATIC = 1, ///< Stack variable 144 IMAGE_SYM_CLASS_EXTERNAL = 2, ///< External symbol 145 IMAGE_SYM_CLASS_STATIC = 3, ///< Static 146 IMAGE_SYM_CLASS_REGISTER = 4, ///< Register variable 147 IMAGE_SYM_CLASS_EXTERNAL_DEF = 5, ///< External definition 148 IMAGE_SYM_CLASS_LABEL = 6, ///< Label 149 IMAGE_SYM_CLASS_UNDEFINED_LABEL = 7, ///< Undefined label 150 IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = 8, ///< Member of structure 151 IMAGE_SYM_CLASS_ARGUMENT = 9, ///< Function argument 152 IMAGE_SYM_CLASS_STRUCT_TAG = 10, ///< Structure tag 153 IMAGE_SYM_CLASS_MEMBER_OF_UNION = 11, ///< Member of union 154 IMAGE_SYM_CLASS_UNION_TAG = 12, ///< Union tag 155 IMAGE_SYM_CLASS_TYPE_DEFINITION = 13, ///< Type definition 156 IMAGE_SYM_CLASS_UNDEFINED_STATIC = 14, ///< Undefined static 157 IMAGE_SYM_CLASS_ENUM_TAG = 15, ///< Enumeration tag 158 IMAGE_SYM_CLASS_MEMBER_OF_ENUM = 16, ///< Member of enumeration 159 IMAGE_SYM_CLASS_REGISTER_PARAM = 17, ///< Register parameter 160 IMAGE_SYM_CLASS_BIT_FIELD = 18, ///< Bit field 161 /// ".bb" or ".eb" - beginning or end of block 162 IMAGE_SYM_CLASS_BLOCK = 100, 163 /// ".bf" or ".ef" - beginning or end of function 164 IMAGE_SYM_CLASS_FUNCTION = 101, 165 IMAGE_SYM_CLASS_END_OF_STRUCT = 102, ///< End of structure 166 IMAGE_SYM_CLASS_FILE = 103, ///< File name 167 /// Line number, reformatted as symbol 168 IMAGE_SYM_CLASS_SECTION = 104, 169 IMAGE_SYM_CLASS_WEAK_EXTERNAL = 105, ///< Duplicate tag 170 /// External symbol in dmert public lib 171 IMAGE_SYM_CLASS_CLR_TOKEN = 107 172 }; 173 174 enum SymbolBaseType { 175 IMAGE_SYM_TYPE_NULL = 0, ///< No type information or unknown base type. 176 IMAGE_SYM_TYPE_VOID = 1, ///< Used with void pointers and functions. 177 IMAGE_SYM_TYPE_CHAR = 2, ///< A character (signed byte). 178 IMAGE_SYM_TYPE_SHORT = 3, ///< A 2-byte signed integer. 179 IMAGE_SYM_TYPE_INT = 4, ///< A natural integer type on the target. 180 IMAGE_SYM_TYPE_LONG = 5, ///< A 4-byte signed integer. 181 IMAGE_SYM_TYPE_FLOAT = 6, ///< A 4-byte floating-point number. 182 IMAGE_SYM_TYPE_DOUBLE = 7, ///< An 8-byte floating-point number. 183 IMAGE_SYM_TYPE_STRUCT = 8, ///< A structure. 184 IMAGE_SYM_TYPE_UNION = 9, ///< An union. 185 IMAGE_SYM_TYPE_ENUM = 10, ///< An enumerated type. 186 IMAGE_SYM_TYPE_MOE = 11, ///< A member of enumeration (a specific value). 187 IMAGE_SYM_TYPE_BYTE = 12, ///< A byte; unsigned 1-byte integer. 188 IMAGE_SYM_TYPE_WORD = 13, ///< A word; unsigned 2-byte integer. 189 IMAGE_SYM_TYPE_UINT = 14, ///< An unsigned integer of natural size. 190 IMAGE_SYM_TYPE_DWORD = 15 ///< An unsigned 4-byte integer. 191 }; 192 193 enum SymbolComplexType { 194 IMAGE_SYM_DTYPE_NULL = 0, ///< No complex type; simple scalar variable. 195 IMAGE_SYM_DTYPE_POINTER = 1, ///< A pointer to base type. 196 IMAGE_SYM_DTYPE_FUNCTION = 2, ///< A function that returns a base type. 197 IMAGE_SYM_DTYPE_ARRAY = 3, ///< An array of base type. 198 199 /// Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT)) 200 SCT_COMPLEX_TYPE_SHIFT = 4 201 }; 202 203 struct section { 204 char Name[NameSize]; 205 uint32_t VirtualSize; 206 uint32_t VirtualAddress; 207 uint32_t SizeOfRawData; 208 uint32_t PointerToRawData; 209 uint32_t PointerToRelocations; 210 uint32_t PointerToLineNumbers; 211 uint16_t NumberOfRelocations; 212 uint16_t NumberOfLineNumbers; 213 uint32_t Characteristics; 214 }; 215 216 enum SectionCharacteristics { 217 IMAGE_SCN_TYPE_NO_PAD = 0x00000008, 218 IMAGE_SCN_CNT_CODE = 0x00000020, 219 IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040, 220 IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080, 221 IMAGE_SCN_LNK_OTHER = 0x00000100, 222 IMAGE_SCN_LNK_INFO = 0x00000200, 223 IMAGE_SCN_LNK_REMOVE = 0x00000800, 224 IMAGE_SCN_LNK_COMDAT = 0x00001000, 225 IMAGE_SCN_GPREL = 0x00008000, 226 IMAGE_SCN_MEM_PURGEABLE = 0x00020000, 227 IMAGE_SCN_MEM_16BIT = 0x00020000, 228 IMAGE_SCN_MEM_LOCKED = 0x00040000, 229 IMAGE_SCN_MEM_PRELOAD = 0x00080000, 230 IMAGE_SCN_ALIGN_1BYTES = 0x00100000, 231 IMAGE_SCN_ALIGN_2BYTES = 0x00200000, 232 IMAGE_SCN_ALIGN_4BYTES = 0x00300000, 233 IMAGE_SCN_ALIGN_8BYTES = 0x00400000, 234 IMAGE_SCN_ALIGN_16BYTES = 0x00500000, 235 IMAGE_SCN_ALIGN_32BYTES = 0x00600000, 236 IMAGE_SCN_ALIGN_64BYTES = 0x00700000, 237 IMAGE_SCN_ALIGN_128BYTES = 0x00800000, 238 IMAGE_SCN_ALIGN_256BYTES = 0x00900000, 239 IMAGE_SCN_ALIGN_512BYTES = 0x00A00000, 240 IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000, 241 IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000, 242 IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000, 243 IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000, 244 IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000, 245 IMAGE_SCN_MEM_DISCARDABLE = 0x02000000, 246 IMAGE_SCN_MEM_NOT_CACHED = 0x04000000, 247 IMAGE_SCN_MEM_NOT_PAGED = 0x08000000, 248 IMAGE_SCN_MEM_SHARED = 0x10000000, 249 IMAGE_SCN_MEM_EXECUTE = 0x20000000, 250 IMAGE_SCN_MEM_READ = 0x40000000, 251 IMAGE_SCN_MEM_WRITE = 0x80000000 252 }; 253 254 struct relocation { 255 uint32_t VirtualAddress; 256 uint32_t SymbolTableIndex; 257 uint16_t Type; 258 }; 259 260 enum RelocationTypeX86 { 261 IMAGE_REL_I386_ABSOLUTE = 0x0000, 262 IMAGE_REL_I386_DIR16 = 0x0001, 263 IMAGE_REL_I386_REL16 = 0x0002, 264 IMAGE_REL_I386_DIR32 = 0x0006, 265 IMAGE_REL_I386_DIR32NB = 0x0007, 266 IMAGE_REL_I386_SEG12 = 0x0009, 267 IMAGE_REL_I386_SECTION = 0x000A, 268 IMAGE_REL_I386_SECREL = 0x000B, 269 IMAGE_REL_I386_TOKEN = 0x000C, 270 IMAGE_REL_I386_SECREL7 = 0x000D, 271 IMAGE_REL_I386_REL32 = 0x0014, 272 273 IMAGE_REL_AMD64_ABSOLUTE = 0x0000, 274 IMAGE_REL_AMD64_ADDR64 = 0x0001, 275 IMAGE_REL_AMD64_ADDR32 = 0x0002, 276 IMAGE_REL_AMD64_ADDR32NB = 0x0003, 277 IMAGE_REL_AMD64_REL32 = 0x0004, 278 IMAGE_REL_AMD64_REL32_1 = 0x0005, 279 IMAGE_REL_AMD64_REL32_2 = 0x0006, 280 IMAGE_REL_AMD64_REL32_3 = 0x0007, 281 IMAGE_REL_AMD64_REL32_4 = 0x0008, 282 IMAGE_REL_AMD64_REL32_5 = 0x0009, 283 IMAGE_REL_AMD64_SECTION = 0x000A, 284 IMAGE_REL_AMD64_SECREL = 0x000B, 285 IMAGE_REL_AMD64_SECREL7 = 0x000C, 286 IMAGE_REL_AMD64_TOKEN = 0x000D, 287 IMAGE_REL_AMD64_SREL32 = 0x000E, 288 IMAGE_REL_AMD64_PAIR = 0x000F, 289 IMAGE_REL_AMD64_SSPAN32 = 0x0010 290 }; 291 292 enum RelocationTypesARM { 293 IMAGE_REL_ARM_ABSOLUTE = 0x0000, 294 IMAGE_REL_ARM_ADDR32 = 0x0001, 295 IMAGE_REL_ARM_ADDR32NB = 0x0002, 296 IMAGE_REL_ARM_BRANCH24 = 0x0003, 297 IMAGE_REL_ARM_BRANCH11 = 0x0004, 298 IMAGE_REL_ARM_TOKEN = 0x0005, 299 IMAGE_REL_ARM_BLX24 = 0x0008, 300 IMAGE_REL_ARM_BLX11 = 0x0009, 301 IMAGE_REL_ARM_SECTION = 0x000E, 302 IMAGE_REL_ARM_SECREL = 0x000F, 303 IMAGE_REL_ARM_MOV32A = 0x0010, 304 IMAGE_REL_ARM_MOV32T = 0x0011, 305 IMAGE_REL_ARM_BRANCH20T = 0x0012, 306 IMAGE_REL_ARM_BRANCH24T = 0x0014, 307 IMAGE_REL_ARM_BLX23T = 0x0015 308 }; 309 310 enum COMDATType { 311 IMAGE_COMDAT_SELECT_NODUPLICATES = 1, 312 IMAGE_COMDAT_SELECT_ANY, 313 IMAGE_COMDAT_SELECT_SAME_SIZE, 314 IMAGE_COMDAT_SELECT_EXACT_MATCH, 315 IMAGE_COMDAT_SELECT_ASSOCIATIVE, 316 IMAGE_COMDAT_SELECT_LARGEST 317 }; 318 319 // Auxiliary Symbol Formats 320 struct AuxiliaryFunctionDefinition { 321 uint32_t TagIndex; 322 uint32_t TotalSize; 323 uint32_t PointerToLinenumber; 324 uint32_t PointerToNextFunction; 325 uint8_t unused[2]; 326 }; 327 328 struct AuxiliarybfAndefSymbol { 329 uint8_t unused1[4]; 330 uint16_t Linenumber; 331 uint8_t unused2[6]; 332 uint32_t PointerToNextFunction; 333 uint8_t unused3[2]; 334 }; 335 336 struct AuxiliaryWeakExternal { 337 uint32_t TagIndex; 338 uint32_t Characteristics; 339 uint8_t unused[10]; 340 }; 341 342 /// These are not documented in the spec, but are located in WinNT.h. 343 enum WeakExternalCharacteristics { 344 IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1, 345 IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2, 346 IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3 347 }; 348 349 struct AuxiliaryFile { 350 uint8_t FileName[18]; 351 }; 352 353 struct AuxiliarySectionDefinition { 354 uint32_t Length; 355 uint16_t NumberOfRelocations; 356 uint16_t NumberOfLinenumbers; 357 uint32_t CheckSum; 358 uint16_t Number; 359 uint8_t Selection; 360 uint8_t unused[3]; 361 }; 362 363 union Auxiliary { 364 AuxiliaryFunctionDefinition FunctionDefinition; 365 AuxiliarybfAndefSymbol bfAndefSymbol; 366 AuxiliaryWeakExternal WeakExternal; 367 AuxiliaryFile File; 368 AuxiliarySectionDefinition SectionDefinition; 369 }; 370 371 /// @brief The Import Directory Table. 372 /// 373 /// There is a single array of these and one entry per imported DLL. 374 struct ImportDirectoryTableEntry { 375 uint32_t ImportLookupTableRVA; 376 uint32_t TimeDateStamp; 377 uint32_t ForwarderChain; 378 uint32_t NameRVA; 379 uint32_t ImportAddressTableRVA; 380 }; 381 382 /// @brief The PE32 Import Lookup Table. 383 /// 384 /// There is an array of these for each imported DLL. It represents either 385 /// the ordinal to import from the target DLL, or a name to lookup and import 386 /// from the target DLL. 387 /// 388 /// This also happens to be the same format used by the Import Address Table 389 /// when it is initially written out to the image. 390 struct ImportLookupTableEntry32 { 391 uint32_t data; 392 393 /// @brief Is this entry specified by ordinal, or name? 394 bool isOrdinal() const { return data & 0x80000000; } 395 396 /// @brief Get the ordinal value of this entry. isOrdinal must be true. 397 uint16_t getOrdinal() const { 398 assert(isOrdinal() && "ILT entry is not an ordinal!"); 399 return data & 0xFFFF; 400 } 401 402 /// @brief Set the ordinal value and set isOrdinal to true. 403 void setOrdinal(uint16_t o) { 404 data = o; 405 data |= 0x80000000; 406 } 407 408 /// @brief Get the Hint/Name entry RVA. isOrdinal must be false. 409 uint32_t getHintNameRVA() const { 410 assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!"); 411 return data; 412 } 413 414 /// @brief Set the Hint/Name entry RVA and set isOrdinal to false. 415 void setHintNameRVA(uint32_t rva) { data = rva; } 416 }; 417 418 /// @brief The DOS compatible header at the front of all PEs. 419 struct DOSHeader { 420 uint16_t Magic; 421 uint16_t UsedBytesInTheLastPage; 422 uint16_t FileSizeInPages; 423 uint16_t NumberOfRelocationItems; 424 uint16_t HeaderSizeInParagraphs; 425 uint16_t MinimumExtraParagraphs; 426 uint16_t MaximumExtraParagraphs; 427 uint16_t InitialRelativeSS; 428 uint16_t InitialSP; 429 uint16_t Checksum; 430 uint16_t InitialIP; 431 uint16_t InitialRelativeCS; 432 uint16_t AddressOfRelocationTable; 433 uint16_t OverlayNumber; 434 uint16_t Reserved[4]; 435 uint16_t OEMid; 436 uint16_t OEMinfo; 437 uint16_t Reserved2[10]; 438 uint32_t AddressOfNewExeHeader; 439 }; 440 441 struct PEHeader { 442 uint32_t Signature; 443 header COFFHeader; 444 uint16_t Magic; 445 uint8_t MajorLinkerVersion; 446 uint8_t MinorLinkerVersion; 447 uint32_t SizeOfCode; 448 uint32_t SizeOfInitializedData; 449 uint32_t SizeOfUninitializedData; 450 uint32_t AddressOfEntryPoint; // RVA 451 uint32_t BaseOfCode; // RVA 452 uint32_t BaseOfData; // RVA 453 uint64_t ImageBase; 454 uint32_t SectionAlignment; 455 uint32_t FileAlignment; 456 uint16_t MajorOperatingSystemVersion; 457 uint16_t MinorOperatingSystemVersion; 458 uint16_t MajorImageVersion; 459 uint16_t MinorImageVersion; 460 uint16_t MajorSubsystemVersion; 461 uint16_t MinorSubsystemVersion; 462 uint32_t Win32VersionValue; 463 uint32_t SizeOfImage; 464 uint32_t SizeOfHeaders; 465 uint32_t CheckSum; 466 uint16_t Subsystem; 467 uint16_t DLLCharacteristics; 468 uint64_t SizeOfStackReserve; 469 uint64_t SizeOfStackCommit; 470 uint64_t SizeOfHeapReserve; 471 uint64_t SizeOfHeapCommit; 472 uint32_t LoaderFlags; 473 uint32_t NumberOfRvaAndSize; 474 }; 475 476 struct DataDirectory { 477 uint32_t RelativeVirtualAddress; 478 uint32_t Size; 479 }; 480 481 enum WindowsSubsystem { 482 IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem. 483 IMAGE_SUBSYSTEM_NATIVE = 1, ///< Device drivers and native Windows processes 484 IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, ///< The Windows GUI subsystem. 485 IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, ///< The Windows character subsystem. 486 IMAGE_SUBSYSTEM_POSIX_CUI = 7, ///< The POSIX character subsystem. 487 IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9, ///< Windows CE. 488 IMAGE_SUBSYSTEM_EFI_APPLICATION = 10, ///< An EFI application. 489 IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11, ///< An EFI driver with boot 490 /// services. 491 IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12, ///< An EFI driver with run-time 492 /// services. 493 IMAGE_SUBSYSTEM_EFI_ROM = 13, ///< An EFI ROM image. 494 IMAGE_SUBSYSTEM_XBOX = 14 ///< XBOX. 495 }; 496 497 enum DLLCharacteristics { 498 /// DLL can be relocated at load time. 499 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040, 500 /// Code integrity checks are enforced. 501 IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY = 0x0080, 502 IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100, ///< Image is NX compatible. 503 /// Isolation aware, but do not isolate the image. 504 IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION = 0x0200, 505 /// Does not use structured exception handling (SEH). No SEH handler may be 506 /// called in this image. 507 IMAGE_DLL_CHARACTERISTICS_NO_SEH = 0x0400, 508 /// Do not bind the image. 509 IMAGE_DLL_CHARACTERISTICS_NO_BIND = 0x0800, 510 IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER = 0x2000, ///< A WDM driver. 511 /// Terminal Server aware. 512 IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000 513 }; 514 515 enum DebugType { 516 IMAGE_DEBUG_TYPE_UNKNOWN = 0, 517 IMAGE_DEBUG_TYPE_COFF = 1, 518 IMAGE_DEBUG_TYPE_CODEVIEW = 2, 519 IMAGE_DEBUG_TYPE_FPO = 3, 520 IMAGE_DEBUG_TYPE_MISC = 4, 521 IMAGE_DEBUG_TYPE_EXCEPTION = 5, 522 IMAGE_DEBUG_TYPE_FIXUP = 6, 523 IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7, 524 IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8, 525 IMAGE_DEBUG_TYPE_BORLAND = 9, 526 IMAGE_DEBUG_TYPE_CLSID = 11 527 }; 528 529 enum BaseRelocationType { 530 IMAGE_REL_BASED_ABSOLUTE = 0, 531 IMAGE_REL_BASED_HIGH = 1, 532 IMAGE_REL_BASED_LOW = 2, 533 IMAGE_REL_BASED_HIGHLOW = 3, 534 IMAGE_REL_BASED_HIGHADJ = 4, 535 IMAGE_REL_BASED_MIPS_JMPADDR = 5, 536 IMAGE_REL_BASED_ARM_MOV32A = 5, 537 IMAGE_REL_BASED_ARM_MOV32T = 7, 538 IMAGE_REL_BASED_MIPS_JMPADDR16 = 9, 539 IMAGE_REL_BASED_DIR64 = 10 540 }; 541 542 enum ImportType { 543 IMPORT_CODE = 0, 544 IMPORT_DATA = 1, 545 IMPORT_CONST = 2 546 }; 547 548 enum ImportNameType { 549 /// Import is by ordinal. This indicates that the value in the Ordinal/Hint 550 /// field of the import header is the import's ordinal. If this constant is 551 /// not specified, then the Ordinal/Hint field should always be interpreted 552 /// as the import's hint. 553 IMPORT_ORDINAL = 0, 554 /// The import name is identical to the public symbol name 555 IMPORT_NAME = 1, 556 /// The import name is the public symbol name, but skipping the leading ?, 557 /// @, or optionally _. 558 IMPORT_NAME_NOPREFIX = 2, 559 /// The import name is the public symbol name, but skipping the leading ?, 560 /// @, or optionally _, and truncating at the first @. 561 IMPORT_NAME_UNDECORATE = 3 562 }; 563 564 struct ImportHeader { 565 uint16_t Sig1; ///< Must be IMAGE_FILE_MACHINE_UNKNOWN (0). 566 uint16_t Sig2; ///< Must be 0xFFFF. 567 uint16_t Version; 568 uint16_t Machine; 569 uint32_t TimeDateStamp; 570 uint32_t SizeOfData; 571 uint16_t OrdinalHint; 572 uint16_t TypeInfo; 573 574 ImportType getType() const { 575 return static_cast<ImportType>(TypeInfo & 0x3); 576 } 577 578 ImportNameType getNameType() const { 579 return static_cast<ImportNameType>((TypeInfo & 0x1C) >> 3); 580 } 581 }; 582 583 } // End namespace COFF. 584 } // End namespace llvm. 585 586 #endif 587