@@ -26,17 +26,17 @@ index 59e2ff9397..78e43cd471 100644
26
26
o_so->next = openedSOs;
27
27
openedSOs = o_so;
28
28
@@ -1314,7 +1314,7 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
29
-
30
-
29
+
30
+
31
31
IF_DEBUG(linker, debugBelch("mkOc: %" PATH_FMT "\n", path));
32
32
- oc = stgMallocBytes(sizeof(ObjectCode), "mkOc(oc)");
33
33
+ oc = stgCallocBytes(1, sizeof(ObjectCode), "mkOc(oc)");
34
-
34
+
35
35
oc->info = NULL;
36
36
oc->type = type;
37
37
@@ -1334,7 +1334,7 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
38
38
oc->fileName = pathdup(path);
39
-
39
+
40
40
if (archiveMemberName) {
41
41
- oc->archiveMemberName = stgMallocBytes( (pathlen(archiveMemberName)+1) * pathsize,
42
42
+ oc->archiveMemberName = stgCallocBytes(1, (pathlen(archiveMemberName)+1) * pathsize,
@@ -50,17 +50,17 @@ index 59e2ff9397..78e43cd471 100644
50
50
- image = stgMallocBytes(fileSize + misalignment, "loadObj(image)");
51
51
+ image = stgCallocBytes(1, fileSize + misalignment, "loadObj(image)");
52
52
image += misalignment;
53
-
53
+
54
54
# else /* !defined(darwin_HOST_OS) */
55
-
55
+
56
56
- image = stgMallocBytes(fileSize, "loadObj(image)");
57
57
+ image = stgCallocBytes(1, fileSize, "loadObj(image)");
58
-
58
+
59
59
#endif /* !defined(darwin_HOST_OS) */
60
-
60
+
61
61
@@ -1787,6 +1787,8 @@ static HsInt resolveObjs_ (void)
62
62
IF_DEBUG(linker, debugBelch("resolveObjs: start\n"));
63
-
63
+
64
64
for (ObjectCode *oc = objects; oc; oc = oc->next) {
65
65
+ if(oc->status == OBJECT_RESOLVED)
66
66
+ continue;
@@ -73,7 +73,7 @@ index 59e2ff9397..78e43cd471 100644
73
73
ProddableBlock* pb
74
74
- = stgMallocBytes(sizeof(ProddableBlock), "addProddableBlock");
75
75
+ = stgCallocBytes(1,sizeof(ProddableBlock), "addProddableBlock");
76
-
76
+
77
77
IF_DEBUG(linker, debugBelch("addProddableBlock: %p %p %d\n", oc, start, size));
78
78
ASSERT(size > 0);
79
79
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
@@ -83,7 +83,7 @@ index 271611a249..784bb19c10 100644
83
83
@@ -299,6 +299,10 @@ struct _ObjectCode {
84
84
int n_segments;
85
85
Segment *segments;
86
-
86
+
87
87
+ // COMMON section
88
88
+ void * common_mem;
89
89
+ unsigned long common_size;
@@ -106,9 +106,9 @@ index 4cac10ba15..fe0d8ca40e 100644
106
106
+ memset(space, 0, count*size);
107
107
return space;
108
108
}
109
-
109
+
110
110
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
111
- index bab2ca3041..5d91301c51 100644
111
+ index bab2ca3041..9f623a62da 100644
112
112
--- a/rts/linker/Elf.c
113
113
+++ b/rts/linker/Elf.c
114
114
@@ -303,6 +303,15 @@ ocInit_ELF(ObjectCode * oc)
@@ -125,7 +125,7 @@ index bab2ca3041..5d91301c51 100644
125
125
+ oc->common_mem = NULL;
126
126
+ oc->common_size = 0;
127
127
}
128
-
128
+
129
129
void
130
130
@@ -961,14 +970,17 @@ ocGetNames_ELF ( ObjectCode* oc )
131
131
for (size_t j = 0; j < symTab->n_symbols; j++) {
@@ -149,17 +149,19 @@ index bab2ca3041..5d91301c51 100644
149
149
barf("ocGetNames_ELF: Failed to allocate memory for SHN_COMMONs");
150
150
}
151
151
}
152
- @@ -1010,8 +1022,9 @@ ocGetNames_ELF ( ObjectCode* oc )
152
+ @@ -1009,9 +1021,10 @@ ocGetNames_ELF ( ObjectCode* oc )
153
+ if (shndx == SHN_COMMON) {
153
154
isLocal = false;
154
155
CHECK(common_used < common_size);
155
- CHECK(common_mem);
156
+ - CHECK(common_mem);
156
157
- symbol->addr = (void*)((uintptr_t)common_mem + common_used);
157
158
- common_used += symbol->elf_sym->st_size;
159
+ + CHECK(oc->common_mem);
158
160
+ int alignment = symbol->elf_sym->st_value-1;
159
161
+ symbol->addr = (void*)(((uintptr_t)oc->common_mem + common_used + alignment) & ~alignment);
160
162
+ common_used = (uintptr_t)symbol->addr - (uintptr_t)oc->common_mem + symbol->elf_sym->st_size;
161
163
CHECK(common_used <= common_size);
162
-
164
+
163
165
IF_DEBUG(linker_verbose,
164
166
@@ -1025,7 +1038,9 @@ ocGetNames_ELF ( ObjectCode* oc )
165
167
|| ELF_ST_BIND(symbol->elf_sym->st_info) == STB_WEAK
@@ -187,10 +189,25 @@ index bab2ca3041..5d91301c51 100644
187
189
if (ELF_ST_BIND(symbol->elf_sym->st_info) == STB_LOCAL) {
188
190
isLocal = true;
189
191
isWeak = false;
190
- @@ -1070,35 +1093,20 @@ ocGetNames_ELF ( ObjectCode* oc )
191
- sym_type = SYM_TYPE_CODE;
192
+ @@ -1063,42 +1086,20 @@ ocGetNames_ELF ( ObjectCode* oc )
193
+ isWeak = ELF_ST_BIND(symbol->elf_sym->st_info)
194
+ == STB_WEAK;
195
+ }
196
+ - }
197
+ -
198
+ - SymType sym_type;
199
+ - if (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC) {
200
+ - sym_type = SYM_TYPE_CODE;
201
+ + } else if (ELF_ST_BIND(symbol->elf_sym->st_info) == STB_WEAK
202
+ + && shndx == SHN_UNDEF
203
+ + && (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC
204
+ + || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_OBJECT
205
+ + || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_NOTYPE)) {
206
+ + symbol->addr = NULL;
207
+ + isLocal = false;
208
+ + isWeak = true;
192
209
} else {
193
- sym_type = SYM_TYPE_DATA;
210
+ - sym_type = SYM_TYPE_DATA;
194
211
- }
195
212
-
196
213
- /* And the decision is ... */
@@ -215,16 +232,7 @@ index bab2ca3041..5d91301c51 100644
215
232
- }
216
233
- } else {
217
234
- /* Skip. */
218
- + } else if (ELF_ST_BIND(symbol->elf_sym->st_info) == STB_WEAK
219
- + && shndx == SHN_UNDEF
220
- + && (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC
221
- + || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_OBJECT
222
- + || ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_NOTYPE)) {
223
- + symbol->addr = NULL;
224
- + isLocal = false;
225
- + isWeak = true;
226
- + } else {
227
- + /* skip this symbol */
235
+ + /* Skip. */
228
236
IF_DEBUG(linker_verbose,
229
237
debugBelch("skipping `%s'\n",
230
238
nm)
@@ -233,28 +241,37 @@ index bab2ca3041..5d91301c51 100644
233
241
/*
234
242
debugBelch(
235
243
"skipping bind = %d, type = %d, secno = %d `%s'\n",
236
- @@ -1108,7 +1116,24 @@ ocGetNames_ELF ( ObjectCode* oc )
244
+ @@ -1108,7 +1109,34 @@ ocGetNames_ELF ( ObjectCode* oc )
237
245
nm
238
246
);
239
247
*/
240
- - }
241
248
+ continue;
242
- + }
249
+ }
250
+ +
251
+ + SymType sym_type;
252
+ + if (ELF_ST_TYPE(symbol->elf_sym->st_info) == STT_FUNC) {
253
+ + sym_type = SYM_TYPE_CODE;
254
+ + } else {
255
+ + sym_type = SYM_TYPE_DATA;
256
+ + }
243
257
+
244
258
+ /* And the decision is ... */
245
- + ASSERT (nm != NULL);
259
+ + CHECK (nm != NULL);
246
260
+ /* Acquire! */
247
261
+ if (!isLocal) {
248
262
+
249
263
+ if (isWeak == HS_BOOL_TRUE) {
250
264
+ setWeakSymbol(oc, nm);
251
265
+ }
252
266
+ if (!ghciInsertSymbolTable(oc->fileName, symhash,
253
- + nm, symbol->addr, isWeak, oc)) {
267
+ + nm, symbol->addr, isWeak, sym_type, oc)
268
+ + ) {
254
269
+ goto fail;
255
270
+ }
256
- + oc->symbols[curSymbol++ ].name = nm;
271
+ + oc->symbols[curSymbol].name = nm;
257
272
+ oc->symbols[curSymbol].addr = symbol->addr;
273
+ + oc->symbols[curSymbol].type = sym_type;
274
+ + curSymbol++;
258
275
+ }
259
276
}
260
277
}
@@ -267,12 +284,12 @@ index 9cd42efff2..70817d8b0b 100644
267
284
#include "Rts.h"
268
285
+ #include "RtsUtils.h"
269
286
#include "elf_plt.h"
270
-
287
+
271
288
#include <stdbool.h>
272
289
@@ -51,7 +52,7 @@ makeStub(Section * section,
273
290
void* * addr,
274
291
uint8_t flags) {
275
-
292
+
276
293
- Stub * s = calloc(1, sizeof(Stub));
277
294
+ Stub * s = stgCallocBytes(1, sizeof(Stub), "makeStub");
278
295
ASSERT(s != NULL);
0 commit comments