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