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