1 |
slyfox 13/08/01 13:15:33 |
2 |
|
3 |
Added: ghc-7.6.3-trac-3333-weak-syms.patch |
4 |
Log: |
5 |
Fixed CFLAGS=-Os ghci failure (bug #452442 by Jason Mours). Added weak symbol processing into ghci. Limit maximum parallel job count down to 4 workers (-j1 is too slow on mmodern boxes, but -j12 kills the build almost always). Does not eliminate failures completely, but reduces them significantly (bug #456386). |
6 |
|
7 |
(Portage version: 2.2.0_alpha186/cvs/Linux x86_64, signed Manifest commit with key 611FF3AA) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/files/ghc-7.6.3-trac-3333-weak-syms.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: ghc-7.6.3-trac-3333-weak-syms.patch |
16 |
=================================================================== |
17 |
The patch set adds support for weak symbols to ghci. |
18 |
|
19 |
For gentoo it fixes nonworking ghci / template haskell |
20 |
for package base. |
21 |
|
22 |
Steps to reproduce: |
23 |
1. CFLAGS=-Os emerge ghc |
24 |
2. ghci -package base |
25 |
Loading package base ... linking ... ghc: /usr/lib64/ghc-7.6.3/base-4.6.0.1/HSbase-4.6.0.1.o: unknown symbol `stat' |
26 |
|
27 |
When built with -O2 weak 'stat' resolved to '__xstat' and we don't see any errors. |
28 |
But on olwer optimization levels 'stat' remains. |
29 |
|
30 |
Patches-by: akio |
31 |
Gentoo-bug: http://bugs.gentoo.org/452442 |
32 |
Upstream-bug: http://ghc.haskell.org/trac/ghc/ticket/3333 |
33 |
|
34 |
From 500d57d3a18412c78cab5abc4d91f1564edc964d Mon Sep 17 00:00:00 2001 |
35 |
From: Takano Akio <aljee@×××××.cx> |
36 |
Date: Sat, 29 Dec 2012 11:47:22 +0900 |
37 |
Subject: [PATCH 1/3] Linker.c: remove stablehash, which is no longer used |
38 |
|
39 |
--- |
40 |
includes/rts/Linker.h | 3 --- |
41 |
rts/Linker.c | 31 ++----------------------------- |
42 |
2 files changed, 2 insertions(+), 32 deletions(-) |
43 |
|
44 |
diff --git a/includes/rts/Linker.h b/includes/rts/Linker.h |
45 |
index e900e85..d20ebc2 100644 |
46 |
--- a/includes/rts/Linker.h |
47 |
+++ b/includes/rts/Linker.h |
48 |
@@ -23,9 +23,6 @@ typedef char pathchar; |
49 |
/* initialize the object linker */ |
50 |
void initLinker( void ); |
51 |
|
52 |
-/* insert a stable symbol in the hash table */ |
53 |
-void insertStableSymbol(pathchar* obj_name, char* key, StgPtr data); |
54 |
- |
55 |
/* insert a symbol in the hash table */ |
56 |
void insertSymbol(pathchar* obj_name, char* key, void* data); |
57 |
|
58 |
diff --git a/rts/Linker.c b/rts/Linker.c |
59 |
index fa1de89..513fe3f 100644 |
60 |
--- a/rts/Linker.c |
61 |
+++ b/rts/Linker.c |
62 |
@@ -30,1 +30,0 @@ |
63 |
-#include "Stable.h" |
64 |
@@ -150,9 +149,6 @@ int dynamicByDefault = 0; |
65 |
/* Hash table mapping symbol names to Symbol */ |
66 |
static /*Str*/HashTable *symhash; |
67 |
|
68 |
-/* Hash table mapping symbol names to StgStablePtr */ |
69 |
-static /*Str*/HashTable *stablehash; |
70 |
- |
71 |
/* List of currently loaded objects */ |
72 |
ObjectCode *objects = NULL; /* initially empty */ |
73 |
|
74 |
@@ -1126,1 +1126,0 @@ typedef struct _RtsSymbolVal { |
75 |
- SymI_HasProto(insertStableSymbol) \ |
76 |
@@ -1488,7 +1483,6 @@ initLinker( void ) |
77 |
#if defined(THREADED_RTS) && (defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO)) |
78 |
initMutex(&dl_mutex); |
79 |
#endif |
80 |
- stablehash = allocStrHashTable(); |
81 |
symhash = allocStrHashTable(); |
82 |
|
83 |
/* populate the symbol table with stuff from the RTS */ |
84 |
@@ -1817,17 +1811,6 @@ error: |
85 |
} |
86 |
|
87 |
/* ----------------------------------------------------------------------------- |
88 |
- * insert a stable symbol in the hash table |
89 |
- */ |
90 |
- |
91 |
-void |
92 |
-insertStableSymbol(pathchar* obj_name, char* key, StgPtr p) |
93 |
-{ |
94 |
- ghciInsertStrHashTable(obj_name, stablehash, key, getStablePtr(p)); |
95 |
-} |
96 |
- |
97 |
- |
98 |
-/* ----------------------------------------------------------------------------- |
99 |
* insert a symbol in the hash table |
100 |
*/ |
101 |
void |
102 |
@@ -4749,8 +4732,6 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC, |
103 |
#ifdef i386_HOST_ARCH |
104 |
Elf_Addr value; |
105 |
#endif |
106 |
- StgStablePtr stablePtr; |
107 |
- StgPtr stableVal; |
108 |
#ifdef arm_HOST_ARCH |
109 |
int is_target_thm=0, T=0; |
110 |
#endif |
111 |
@@ -4773,16 +4754,8 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC, |
112 |
|
113 |
} else { |
114 |
symbol = strtab + sym.st_name; |
115 |
- stablePtr = (StgStablePtr)lookupHashTable(stablehash, (StgWord)symbol); |
116 |
- if (NULL == stablePtr) { |
117 |
- /* No, so look up the name in our global table. */ |
118 |
- S_tmp = lookupSymbol( symbol ); |
119 |
- S = (Elf_Addr)S_tmp; |
120 |
- } else { |
121 |
- stableVal = deRefStablePtr( stablePtr ); |
122 |
- S_tmp = stableVal; |
123 |
- S = (Elf_Addr)S_tmp; |
124 |
- } |
125 |
+ S_tmp = lookupSymbol( symbol ); |
126 |
+ S = (Elf_Addr)S_tmp; |
127 |
} |
128 |
if (!S) { |
129 |
errorBelch("%s: unknown symbol `%s'", oc->fileName, symbol); |
130 |
-- |
131 |
1.7.9.5 |
132 |
|
133 |
From 2e5e0f7a90dd390adc5ae5fb2a3bc6e879aa42d6 Mon Sep 17 00:00:00 2001 |
134 |
From: Takano Akio <aljee@×××××.cx> |
135 |
Date: Sat, 29 Dec 2012 11:59:34 +0900 |
136 |
Subject: [PATCH 2/3] ghci: add support for ELF weak symbols |
137 |
|
138 |
--- |
139 |
rts/Linker.c | 102 ++++++++++++++++++++++++++++++++++++++++++++-------------- |
140 |
1 file changed, 78 insertions(+), 24 deletions(-) |
141 |
|
142 |
diff --git a/rts/Linker.c b/rts/Linker.c |
143 |
index 513fe3f..5105085 100644 |
144 |
--- a/rts/Linker.c |
145 |
+++ b/rts/Linker.c |
146 |
@@ -146,7 +146,13 @@ int dynamicByDefault = 1; |
147 |
int dynamicByDefault = 0; |
148 |
#endif |
149 |
|
150 |
-/* Hash table mapping symbol names to Symbol */ |
151 |
+typedef struct _RtsSymbolInfo { |
152 |
+ void *value; |
153 |
+ const ObjectCode *owner; |
154 |
+ HsBool weak; |
155 |
+} RtsSymbolInfo; |
156 |
+ |
157 |
+/* Hash table mapping symbol names to RtsSymbolInfo */ |
158 |
static /*Str*/HashTable *symhash; |
159 |
|
160 |
/* List of currently loaded objects */ |
161 |
@@ -1415,15 +1421,31 @@ static RtsSymbolVal rtsSyms[] = { |
162 |
* Insert symbols into hash tables, checking for duplicates. |
163 |
*/ |
164 |
|
165 |
-static void ghciInsertStrHashTable ( pathchar* obj_name, |
166 |
- HashTable *table, |
167 |
- char* key, |
168 |
- void *data |
169 |
- ) |
170 |
+static void ghciInsertSymbolTable( |
171 |
+ pathchar* obj_name, |
172 |
+ HashTable *table, |
173 |
+ char* key, |
174 |
+ void *data, |
175 |
+ HsBool weak, |
176 |
+ ObjectCode *owner) |
177 |
{ |
178 |
- if (lookupHashTable(table, (StgWord)key) == NULL) |
179 |
+ RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); |
180 |
+ if (!pinfo) /* new entry */ |
181 |
+ { |
182 |
+ pinfo = stgMallocBytes(sizeof (*pinfo), "ghciInsertToSymbolTable"); |
183 |
+ pinfo->value = data; |
184 |
+ pinfo->owner = owner; |
185 |
+ pinfo->weak = weak; |
186 |
+ insertStrHashTable(table, key, pinfo); |
187 |
+ return; |
188 |
+ } else if ((!pinfo->weak || pinfo->value) && weak) { |
189 |
+ return; /* duplicate weak symbol, throw it away */ |
190 |
+ } else if (pinfo->weak) /* weak symbol is in the table */ |
191 |
{ |
192 |
- insertStrHashTable(table, (StgWord)key, data); |
193 |
+ /* override the weak definition with the non-weak one */ |
194 |
+ pinfo->value = data; |
195 |
+ pinfo->owner = owner; |
196 |
+ pinfo->weak = HS_BOOL_FALSE; |
197 |
return; |
198 |
} |
199 |
debugBelch( |
200 |
@@ -1444,6 +1466,32 @@ static void ghciInsertStrHashTable ( pathchar* obj_name, |
201 |
); |
202 |
stg_exit(1); |
203 |
} |
204 |
+ |
205 |
+static HsBool ghciLookupSymbolTable(HashTable *table, |
206 |
+ const char *key, void **result) |
207 |
+{ |
208 |
+ RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); |
209 |
+ if (!pinfo) { |
210 |
+ *result = NULL; |
211 |
+ return HS_BOOL_FALSE; |
212 |
+ } |
213 |
+ if (pinfo->weak) |
214 |
+ IF_DEBUG(linker, debugBelch("lookup: promoting %s\n", key)); |
215 |
+ /* Once it's looked up, it can no longer be overridden */ |
216 |
+ pinfo->weak = HS_BOOL_FALSE; |
217 |
+ |
218 |
+ *result = pinfo->value; |
219 |
+ return HS_BOOL_TRUE; |
220 |
+} |
221 |
+ |
222 |
+static void ghciRemoveSymbolTable(HashTable *table, const char *key, |
223 |
+ ObjectCode *owner) |
224 |
+{ |
225 |
+ RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); |
226 |
+ if (!pinfo || owner != pinfo->owner) return; |
227 |
+ removeStrHashTable(table, key, NULL); |
228 |
+ stgFree(pinfo); |
229 |
+} |
230 |
/* ----------------------------------------------------------------------------- |
231 |
* initialize the object linker |
232 |
*/ |
233 |
@@ -1487,8 +1535,8 @@ initLinker( void ) |
234 |
|
235 |
/* populate the symbol table with stuff from the RTS */ |
236 |
for (sym = rtsSyms; sym->lbl != NULL; sym++) { |
237 |
- ghciInsertStrHashTable(WSTR("(GHCi built-in symbols)"), |
238 |
- symhash, sym->lbl, sym->addr); |
239 |
+ ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), |
240 |
+ symhash, sym->lbl, sym->addr, HS_BOOL_FALSE, NULL); |
241 |
IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr)); |
242 |
} |
243 |
# if defined(OBJFORMAT_MACHO) && defined(powerpc_HOST_ARCH) |
244 |
@@ -1816,7 +1864,7 @@ error: |
245 |
void |
246 |
insertSymbol(pathchar* obj_name, char* key, void* data) |
247 |
{ |
248 |
- ghciInsertStrHashTable(obj_name, symhash, key, data); |
249 |
+ ghciInsertSymbolTable(obj_name, symhash, key, data, HS_BOOL_FALSE, NULL); |
250 |
} |
251 |
|
252 |
/* ----------------------------------------------------------------------------- |
253 |
@@ -1829,9 +1877,8 @@ lookupSymbol( char *lbl ) |
254 |
IF_DEBUG(linker, debugBelch("lookupSymbol: looking up %s\n", lbl)); |
255 |
initLinker() ; |
256 |
ASSERT(symhash != NULL); |
257 |
- val = lookupStrHashTable(symhash, lbl); |
258 |
|
259 |
- if (val == NULL) { |
260 |
+ if (!ghciLookupSymbolTable(symhash, lbl, &val)) { |
261 |
IF_DEBUG(linker, debugBelch("lookupSymbol: symbol not found\n")); |
262 |
# if defined(OBJFORMAT_ELF) |
263 |
return internal_dlsym(dl_prog_handle, lbl); |
264 |
@@ -1903,7 +1950,7 @@ void ghci_enquire ( char* addr ) |
265 |
if (sym == NULL) continue; |
266 |
a = NULL; |
267 |
if (a == NULL) { |
268 |
- a = lookupStrHashTable(symhash, sym); |
269 |
+ ghciLookupSymbolTable(symhash, sym, (void **)&a); |
270 |
} |
271 |
if (a == NULL) { |
272 |
// debugBelch("ghci_enquire: can't find %s\n", sym); |
273 |
@@ -2715,7 +2762,7 @@ unloadObj( pathchar *path ) |
274 |
int i; |
275 |
for (i = 0; i < oc->n_symbols; i++) { |
276 |
if (oc->symbols[i] != NULL) { |
277 |
- removeStrHashTable(symhash, oc->symbols[i], NULL); |
278 |
+ ghciRemoveSymbolTable(symhash, oc->symbols[i], oc); |
279 |
} |
280 |
} |
281 |
} |
282 |
@@ -3802,7 +3849,8 @@ ocGetNames_PEi386 ( ObjectCode* oc ) |
283 |
ASSERT(i >= 0 && i < oc->n_symbols); |
284 |
/* cstring_from_COFF_symbol_name always succeeds. */ |
285 |
oc->symbols[i] = (char*)sname; |
286 |
- ghciInsertStrHashTable(oc->fileName, symhash, (char*)sname, addr); |
287 |
+ ghciInsertSymbolTable(oc->fileName, symhash, (char*)sname, addr, |
288 |
+ HS_BOOL_FALSE, oc); |
289 |
} else { |
290 |
# if 0 |
291 |
debugBelch( |
292 |
@@ -4595,6 +4643,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
293 |
for (j = 0; j < nent; j++) { |
294 |
|
295 |
char isLocal = FALSE; /* avoids uninit-var warning */ |
296 |
+ HsBool isWeak = HS_BOOL_FALSE; |
297 |
char* ad = NULL; |
298 |
char* nm = strtab + stab[j].st_name; |
299 |
int secno = stab[j].st_shndx; |
300 |
@@ -4615,6 +4664,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
301 |
else |
302 |
if ( ( ELF_ST_BIND(stab[j].st_info)==STB_GLOBAL |
303 |
|| ELF_ST_BIND(stab[j].st_info)==STB_LOCAL |
304 |
+ || ELF_ST_BIND(stab[j].st_info)==STB_WEAK |
305 |
) |
306 |
/* and not an undefined symbol */ |
307 |
&& stab[j].st_shndx != SHN_UNDEF |
308 |
@@ -4638,7 +4688,8 @@ ocGetNames_ELF ( ObjectCode* oc ) |
309 |
ad = ehdrC + shdr[ secno ].sh_offset + stab[j].st_value; |
310 |
if (ELF_ST_BIND(stab[j].st_info)==STB_LOCAL) { |
311 |
isLocal = TRUE; |
312 |
- } else { |
313 |
+ isWeak = FALSE; |
314 |
+ } else { /* STB_GLOBAL or STB_WEAK */ |
315 |
#ifdef ELF_FUNCTION_DESC |
316 |
/* dlsym() and the initialisation table both give us function |
317 |
* descriptors, so to be consistent we store function descriptors |
318 |
@@ -4649,6 +4700,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
319 |
IF_DEBUG(linker,debugBelch( "addOTabName(GLOB): %10p %s %s\n", |
320 |
ad, oc->fileName, nm )); |
321 |
isLocal = FALSE; |
322 |
+ isWeak = (ELF_ST_BIND(stab[j].st_info)==STB_WEAK); |
323 |
} |
324 |
} |
325 |
|
326 |
@@ -4661,7 +4713,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
327 |
if (isLocal) { |
328 |
/* Ignore entirely. */ |
329 |
} else { |
330 |
- ghciInsertStrHashTable(oc->fileName, symhash, nm, ad); |
331 |
+ ghciInsertSymbolTable(oc->fileName, symhash, nm, ad, isWeak, oc); |
332 |
} |
333 |
} else { |
334 |
/* Skip. */ |
335 |
@@ -6306,11 +6358,13 @@ ocGetNames_MachO(ObjectCode* oc) |
336 |
else |
337 |
{ |
338 |
IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting %s\n", nm)); |
339 |
- ghciInsertStrHashTable(oc->fileName, symhash, nm, |
340 |
+ ghciInsertSymbolTable(oc->fileName, symhash, nm, |
341 |
image |
342 |
+ sections[nlist[i].n_sect-1].offset |
343 |
- sections[nlist[i].n_sect-1].addr |
344 |
- + nlist[i].n_value); |
345 |
+ + nlist[i].n_value, |
346 |
+ HS_BOOL_FALSE, |
347 |
+ oc); |
348 |
oc->symbols[curSymbol++] = nm; |
349 |
} |
350 |
} |
351 |
@@ -6341,8 +6395,8 @@ ocGetNames_MachO(ObjectCode* oc) |
352 |
nlist[i].n_value = commonCounter; |
353 |
|
354 |
IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting common symbol: %s\n", nm)); |
355 |
- ghciInsertStrHashTable(oc->fileName, symhash, nm, |
356 |
- (void*)commonCounter); |
357 |
+ ghciInsertSymbolTable(oc->fileName, symhash, nm, |
358 |
+ (void*)commonCounter, HS_BOOL_FALSE, oc); |
359 |
oc->symbols[curSymbol++] = nm; |
360 |
|
361 |
commonCounter += sz; |
362 |
@@ -6466,7 +6520,7 @@ machoInitSymbolsWithoutUnderscore(void) |
363 |
|
364 |
#undef SymI_NeedsProto |
365 |
#define SymI_NeedsProto(x) \ |
366 |
- ghciInsertStrHashTable("(GHCi built-in symbols)", symhash, #x, *p++); |
367 |
+ ghciInsertSymbolTable("(GHCi built-in symbols)", symhash, #x, *p++, HS_BOOL_FALSE, NULL); |
368 |
|
369 |
RTS_MACHO_NOUNDERLINE_SYMBOLS |
370 |
|
371 |
-- |
372 |
1.7.9.5 |
373 |
|
374 |
From 916d7713b34b529ae7ec24eaa836a4eaca7724fc Mon Sep 17 00:00:00 2001 |
375 |
From: Takano Akio <aljee@×××××.cx> |
376 |
Date: Sun, 6 Jan 2013 17:51:19 +0900 |
377 |
Subject: [PATCH 3/3] Linker.c: add dso_handle to the symbol table |
378 |
|
379 |
--- |
380 |
rts/Linker.c | 7 +++++++ |
381 |
1 file changed, 7 insertions(+) |
382 |
|
383 |
diff --git a/rts/Linker.c b/rts/Linker.c |
384 |
index 5105085..0b2bf63 100644 |
385 |
--- a/rts/Linker.c |
386 |
+++ b/rts/Linker.c |
387 |
@@ -1542,6 +1542,13 @@ initLinker( void ) |
388 |
# if defined(OBJFORMAT_MACHO) && defined(powerpc_HOST_ARCH) |
389 |
machoInitSymbolsWithoutUnderscore(); |
390 |
# endif |
391 |
+ /* GCC defines a special symbol __dso_handle which is resolved to NULL if |
392 |
+ referenced from a statically linked module. We need to mimic this, but |
393 |
+ we cannot use NULL because we use it to mean nonexistent symbols. So we |
394 |
+ use an arbitrary (hopefully unique) address here. |
395 |
+ */ |
396 |
+ ghciInsertSymbolTable(WSTR("(GHCi special symbols)"), |
397 |
+ symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, NULL); |
398 |
|
399 |
# if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO) |
400 |
# if defined(RTLD_DEFAULT) |
401 |
-- |
402 |
1.7.9.5 |