Skip to content

Commit 5915b86

Browse files
committed
Fix patches for GHC 8.10
1 parent 91dade0 commit 5915b86

File tree

2 files changed

+239
-2
lines changed

2 files changed

+239
-2
lines changed

overlays/bootstrap.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,12 @@ in {
271271
++ fromUntil "9.8" "9.9" ./patches/ghc/docs-sphinx-7-ghc98.patch
272272

273273
# These two patches are needed for libblst, which has now hidden symbols, which the linker doesn't know how to deal with.
274-
++ until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols.patch
275-
++ until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-2.patch
274+
++ (
275+
if final.stdenv.targetPlatform.isAndroid
276+
then until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-android.patch
277+
else until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols.patch
278+
++ until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-2.patch
279+
)
276280
++ onWindowsOrMusl (fromUntil "9.6" "9.7" ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols.patch)
277281
++ onWindowsOrMusl (fromUntil "9.8.2" "9.11" ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols.patch)
278282
++ onWindowsOrMusl (fromUntil "9.6" "9.7" ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols-2.patch)
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
diff --git a/rts/Linker.c b/rts/Linker.c
2+
index 3428a010da..6eb43be959 100644
3+
--- a/rts/Linker.c
4+
+++ b/rts/Linker.c
5+
@@ -267,9 +267,12 @@ int ghciInsertSymbolTable(
6+
HashTable *table,
7+
const SymbolName* key,
8+
SymbolAddr* data,
9+
- HsBool weak,
10+
+ int flags,
11+
ObjectCode *owner)
12+
{
13+
+ HsBool weak = flags & 1;
14+
+ HsBool hidden = flags & 2;
15+
+
16+
RtsSymbolInfo *pinfo = lookupStrHashTable(table, key);
17+
if (!pinfo) /* new entry */
18+
{
19+
@@ -277,6 +280,7 @@ int ghciInsertSymbolTable(
20+
pinfo->value = data;
21+
pinfo->owner = owner;
22+
pinfo->weak = weak;
23+
+ pinfo->hidden = hidden;
24+
insertStrHashTable(table, key, pinfo);
25+
return 1;
26+
}
27+
@@ -340,11 +344,22 @@ int ghciInsertSymbolTable(
28+
call this function again to trigger the duplicate error. */
29+
return 1;
30+
}
31+
+ else if(pinfo->hidden && !hidden)
32+
+ {
33+
+ /* The existing symbol is hidden, let's replace it */
34+
+ pinfo->value = data;
35+
+ pinfo->owner = owner;
36+
+ pinfo->weak = weak;
37+
38+
+ pinfo->hidden = hidden;
39+
+ return 1;
40+
+ }
41+
pathchar* archiveName = NULL;
42+
debugBelch(
43+
"GHC runtime linker: fatal error: I found a duplicate definition for symbol\n"
44+
" %s\n"
45+
+ " new symbol is hidden: %d\n"
46+
+ " old symbol is hidden: %d\n"
47+
"whilst processing object file\n"
48+
" %" PATH_FMT "\n"
49+
"The symbol was previously defined in\n"
50+
@@ -355,6 +370,8 @@ int ghciInsertSymbolTable(
51+
" * An incorrect `package.conf' entry, causing some object to be\n"
52+
" loaded twice.\n",
53+
(char*)key,
54+
+ hidden ? 1 : 0,
55+
+ pinfo->hidden ? 1 : 0,
56+
obj_name,
57+
pinfo->owner == NULL ? WSTR("(GHCi built-in symbols)") :
58+
pinfo->owner->archiveMemberName ? archiveName = mkPath(pinfo->owner->archiveMemberName)
59+
@@ -451,7 +468,7 @@ initLinker_ (int retain_cafs)
60+
for (sym = rtsSyms; sym->lbl != NULL; sym++) {
61+
if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
62+
symhash, sym->lbl, sym->addr,
63+
- sym->weak, NULL)) {
64+
+ sym->weak | (HS_BOOL_FALSE << 1), NULL)) {
65+
barf("ghciInsertSymbolTable failed");
66+
}
67+
IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
68+
@@ -463,7 +480,7 @@ initLinker_ (int retain_cafs)
69+
use an arbitrary (hopefully unique) address here.
70+
*/
71+
if (! ghciInsertSymbolTable(WSTR("(GHCi special symbols)"),
72+
- symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, NULL)) {
73+
+ symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), NULL)) {
74+
barf("ghciInsertSymbolTable failed");
75+
}
76+
77+
@@ -471,7 +488,7 @@ initLinker_ (int retain_cafs)
78+
if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), symhash,
79+
MAYBE_LEADING_UNDERSCORE_STR("newCAF"),
80+
retain_cafs ? newRetainedCAF : newGCdCAF,
81+
- HS_BOOL_FALSE, NULL)) {
82+
+ HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), NULL)) {
83+
barf("ghciInsertSymbolTable failed");
84+
}
85+
86+
@@ -844,8 +861,8 @@ HsBool removeLibrarySearchPath(HsPtr dll_path_index)
87+
*/
88+
HsInt insertSymbol(pathchar* obj_name, SymbolName* key, SymbolAddr* data)
89+
{
90+
- return ghciInsertSymbolTable(obj_name, symhash, key, data, HS_BOOL_FALSE,
91+
- NULL);
92+
+ return ghciInsertSymbolTable(obj_name, symhash, key, data,
93+
+ HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), NULL);
94+
}
95+
96+
/* -----------------------------------------------------------------------------
97+
@@ -1696,7 +1713,8 @@ int ocTryLoad (ObjectCode* oc) {
98+
if ( symbol.name
99+
&& !ghciInsertSymbolTable(oc->fileName, symhash, symbol.name,
100+
symbol.addr,
101+
- isSymbolWeak(oc, symbol.name), oc)) {
102+
+ isSymbolWeak(oc, symbol.name) | (HS_BOOL_FALSE << 1),
103+
+ oc)) {
104+
return 0;
105+
}
106+
}
107+
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
108+
index a846bf5ca7..acba66828b 100644
109+
--- a/rts/LinkerInternals.h
110+
+++ b/rts/LinkerInternals.h
111+
@@ -310,6 +310,7 @@ typedef struct _RtsSymbolInfo {
112+
SymbolAddr* value;
113+
ObjectCode *owner;
114+
HsBool weak;
115+
+ HsBool hidden;
116+
} RtsSymbolInfo;
117+
118+
void exitLinker( void );
119+
@@ -337,7 +338,7 @@ int ghciInsertSymbolTable(
120+
HashTable *table,
121+
const SymbolName* key,
122+
SymbolAddr* data,
123+
- HsBool weak,
124+
+ int flags,
125+
ObjectCode *owner);
126+
127+
/* Lock-free version of lookupSymbol. When 'dependent' is not NULL, adds it as a
128+
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
129+
index c3f9110509..5bf7f00f31 100644
130+
--- a/rts/linker/Elf.c
131+
+++ b/rts/linker/Elf.c
132+
@@ -1013,7 +1013,9 @@ ocGetNames_ELF ( ObjectCode* oc )
133+
setWeakSymbol(oc, nm);
134+
}
135+
if (!ghciInsertSymbolTable(oc->fileName, symhash,
136+
- nm, symbol->addr, isWeak, oc)) {
137+
+ nm, symbol->addr,
138+
+ isWeak | ((ELF_ST_VISIBILITY(symbol->elf_sym->st_other) == STV_HIDDEN) << 1),
139+
+ oc)) {
140+
goto fail;
141+
}
142+
oc->symbols[curSymbol++].name = nm;
143+
diff --git a/rts/linker/ElfTypes.h b/rts/linker/ElfTypes.h
144+
index e5333d71a7..0a8e44a076 100644
145+
--- a/rts/linker/ElfTypes.h
146+
+++ b/rts/linker/ElfTypes.h
147+
@@ -32,6 +32,9 @@
148+
#define Elf_Sym Elf64_Sym
149+
#define Elf_Rel Elf64_Rel
150+
#define Elf_Rela Elf64_Rela
151+
+#if !defined(ELF_ST_VISIBILITY)
152+
+#define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY
153+
+#endif
154+
#if !defined(ELF_ST_TYPE)
155+
#define ELF_ST_TYPE ELF64_ST_TYPE
156+
#endif
157+
@@ -56,6 +59,9 @@
158+
#define Elf_Sym Elf32_Sym
159+
#define Elf_Rel Elf32_Rel
160+
#define Elf_Rela Elf32_Rela
161+
+#if !defined(ELF_ST_VISIBILITY)
162+
+#define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY
163+
+#endif /* ELF_ST_VISIBILITY */
164+
#if !defined(ELF_ST_TYPE)
165+
#define ELF_ST_TYPE ELF32_ST_TYPE
166+
#endif /* ELF_ST_TYPE */
167+
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
168+
index 00b0dce04c..d63369972d 100644
169+
--- a/rts/linker/MachO.c
170+
+++ b/rts/linker/MachO.c
171+
@@ -1336,7 +1336,7 @@ ocGetNames_MachO(ObjectCode* oc)
172+
, symhash
173+
, nm
174+
, addr
175+
- , HS_BOOL_FALSE
176+
+ , HS_BOOL_FALSE | (HS_BOOL_FALSE << 1)
177+
, oc);
178+
179+
oc->symbols[curSymbol].name = nm;
180+
@@ -1376,7 +1376,7 @@ ocGetNames_MachO(ObjectCode* oc)
181+
182+
IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting common symbol: %s\n", nm));
183+
ghciInsertSymbolTable(oc->fileName, symhash, nm,
184+
- (void*)commonCounter, HS_BOOL_FALSE, oc);
185+
+ (void*)commonCounter, HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), oc);
186+
oc->symbols[curSymbol].name = nm;
187+
oc->symbols[curSymbol].addr = oc->info->macho_symbols[i].addr;
188+
curSymbol++;
189+
diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c
190+
index c73d858d52..74b7fd1009 100644
191+
--- a/rts/linker/PEi386.c
192+
+++ b/rts/linker/PEi386.c
193+
@@ -292,7 +292,7 @@ const void* __rts_iob_func = (void*)&__acrt_iob_func;
194+
void initLinker_PEi386()
195+
{
196+
if (!ghciInsertSymbolTable(WSTR("(GHCi/Ld special symbols)"),
197+
- symhash, "__image_base__", __image_base, HS_BOOL_TRUE, NULL)) {
198+
+ symhash, "__image_base__", __image_base, HS_BOOL_TRUE | (HS_BOOL_FALSE << 1), NULL)) {
199+
barf("ghciInsertSymbolTable failed");
200+
}
201+
202+
@@ -1533,7 +1533,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
203+
sname = strdup (sname);
204+
addr = strdup (addr);
205+
if (!ghciInsertSymbolTable(oc->fileName, symhash, sname,
206+
- addr, false, oc)) {
207+
+ addr, HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), oc)) {
208+
releaseOcInfo (oc);
209+
stgFree (oc->image);
210+
oc->image = NULL;
211+
@@ -1751,7 +1751,9 @@ ocGetNames_PEi386 ( ObjectCode* oc )
212+
stgFree(tmp);
213+
sname = strdup (sname);
214+
if (!ghciInsertSymbolTable(oc->fileName, symhash, sname,
215+
- addr, false, oc))
216+
+ addr,
217+
+ HS_BOOL_FALSE | ((secNumber == IMAGE_SYM_UNDEFINED) << 1),
218+
+ oc))
219+
return false;
220+
221+
break;
222+
@@ -1768,9 +1770,9 @@ ocGetNames_PEi386 ( ObjectCode* oc )
223+
if (isWeak) {
224+
setWeakSymbol(oc, sname);
225+
}
226+
-
227+
if (! ghciInsertSymbolTable(oc->fileName, symhash, sname, addr,
228+
- isWeak, oc))
229+
+ isWeak | ((secNumber == IMAGE_SYM_UNDEFINED) << 1),
230+
+ oc))
231+
return false;
232+
} else {
233+
/* We're skipping the symbol, but if we ever load this

0 commit comments

Comments
 (0)