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