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