020b84bfeca7f6125d6e7b50c72655e85fe9a36e
[ghc.git] / rts / linker / PEi386.h
1 #ifndef LINKER_PE_I386_H
2 #define LINKER_PE_I386_H
3
4 #include "Rts.h"
5 #include "LinkerInternals.h"
6 #include "PathUtils.h"
7
8 #include "BeginPrivate.h"
9
10 #if defined(x86_64_HOST_ARCH)
11 #define PEi386_IMAGE_OFFSET 4
12 #else
13 #define PEi386_IMAGE_OFFSET 0
14 #endif
15
16 void initLinker_PEi386(void);
17 const char * addDLL_PEi386(pathchar *dll_name);
18 void freePreloadObjectFile_PEi386(ObjectCode *oc);
19
20 int findAndLoadImportLibrary(ObjectCode* oc);
21 int checkAndLoadImportLibrary( pathchar* arch_name, char* member_name, FILE* f);
22
23 pathchar* findSystemLibrary_PEi386(pathchar* dll_name);
24 HsPtr addLibrarySearchPath_PEi386(pathchar* dll_path);
25 HsBool removeLibrarySearchPath_PEi386(HsPtr dll_path_index);
26
27 int ocResolve_PEi386 ( ObjectCode* oc );
28 int ocRunInit_PEi386 ( ObjectCode *oc );
29 int ocGetNames_PEi386 ( ObjectCode* oc );
30 int ocVerifyImage_PEi386 ( ObjectCode* oc );
31 SymbolAddr *lookupSymbol_PEi386(SymbolName *lbl);
32 int ocAllocateSymbolExtras_PEi386 ( ObjectCode* oc );
33 void *lookupSymbolInDLLs ( unsigned char *lbl );
34 /* See Note [mingw-w64 name decoration scheme] */
35
36 char *
37 allocateImageAndTrampolines (
38 pathchar* arch_name, char* member_name,
39 FILE* f,
40 int size,
41 int isThin);
42
43 /********************************************
44 * COFF/PE headers
45 ********************************************/
46 typedef unsigned char UChar;
47 typedef unsigned short UInt16;
48 typedef short Int16;
49 typedef unsigned int UInt32;
50 typedef int Int32;
51 typedef unsigned long long int UInt64;
52
53
54 typedef
55 struct {
56 UInt16 Machine;
57 UInt16 NumberOfSections;
58 UInt32 TimeDateStamp;
59 UInt32 PointerToSymbolTable;
60 UInt32 NumberOfSymbols;
61 UInt16 SizeOfOptionalHeader;
62 UInt16 Characteristics;
63 }
64 COFF_header;
65
66 #define sizeof_COFF_header 20
67
68 /* Section 7.1 PE Specification */
69 typedef
70 struct {
71 UInt16 Sig1;
72 UInt16 Sig2;
73 UInt16 Version;
74 UInt16 Machine;
75 UInt32 TimeDateStamp;
76 UInt32 SizeOfData;
77 UInt16 Ordinal;
78 UInt16 Type_NameType_Reserved;
79 }
80 COFF_import_header;
81
82 #define sizeof_COFF_import_Header 20
83
84 typedef
85 struct {
86 UChar Name[8];
87 UInt32 VirtualSize;
88 UInt32 VirtualAddress;
89 UInt32 SizeOfRawData;
90 UInt32 PointerToRawData;
91 UInt32 PointerToRelocations;
92 UInt32 PointerToLinenumbers;
93 UInt16 NumberOfRelocations;
94 UInt16 NumberOfLineNumbers;
95 UInt32 Characteristics;
96 }
97 COFF_section;
98
99 #define sizeof_COFF_section 40
100
101
102 typedef
103 struct {
104 UChar Name[8];
105 UInt32 Value;
106 Int16 SectionNumber;
107 UInt16 Type;
108 UChar StorageClass;
109 UChar NumberOfAuxSymbols;
110 }
111 COFF_symbol;
112
113 #define sizeof_COFF_symbol 18
114
115
116 typedef
117 struct {
118 UInt32 VirtualAddress;
119 UInt32 SymbolTableIndex;
120 UInt16 Type;
121 }
122 COFF_reloc;
123
124 #define sizeof_COFF_reloc 10
125
126 /* From PE spec doc, section 3.3.2 */
127 /* Note use of MYIMAGE_* since IMAGE_* are already defined in
128 windows.h -- for the same purpose, but I want to know what I'm
129 getting, here. */
130 #define MYIMAGE_FILE_RELOCS_STRIPPED 0x0001
131 #define MYIMAGE_FILE_EXECUTABLE_IMAGE 0x0002
132 #define MYIMAGE_FILE_DLL 0x2000
133 #define MYIMAGE_FILE_SYSTEM 0x1000
134 #define MYIMAGE_FILE_BYTES_REVERSED_HI 0x8000
135 #define MYIMAGE_FILE_BYTES_REVERSED_LO 0x0080
136 #define MYIMAGE_FILE_32BIT_MACHINE 0x0100
137
138 /* From PE spec doc, section 5.4.2 and 5.4.4 */
139 #define MYIMAGE_SYM_CLASS_EXTERNAL 2
140 #define MYIMAGE_SYM_CLASS_STATIC 3
141 #define MYIMAGE_SYM_UNDEFINED 0
142 #define MYIMAGE_SYM_CLASS_SECTION 104
143 #define MYIMAGE_SYM_CLASS_WEAK_EXTERNAL 105
144
145 /* From PE spec doc, section 3.1 */
146 #define MYIMAGE_SCN_CNT_CODE 0x00000020
147 #define MYIMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
148 #define MYIMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
149 #define MYIMAGE_SCN_LNK_COMDAT 0x00001000
150 #define MYIMAGE_SCN_LNK_NRELOC_OVFL 0x01000000
151 #define MYIMAGE_SCN_LNK_REMOVE 0x00000800
152 #define MYIMAGE_SCN_MEM_DISCARDABLE 0x02000000
153
154 /* From PE spec doc, section 5.2.1 */
155 #define MYIMAGE_REL_I386_DIR32 0x0006
156 #define MYIMAGE_REL_I386_DIR32NB 0x0007
157 #define MYIMAGE_REL_I386_REL32 0x0014
158
159 #include "EndPrivate.h"
160
161 #endif /* LINKER_PE_I386_H */