09b8c91c942547a850d68ea4e31eba16d234c0e3
[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 #include <windows.h>
8 #include <stdbool.h>
9
10 #include "BeginPrivate.h"
11
12 #if defined(x86_64_HOST_ARCH)
13 #define PEi386_IMAGE_OFFSET 4
14 #else
15 #define PEi386_IMAGE_OFFSET 0
16 #endif
17
18 void initLinker_PEi386( void );
19 const char * addDLL_PEi386( pathchar *dll_name );
20 void freePreloadObjectFile_PEi386( ObjectCode *oc );
21
22 bool findAndLoadImportLibrary( ObjectCode* oc );
23 bool checkAndLoadImportLibrary( pathchar* arch_name, char* member_name, FILE* f);
24
25 pathchar* findSystemLibrary_PEi386( pathchar* dll_name );
26 HsPtr addLibrarySearchPath_PEi386( pathchar* dll_path );
27 bool removeLibrarySearchPath_PEi386( HsPtr dll_path_index );
28
29 bool ocResolve_PEi386 ( ObjectCode* oc );
30 bool ocRunInit_PEi386 ( ObjectCode *oc );
31 bool ocGetNames_PEi386 ( ObjectCode* oc );
32 bool ocVerifyImage_PEi386 ( ObjectCode* oc );
33 SymbolAddr *lookupSymbol_PEi386(SymbolName *lbl);
34 bool ocAllocateSymbolExtras_PEi386 ( ObjectCode* oc );
35 void *lookupSymbolInDLLs ( unsigned char *lbl );
36 /* See Note [mingw-w64 name decoration scheme] */
37
38 char *
39 allocateImageAndTrampolines (
40 pathchar* arch_name, char* member_name,
41 FILE* f,
42 int size,
43 int isThin);
44
45 /********************************************
46 * COFF/PE headers
47 ********************************************/
48 typedef IMAGE_FILE_HEADER COFF_header;
49 #define sizeof_COFF_header sizeof(COFF_header)
50
51 /* Section 7.1 PE Specification */
52 typedef IMPORT_OBJECT_HEADER COFF_import_header;
53 #define sizeof_COFF_import_Header sizeof(COFF_import_header)
54
55 typedef IMAGE_SECTION_HEADER COFF_section;
56 #define sizeof_COFF_section sizeof(COFF_section)
57
58
59 typedef IMAGE_SYMBOL COFF_symbol;
60 #define sizeof_COFF_symbol sizeof(COFF_symbol)
61
62
63 typedef IMAGE_RELOCATION COFF_reloc;
64 #define sizeof_COFF_reloc sizeof(COFF_reloc)
65
66 // MingW-w64 is missing these from the implementation. So we have to look them up
67 typedef DLL_DIRECTORY_COOKIE(WINAPI *LPAddDLLDirectory)(PCWSTR NewDirectory);
68 typedef WINBOOL(WINAPI *LPRemoveDLLDirectory)(DLL_DIRECTORY_COOKIE Cookie);
69
70 /* A record for storing handles into DLLs. */
71 typedef
72 struct _OpenedDLL {
73 pathchar* name;
74 struct _OpenedDLL* next;
75 HINSTANCE instance;
76 } OpenedDLL;
77
78 /* A record for storing indirectly linked functions from DLLs. */
79 typedef
80 struct _IndirectAddr {
81 SymbolAddr* addr;
82 struct _IndirectAddr* next;
83 } IndirectAddr;
84
85 /* See Note [mingw-w64 name decoration scheme] */
86 #ifndef x86_64_HOST_ARCH
87 #define STRIP_LEADING_UNDERSCORE 1
88 #else
89 #define STRIP_LEADING_UNDERSCORE 0
90 #endif
91
92 /*
93 Note [mingw-w64 name decoration scheme]
94
95 What's going on with name decoration? Well, original code
96 have some crufty and ad-hocish paths related mostly to very old
97 mingw gcc/binutils/runtime combinations. Now mingw-w64 offers pretty
98 uniform and MS-compatible decoration scheme across its tools and runtime.
99
100 The scheme is pretty straightforward: on 32 bit objects symbols are exported
101 with underscore prepended (and @ + stack size suffix appended for stdcall
102 functions), on 64 bits no underscore is prepended and no suffix is appended
103 because we have no stdcall convention on 64 bits.
104
105 See #9218
106 */
107
108
109 #include "EndPrivate.h"
110
111 #endif /* LINKER_PE_I386_H */