github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/cmd/ld/pe.h (about)

     1  // Copyright 2009 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  typedef struct {
     6  	uint16 Machine;
     7  	uint16 NumberOfSections;
     8  	uint32 TimeDateStamp;
     9  	uint32 PointerToSymbolTable;
    10  	uint32 NumberOfSymbols;
    11  	uint16 SizeOfOptionalHeader;
    12  	uint16 Characteristics;
    13  } IMAGE_FILE_HEADER;
    14  
    15  typedef struct {
    16  	uint32 VirtualAddress;
    17  	uint32 Size;
    18  } IMAGE_DATA_DIRECTORY;
    19  
    20  typedef struct {
    21  	uint16 Magic;
    22  	uint8  MajorLinkerVersion;
    23  	uint8  MinorLinkerVersion;
    24  	uint32 SizeOfCode;
    25  	uint32 SizeOfInitializedData;
    26  	uint32 SizeOfUninitializedData;
    27  	uint32 AddressOfEntryPoint;
    28  	uint32 BaseOfCode;
    29  	uint32 BaseOfData;
    30  	uint32 ImageBase;
    31  	uint32 SectionAlignment;
    32  	uint32 FileAlignment;
    33  	uint16 MajorOperatingSystemVersion;
    34  	uint16 MinorOperatingSystemVersion;
    35  	uint16 MajorImageVersion;
    36  	uint16 MinorImageVersion;
    37  	uint16 MajorSubsystemVersion;
    38  	uint16 MinorSubsystemVersion;
    39  	uint32 Win32VersionValue;
    40  	uint32 SizeOfImage;
    41  	uint32 SizeOfHeaders;
    42  	uint32 CheckSum;
    43  	uint16 Subsystem;
    44  	uint16 DllCharacteristics;
    45  	uint32 SizeOfStackReserve;
    46  	uint32 SizeOfStackCommit;
    47  	uint32 SizeOfHeapReserve;
    48  	uint32 SizeOfHeapCommit;
    49  	uint32 LoaderFlags;
    50  	uint32 NumberOfRvaAndSizes;
    51  	IMAGE_DATA_DIRECTORY DataDirectory[16];
    52  } IMAGE_OPTIONAL_HEADER;
    53  
    54  typedef struct {
    55  	uint8  Name[8];
    56  	uint32 VirtualSize;
    57  	uint32 VirtualAddress;
    58  	uint32 SizeOfRawData;
    59  	uint32 PointerToRawData;
    60  	uint32 PointerToRelocations;
    61  	uint32 PointerToLineNumbers;
    62  	uint16 NumberOfRelocations;
    63  	uint16 NumberOfLineNumbers;
    64  	uint32 Characteristics;
    65  } IMAGE_SECTION_HEADER;
    66  
    67  typedef struct {
    68  	uint32 OriginalFirstThunk;
    69  	uint32 TimeDateStamp;
    70  	uint32 ForwarderChain;
    71  	uint32 Name;
    72  	uint32 FirstThunk;
    73  } IMAGE_IMPORT_DESCRIPTOR;
    74  
    75  typedef struct _IMAGE_EXPORT_DIRECTORY {
    76  	uint32 Characteristics;
    77  	uint32 TimeDateStamp;
    78  	uint16 MajorVersion;
    79  	uint16 MinorVersion;
    80  	uint32 Name;
    81  	uint32 Base;
    82  	uint32 NumberOfFunctions;
    83  	uint32 NumberOfNames;
    84  	uint32 AddressOfFunctions;
    85  	uint32 AddressOfNames;
    86  	uint32 AddressOfNameOrdinals;
    87  } IMAGE_EXPORT_DIRECTORY;
    88  
    89  #define PEBASE		0x00400000
    90  // SectionAlignment must be greater than or equal to FileAlignment.
    91  // The default is the page size for the architecture.
    92  #define PESECTALIGN	0x1000
    93  // FileAlignment should be a power of 2 between 512 and 64 K, inclusive.
    94  // The default is 512. If the SectionAlignment is less than
    95  // the architecture's page size, then FileAlignment must match SectionAlignment.
    96  #define PEFILEALIGN	(2<<8)
    97  extern	int32	PESECTHEADR;
    98  extern	int32	PEFILEHEADR;
    99  
   100  enum {
   101  	IMAGE_FILE_MACHINE_I386 = 0x14c,
   102  	IMAGE_FILE_MACHINE_AMD64 = 0x8664,
   103  
   104  	IMAGE_FILE_RELOCS_STRIPPED = 0x0001,
   105  	IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002,
   106  	IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020,
   107  	IMAGE_FILE_32BIT_MACHINE = 0x0100,
   108  	IMAGE_FILE_DEBUG_STRIPPED = 0x0200,
   109  
   110  	IMAGE_SCN_CNT_CODE = 0x00000020,
   111  	IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040,
   112  	IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080,
   113  	IMAGE_SCN_MEM_EXECUTE = 0x20000000,
   114  	IMAGE_SCN_MEM_READ = 0x40000000,
   115  	IMAGE_SCN_MEM_WRITE = 0x80000000,
   116  	IMAGE_SCN_MEM_DISCARDABLE = 0x2000000,
   117  
   118  	IMAGE_DIRECTORY_ENTRY_EXPORT = 0,
   119  	IMAGE_DIRECTORY_ENTRY_IMPORT = 1,
   120  	IMAGE_DIRECTORY_ENTRY_RESOURCE = 2,
   121  	IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3,
   122  	IMAGE_DIRECTORY_ENTRY_SECURITY = 4,
   123  	IMAGE_DIRECTORY_ENTRY_BASERELOC = 5,
   124  	IMAGE_DIRECTORY_ENTRY_DEBUG = 6,
   125  	IMAGE_DIRECTORY_ENTRY_COPYRIGHT = 7,
   126  	IMAGE_DIRECTORY_ENTRY_ARCHITECTURE = 7,
   127  	IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8,
   128  	IMAGE_DIRECTORY_ENTRY_TLS = 9,
   129  	IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10,
   130  	IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11,
   131  	IMAGE_DIRECTORY_ENTRY_IAT = 12,
   132  	IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13,
   133  	IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14,
   134  
   135  	IMAGE_SUBSYSTEM_WINDOWS_GUI = 2,
   136  	IMAGE_SUBSYSTEM_WINDOWS_CUI = 3,
   137  };
   138  
   139  void peinit(void);
   140  void asmbpe(void);
   141  void dope(void);
   142  
   143  IMAGE_SECTION_HEADER* newPEDWARFSection(char *name, vlong size);
   144  
   145  // X64
   146  typedef struct {
   147  	uint16 Magic;
   148  	uint8  MajorLinkerVersion;
   149  	uint8  MinorLinkerVersion;
   150  	uint32 SizeOfCode;
   151  	uint32 SizeOfInitializedData;
   152  	uint32 SizeOfUninitializedData;
   153  	uint32 AddressOfEntryPoint;
   154  	uint32 BaseOfCode;
   155  	uint64 ImageBase;
   156  	uint32 SectionAlignment;
   157  	uint32 FileAlignment;
   158  	uint16 MajorOperatingSystemVersion;
   159  	uint16 MinorOperatingSystemVersion;
   160  	uint16 MajorImageVersion;
   161  	uint16 MinorImageVersion;
   162  	uint16 MajorSubsystemVersion;
   163  	uint16 MinorSubsystemVersion;
   164  	uint32 Win32VersionValue;
   165  	uint32 SizeOfImage;
   166  	uint32 SizeOfHeaders;
   167  	uint32 CheckSum;
   168  	uint16 Subsystem;
   169  	uint16 DllCharacteristics;
   170  	uint64 SizeOfStackReserve;
   171  	uint64 SizeOfStackCommit;
   172  	uint64 SizeOfHeapReserve;
   173  	uint64 SizeOfHeapCommit;
   174  	uint32 LoaderFlags;
   175  	uint32 NumberOfRvaAndSizes;
   176  	IMAGE_DATA_DIRECTORY DataDirectory[16];
   177  } PE64_IMAGE_OPTIONAL_HEADER;
   178  
   179  void setpersrc(LSym *sym);