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