Revert "rts: add Emacs 'Local Variables' to every .c file"
[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 struct _Section {
32 void* start;
33 void* end;
34 SectionKind kind;
35 struct _Section* next;
36 }
37 Section;
38
39 typedef
40 struct _ProddableBlock {
41 void* start;
42 int size;
43 struct _ProddableBlock* next;
44 }
45 ProddableBlock;
46
47 /*
48 * We must keep track of the StablePtrs that are created for foreign
49 * exports by constructor functions when the module is loaded, so that
50 * we can free them again when the module is unloaded. If we don't do
51 * this, then the StablePtr will keep the module alive indefinitely.
52 */
53 typedef struct ForeignExportStablePtr_ {
54 StgStablePtr stable_ptr;
55 struct ForeignExportStablePtr_ *next;
56 } ForeignExportStablePtr;
57
58 /* Jump Islands are sniplets of machine code required for relative
59 * address relocations on the PowerPC, x86_64 and ARM.
60 */
61 typedef struct {
62 #ifdef powerpc_HOST_ARCH
63 struct {
64 short lis_r12, hi_addr;
65 short ori_r12_r12, lo_addr;
66 long mtctr_r12;
67 long bctr;
68 } jumpIsland;
69 #elif x86_64_HOST_ARCH
70 uint64_t addr;
71 uint8_t jumpIsland[6];
72 #elif arm_HOST_ARCH
73 uint8_t jumpIsland[16];
74 #endif
75 } SymbolExtra;
76
77 /* Top-level structure for an object module. One of these is allocated
78 * for each object file in use.
79 */
80 typedef struct _ObjectCode {
81 OStatus status;
82 pathchar *fileName;
83 int fileSize;
84 char* formatName; /* eg "ELF32", "DLL", "COFF", etc. */
85
86 /* If this object is a member of an archive, archiveMemberName is
87 * like "libarchive.a(object.o)". Otherwise it's NULL.
88 */
89 char* archiveMemberName;
90
91 /* An array containing ptrs to all the symbol names copied from
92 this object into the global symbol hash table. This is so that
93 we know which parts of the latter mapping to nuke when this
94 object is removed from the system. */
95 char** symbols;
96 int n_symbols;
97
98 /* ptr to malloc'd lump of memory holding the obj file */
99 char* image;
100
101 /* flag used when deciding whether to unload an object file */
102 int referenced;
103
104 #ifdef darwin_HOST_OS
105 /* record by how much image has been deliberately misaligned
106 after allocation, so that we can use realloc */
107 int misalignment;
108 #endif
109
110 /* The section-kind entries for this object module. Linked
111 list. */
112 Section* sections;
113
114 /* Allow a chain of these things */
115 struct _ObjectCode * next;
116
117 /* SANITY CHECK ONLY: a list of the only memory regions which may
118 safely be prodded during relocation. Any attempt to prod
119 outside one of these is an error in the linker. */
120 ProddableBlock* proddables;
121
122 #ifdef ia64_HOST_ARCH
123 /* Procedure Linkage Table for this object */
124 void *plt;
125 unsigned int pltIndex;
126 #endif
127
128 #if powerpc_HOST_ARCH || x86_64_HOST_ARCH || arm_HOST_ARCH
129 SymbolExtra *symbol_extras;
130 unsigned long first_symbol_extra;
131 unsigned long n_symbol_extras;
132 #endif
133
134 ForeignExportStablePtr *stable_ptrs;
135
136 } ObjectCode;
137
138 #define OC_INFORMATIVE_FILENAME(OC) \
139 ( (OC)->archiveMemberName ? \
140 (OC)->archiveMemberName : \
141 (OC)->fileName \
142 )
143
144 extern ObjectCode *objects;
145 extern ObjectCode *unloaded_objects;
146
147 void exitLinker( void );
148
149 void freeObjectCode (ObjectCode *oc);
150
151 #endif /* LINKERINTERNALS_H */