-/* pe.h - PE COFF header information
+/* pe.h - PE COFF header information
- Copyright 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1999-2018 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
/* DllCharacteristics flag bits. The inconsistent naming may seem
odd, but that is how they are defined in the PE specification. */
+#define IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA 0x0020
#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
/* Section characteristics added for ppc-nt. */
-#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
+#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
-#define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
-#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
-#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
+#define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
+#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
+#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
-#define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
-#define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
-#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
-#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
+#define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
+#define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
+#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
+#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
#define IMAGE_SCN_MEM_FARDATA 0x00008000
#define IMAGE_SCN_MEM_LOCKED 0x00040000
#define IMAGE_SCN_MEM_PRELOAD 0x00080000
-/* Bit position in the s_flags field where the alignment values start. */
+/* Bit position in the s_flags field where the alignment values start. */
#define IMAGE_SCN_ALIGN_POWER_BIT_POS 20
#define IMAGE_SCN_ALIGN_POWER_BIT_MASK 0x00f00000
#define IMAGE_SCN_ALIGN_POWER_NUM(val) \
#define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_POWER_CONST (1)
#define IMAGE_SCN_ALIGN_4BYTES IMAGE_SCN_ALIGN_POWER_CONST (2)
#define IMAGE_SCN_ALIGN_8BYTES IMAGE_SCN_ALIGN_POWER_CONST (3)
-/* Default alignment if no others are specified. */
+/* Default alignment if no others are specified. */
#define IMAGE_SCN_ALIGN_16BYTES IMAGE_SCN_ALIGN_POWER_CONST (4)
#define IMAGE_SCN_ALIGN_32BYTES IMAGE_SCN_ALIGN_POWER_CONST (5)
#define IMAGE_SCN_ALIGN_64BYTES IMAGE_SCN_ALIGN_POWER_CONST (6)
#define IMAGE_SCN_ALIGN_4096BYTES IMAGE_SCN_ALIGN_POWER_CONST (12)
#define IMAGE_SCN_ALIGN_8192BYTES IMAGE_SCN_ALIGN_POWER_CONST (13)
-/* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags */
+/* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags. */
#define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \
- ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER)))
+ ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER) <= 13 \
+ ? (ALIGNMENT_POWER) : 13))
+#define COFF_DECODE_ALIGNMENT(X) \
+ IMAGE_SCN_ALIGN_POWER_NUM ((X) & IMAGE_SCN_ALIGN_POWER_BIT_MASK)
#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
-#define IMAGE_SUBSYSTEM_EFI_ROM 13
+#define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
#define IMAGE_SUBSYSTEM_XBOX 14
-
+
/* Magic values that are true for all dos/nt implementations. */
-#define DOSMAGIC 0x5a4d
+#define DOSMAGIC 0x5a4d
#define NT_SIGNATURE 0x00004550
/* NT allows long filenames, we want to accommodate this.
struct external_PEI_IMAGE_hdr
{
- char nt_signature[4]; /* required NT signature, 0x4550. */
+ char nt_signature[4]; /* Required NT signature, 0x4550. */
/* From standard header. */
char f_magic[2]; /* Magic number. */
/* Note: additional bytes may be inserted before the signature. Use
the e_lfanew field to find the actual location of the NT signature. */
- char nt_signature[4]; /* required NT signature, 0x4550. */
+ char nt_signature[4]; /* Required NT signature, 0x4550. */
/* From standard header. */
char f_magic[2]; /* Magic number. */
#endif /* COFF_IMAGE_WITH_PE */
-/* 32-bit PE a.out header: */
+/* 32-bit PE a.out header: */
-typedef struct
+typedef struct
{
AOUTHDR standard;
/* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
(aka data_start) member and that some of the members are 8 instead
of just 4 bytes long. */
-typedef struct
+typedef struct
{
#ifdef AOUTHDRSZ64
AOUTHDR64 standard;
#else
#define PEPAOUTSZ 240
#endif
-
+
#undef E_FILNMLEN
#define E_FILNMLEN 18 /* # characters in a file name. */
#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
+/* Bigobj header. */
+struct external_ANON_OBJECT_HEADER_BIGOBJ
+{
+ /* ANON_OBJECT_HEADER_V2 header. */
+ char Sig1[2];
+ char Sig2[2];
+ char Version[2];
+ char Machine[2];
+ char TimeDateStamp[4];
+ char ClassID[16];
+ char SizeOfData[4];
+ char Flags[4];
+ char MetaDataSize[4];
+ char MetaDataOffset[4];
+
+ /* BIGOBJ specific. */
+ char NumberOfSections[4];
+ char PointerToSymbolTable[4];
+ char NumberOfSymbols[4];
+};
+
+#define FILHSZ_BIGOBJ (14 * 4)
+
+struct external_SYMBOL_EX
+{
+ union
+ {
+ char e_name[E_SYMNMLEN];
+
+ struct
+ {
+ char e_zeroes[4];
+ char e_offset[4];
+ } e;
+ } e;
+
+ char e_value[4];
+ char e_scnum[4];
+ char e_type[2];
+ char e_sclass[1];
+ char e_numaux[1];
+} ATTRIBUTE_PACKED ;
+
+#define SYMENT_BIGOBJ struct external_SYMBOL_EX
+#define SYMESZ_BIGOBJ 20
+
+#define FILNMLEN_BIGOBJ 20
+
+union external_AUX_SYMBOL_EX
+{
+ struct
+ {
+ char WeakDefaultSymIndex[4];
+ char WeakSearchType[4];
+ char rgbReserved[12];
+ } Sym;
+
+ struct
+ {
+ char Name[FILNMLEN_BIGOBJ];
+ } File;
+
+ struct
+ {
+ char Length[4]; /* Section length. */
+ char NumberOfRelocations[2];/* # relocation entries. */
+ char NumberOfLinenumbers[2];/* # line numbers. */
+ char Checksum[4]; /* Section COMDAT checksum. */
+ char Number[2]; /* COMDAT associated section index. */
+ char Selection[1]; /* COMDAT selection number. */
+ char bReserved[1];
+ char HighNumber[2]; /* High bits of COMDAT associated sec. */
+ char rgbReserved[2];
+ } Section;
+} ATTRIBUTE_PACKED;
+
+#define AUXENT_BIGOBJ union external_AUX_SYMBOL_EX
+#define AUXESZ_BIGOBJ 20
+
+/* .pdata/.xdata defines and structures for x64 PE+ for exception handling. */
+
+/* .pdata in exception directory. */
+
+struct pex64_runtime_function
+{
+ bfd_vma rva_BeginAddress;
+ bfd_vma rva_EndAddress;
+ bfd_vma rva_UnwindData;
+};
+
+struct external_pex64_runtime_function
+{
+ bfd_byte rva_BeginAddress[4];
+ bfd_byte rva_EndAddress[4];
+ bfd_byte rva_UnwindData[4];
+};
+
+/* If the lowest significant bit is set for rva_UnwindData RVA, it
+ means that the unified RVA points to another pex64_runtime_function
+ that this entry shares the unwind_info block with. */
+#define PEX64_IS_RUNTIME_FUNCTION_CHAINED(PTR_RTF) \
+ (((PTR_RTF)->rva_UnwindData & 1) != 0)
+#define PEX64_GET_UNWINDDATA_UNIFIED_RVA(PTR_RTF) \
+ ((PTR_RTF)->rva_UnwindData & ~1)
+
+/* The unwind codes. */
+#define UWOP_PUSH_NONVOL 0
+#define UWOP_ALLOC_LARGE 1
+#define UWOP_ALLOC_SMALL 2
+#define UWOP_SET_FPREG 3
+#define UWOP_SAVE_NONVOL 4
+#define UWOP_SAVE_NONVOL_FAR 5
+#define UWOP_SAVE_XMM 6 /* For version 1. */
+#define UWOP_EPILOG 6 /* For version 2. */
+#define UWOP_SAVE_XMM_FAR 7 /* For version 1 (deprecated). */
+#define UWOP_SPARE 7 /* For version 2. */
+#define UWOP_SAVE_XMM128 8
+#define UWOP_SAVE_XMM128_FAR 9
+#define UWOP_PUSH_MACHFRAME 10
+
+struct pex64_unwind_code
+{
+ bfd_vma prologue_offset;
+ /* Contains Frame offset, or frame allocation size. */
+ bfd_vma frame_addr;
+ unsigned int uwop_code : 4;
+ /* xmm, mm, or standard register from 0 - 15. */
+ unsigned int reg : 4;
+ /* Used for UWOP_PUSH_MACHFRAME to indicate optional errorcode stack
+ argument. */
+ unsigned int has_errorcode : 1;
+};
+
+struct external_pex64_unwind_code
+{
+ bfd_byte dta[2];
+};
+
+#define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
+#define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
+
+/* The unwind info. */
+#define UNW_FLAG_NHANDLER 0
+#define UNW_FLAG_EHANDLER 1
+#define UNW_FLAG_UHANDLER 2
+#define UNW_FLAG_FHANDLER 3
+#define UNW_FLAG_CHAININFO 4
+
+#define UNW_FLAG_MASK 0x1f
+
+struct pex64_unwind_info
+{
+ bfd_vma SizeOfBlock;
+ bfd_byte Version; /* Values from 0 up to 7 are possible. */
+ bfd_byte Flags; /* Values from 0 up to 31 are possible. */
+ bfd_vma SizeOfPrologue;
+ bfd_vma CountOfCodes; /* Amount of pex64_unwind_code elements. */
+ /* 0 = CFA, 1..15 are index of integer registers. */
+ unsigned int FrameRegister : 4;
+ bfd_vma FrameOffset;
+ bfd_vma sizeofUnwindCodes;
+ bfd_byte *rawUnwindCodes;
+ bfd_vma rva_ExceptionHandler; /* UNW_EHANDLER or UNW_FLAG_UHANDLER. */
+ bfd_vma rva_BeginAddress; /* UNW_FLAG_CHAININFO. */
+ bfd_vma rva_EndAddress; /* UNW_FLAG_CHAININFO. */
+ bfd_vma rva_UnwindData; /* UNW_FLAG_CHAININFO. */
+};
+
+struct external_pex64_unwind_info
+{
+ bfd_byte Version_Flags;
+ bfd_byte SizeOfPrologue;
+ bfd_byte CountOfCodes;
+ bfd_byte FrameRegisterOffset;
+ /* external_pex64_unwind_code array. */
+ /* bfd_byte handler[4]; */
+ /* Optional language specific data. */
+};
+
+struct external_pex64_scope
+{
+ bfd_vma Count;
+};
+
+struct pex64_scope
+{
+ bfd_byte Count[4];
+};
+
+struct pex64_scope_entry
+{
+ bfd_vma rva_BeginAddress;
+ bfd_vma rva_EndAddress;
+ bfd_vma rva_HandlerAddress;
+ bfd_vma rva_JumpAddress;
+};
+#define PEX64_SCOPE_ENTRY_SIZE 16
+
+struct external_pex64_scope_entry
+{
+ bfd_byte rva_BeginAddress[4];
+ bfd_byte rva_EndAddress[4];
+ bfd_byte rva_HandlerAddress[4];
+ bfd_byte rva_JumpAddress[4];
+};
+
+#define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
+#define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
+#define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
+#define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
+#define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
+ ((((VAL) + 1) & ~1) * 2)
+
+#define PEX64_OFFSET_TO_UNWIND_CODE 0x4
+
+#define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
+ (PEX64_OFFSET_TO_UNWIND_CODE + \
+ PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
+
+#define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
+ (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
+
+#define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
+ (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
+ PEX64_SCOPE_ENTRY_SIZE * (IDX))
+
+/* Extra structure used in debug directory. */
+struct external_IMAGE_DEBUG_DIRECTORY
+{
+ char Characteristics[4];
+ char TimeDateStamp[4];
+ char MajorVersion[2];
+ char MinorVersion[2];
+ char Type[4];
+ char SizeOfData[4];
+ char AddressOfRawData[4];
+ char PointerToRawData[4];
+};
+
+/* Extra structures used in codeview debug record. */
+/* This is not part of the PE specification. */
+
+#define CVINFO_PDB70_CVSIGNATURE 0x53445352 // "RSDS"
+#define CVINFO_PDB20_CVSIGNATURE 0x3031424e // "NB10"
+#define CVINFO_CV50_CVSIGNATURE 0x3131424e // "NB11"
+#define CVINFO_CV41_CVSIGNATURE 0x3930424e // "NB09"
+
+typedef struct _CV_INFO_PDB70
+{
+ char CvSignature[4];
+ char Signature[16];
+ char Age[4];
+ char PdbFileName[];
+} CV_INFO_PDB70;
+
+typedef struct _CV_INFO_PDB20
+{
+ char CvHeader[4];
+ char Offset[4];
+ char Signature[4];
+ char Age[4];
+ char PdbFileName[];
+} CV_INFO_PDB20;
+
#endif /* _PE_H */