Support more sphinx-build versions in configure script
[ghc.git] / rts / LinkerInternals.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 2000
4 *
5 * RTS Object Linker
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #ifndef LINKERINTERNALS_H
10 #define LINKERINTERNALS_H
11
12 typedef enum {
13 OBJECT_LOADED,
14 OBJECT_RESOLVED,
15 OBJECT_UNLOADED
16 } OStatus;
17
18 /* Indication of section kinds for loaded objects. Needed by
19 the GC for deciding whether or not a pointer on the stack
20 is a code pointer.
21 */
22 typedef
23 enum { SECTIONKIND_CODE_OR_RODATA,
24 SECTIONKIND_RWDATA,
25 SECTIONKIND_INIT_ARRAY,
26 SECTIONKIND_OTHER,
27 SECTIONKIND_NOINFOAVAIL }
28 SectionKind;
29
30 typedef
31 enum { SECTION_NOMEM,
32 SECTION_M32,
33 SECTION_MMAP,
34 SECTION_MALLOC,
35 }
36 SectionAlloc;
37
38 typedef
39 struct _Section {
40 void* start; /* actual start of section in memory */
41 StgWord size; /* actual size of section in memory */
42 SectionKind kind;
43 SectionAlloc alloc;
44
45 /*
46 * The following fields are relevant for SECTION_MMAP sections only
47 */
48 StgWord mapped_offset; /* offset from the image of mapped_start */
49 void* mapped_start; /* start of mmap() block */
50 StgWord mapped_size; /* size of mmap() block */
51 }
52 Section;
53
54 typedef
55 struct _ProddableBlock {
56 void* start;
57 int size;
58 struct _ProddableBlock* next;
59 }
60 ProddableBlock;
61
62 /*
63 * We must keep track of the StablePtrs that are created for foreign
64 * exports by constructor functions when the module is loaded, so that
65 * we can free them again when the module is unloaded. If we don't do
66 * this, then the StablePtr will keep the module alive indefinitely.
67 */
68 typedef struct ForeignExportStablePtr_ {
69 StgStablePtr stable_ptr;
70 struct ForeignExportStablePtr_ *next;
71 } ForeignExportStablePtr;
72
73 #if powerpc_HOST_ARCH || x86_64_HOST_ARCH || arm_HOST_ARCH
74 #define NEED_SYMBOL_EXTRAS 1
75 #endif
76
77 /* Jump Islands are sniplets of machine code required for relative
78 * address relocations on the PowerPC, x86_64 and ARM.
79 */
80 typedef struct {
81 #ifdef powerpc_HOST_ARCH
82 struct {
83 short lis_r12, hi_addr;
84 short ori_r12_r12, lo_addr;
85 long mtctr_r12;
86 long bctr;
87 } jumpIsland;
88 #elif x86_64_HOST_ARCH
89 uint64_t addr;
90 uint8_t jumpIsland[6];
91 #elif arm_HOST_ARCH
92 uint8_t jumpIsland[16];
93 #endif
94 } SymbolExtra;
95
96 /* Top-level structure for an object module. One of these is allocated
97 * for each object file in use.
98 */
99 typedef struct _ObjectCode {
100 OStatus status;
101 pathchar *fileName;
102 int fileSize; /* also mapped image size when using mmap() */
103 char* formatName; /* eg "ELF32", "DLL", "COFF", etc. */
104
105 /* If this object is a member of an archive, archiveMemberName is
106 * like "libarchive.a(object.o)". Otherwise it's NULL.
107 */
108 char* archiveMemberName;
109
110 /* An array containing ptrs to all the symbol names copied from
111 this object into the global symbol hash table. This is so that
112 we know which parts of the latter mapping to nuke when this
113 object is removed from the system. */
114 char** symbols;
115 int n_symbols;
116
117 /* ptr to mem containing the object file image */
118 char* image;
119 /* non-zero if the object file was mmap'd, otherwise malloc'd */
120 int imageMapped;
121
122 /* flag used when deciding whether to unload an object file */
123 int referenced;
124
125 #ifdef darwin_HOST_OS
126 /* record by how much image has been deliberately misaligned
127 after allocation, so that we can use realloc */
128 int misalignment;
129 #endif
130
131 /* The section-kind entries for this object module. Linked
132 list. */
133 int n_sections;
134 Section* sections;
135
136 /* Allow a chain of these things */
137 struct _ObjectCode * next;
138
139 /* SANITY CHECK ONLY: a list of the only memory regions which may
140 safely be prodded during relocation. Any attempt to prod
141 outside one of these is an error in the linker. */
142 ProddableBlock* proddables;
143
144 #ifdef ia64_HOST_ARCH
145 /* Procedure Linkage Table for this object */
146 void *plt;
147 unsigned int pltIndex;
148 #endif
149
150 #if NEED_SYMBOL_EXTRAS
151 SymbolExtra *symbol_extras;
152 unsigned long first_symbol_extra;
153 unsigned long n_symbol_extras;
154 #endif
155
156 ForeignExportStablePtr *stable_ptrs;
157
158 } ObjectCode;
159
160 #define OC_INFORMATIVE_FILENAME(OC) \
161 ( (OC)->archiveMemberName ? \
162 (OC)->archiveMemberName : \
163 (OC)->fileName \
164 )
165
166 extern ObjectCode *objects;
167 extern ObjectCode *unloaded_objects;
168
169 #ifdef THREADED_RTS
170 extern Mutex linker_mutex;
171 extern Mutex linker_unloaded_mutex;
172 #endif
173
174 void exitLinker( void );
175
176 void freeObjectCode (ObjectCode *oc);
177
178 #endif /* LINKERINTERNALS_H */