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