Skip to content

Commit d62e388

Browse files
committed
Patches for back porting fixes to 9.12
1 parent 17d6cbe commit d62e388

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

builder/ghc-for-component-wrapper.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ let
137137
+ lib.optionalString (stdenv.hostPlatform.isWasm) ''
138138
rm $wrappedGhc/lib/*.mjs
139139
cp $unwrappedGhc/lib/*.mjs $wrappedGhc/lib/
140-
substituteInPlace $wrappedGhc/lib/dyld.mjs \
141-
--replace-fail "instance.exports.__wasm_apply_data_relocs();" \
142-
"if(instance.exports.__wasm_apply_data_relocs) instance.exports.__wasm_apply_data_relocs(); else {}"
143140
''
144141
# Wrap haddock, if the base GHC provides it.
145142
+ ''

overlays/bootstrap.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ in {
8888
onNative = final.lib.optionals (final.stdenv.buildPlatform == final.stdenv.targetPlatform);
8989
onCross = final.lib.optionals (final.stdenv.targetPlatform != final.stdenv.hostPlatform);
9090
onGhcjs = final.lib.optionals final.stdenv.targetPlatform.isGhcjs;
91+
onWasm = final.lib.optionals final.stdenv.targetPlatform.isWasm;
9192
on32bit = final.lib.optionals final.stdenv.targetPlatform.is32bit;
9293
# Try to avoid reordering the patches unless a patch is added or changed that
9394
# will be applied to most versions of the GHC anyway (reordering the patches
@@ -338,6 +339,9 @@ in {
338339
++ onGhcjs (from "9.13" ./patches/ghc/ghc-9.13-ghcjs-rts-types.patch)
339340

340341
++ onGhcjs (fromUntil "9.6.7" "9.7" ./patches/ghc/ghc-9.6-js-support-this-unit-id-10819.patch)
342+
343+
++ onWasm (until "9.13" ./patches/ghc/ghc-9.12-wasm-shared-libs.patch)
344+
++ onWasm (until "9.13" ./patches/ghc/ghc-9.12-wasm-keep-cafs.patch)
341345
;
342346
in ({
343347
ghc8107 = traceWarnOld "8.10" (final.callPackage ../compiler/ghc {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From 10f06163d9adcb3b6e6438f1524faaca3bf6c3b2 Mon Sep 17 00:00:00 2001
2+
From: Cheng Shao <[email protected]>
3+
Date: Sat, 23 Aug 2025 05:11:31 +0200
4+
Subject: [PATCH] wasm: ensure setKeepCAFs() is called in ghci
5+
6+
This patch is a critical bugfix for #26106, see comment and linked
7+
issue for details.
8+
---
9+
utils/jsffi/dyld.mjs | 14 ++++++++++++++
10+
1 file changed, 14 insertions(+)
11+
12+
diff --git a/utils/jsffi/dyld.mjs b/utils/jsffi/dyld.mjs
13+
index 285cc8b72011..8c38ebc2efa0 100755
14+
--- a/utils/jsffi/dyld.mjs
15+
+++ b/utils/jsffi/dyld.mjs
16+
@@ -1105,6 +1105,20 @@ class DyLD {
17+
if (/libHSghc-internal-\d+(\.\d+)*/i.test(soname)) {
18+
this.rts_init();
19+
delete this.rts_init;
20+
+
21+
+ // At this point the RTS symbols in linear memory are fixed
22+
+ // and constructors are run, especially the one in JSFFI.c
23+
+ // that does GHC RTS initialization for any code that links
24+
+ // JSFFI.o. Luckily no Haskell computation or gc has taken
25+
+ // place yet, so we must set keepCAFs=1 right now! Otherwise,
26+
+ // any BCO created by later TH splice or ghci expression may
27+
+ // refer to any CAF that's not reachable from GC roots (here
28+
+ // our only entry point is defaultServer) and the CAF could
29+
+ // have been GC'ed! (#26106)
30+
+ //
31+
+ // We call it here instead of in RTS C code, since we only
32+
+ // want keepCAFs=1 for ghci, not user code.
33+
+ this.exportFuncs.setKeepCAFs();
34+
}
35+
init();
36+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
From cb60da245b2fea7a0c39af0e58f9ef89104a9255 Mon Sep 17 00:00:00 2001
2+
From: Cheng Shao <[email protected]>
3+
Date: Fri, 21 Feb 2025 20:30:31 +0000
4+
Subject: [PATCH] wasm: fix dyld for shared libraries created by llvm 20.x
5+
6+
This patch fixes wasm dyld script for shared libraries created by llvm
7+
20.x. The __wasm_apply_data_relocs function is now optional and may be
8+
omitted for shared libraries without any runtime relocatable data
9+
segments, so only call __wasm_apply_data_relocs when it's present.
10+
---
11+
utils/jsffi/dyld.mjs | 13 +++++++++----
12+
1 file changed, 9 insertions(+), 4 deletions(-)
13+
14+
diff --git a/utils/jsffi/dyld.mjs b/utils/jsffi/dyld.mjs
15+
index 3c1c2106557a..c6cfedbece4f 100755
16+
--- a/utils/jsffi/dyld.mjs
17+
+++ b/utils/jsffi/dyld.mjs
18+
@@ -796,12 +796,17 @@ class DyLD {
19+
20+
const init = () => {
21+
// See
22+
- // https://github.com/llvm/llvm-project/blob/llvmorg-19.1.1/lld/wasm/Writer.cpp#L1430,
23+
- // there's also __wasm_init_memory (not relevant yet, we don't
24+
+ // https://gitlab.haskell.org/haskell-wasm/llvm-project/-/blob/release/20.x/lld/wasm/Writer.cpp#L1450,
25+
+ // __wasm_apply_data_relocs is now optional so only call it if
26+
+ // it exists (we know for sure it exists for libc.so though).
27+
+ // There's also __wasm_init_memory (not relevant yet, we don't
28+
// use passive segments) & __wasm_apply_global_relocs but
29+
// those are included in the start function and should have
30+
- // been called upon instantiation.
31+
- instance.exports.__wasm_apply_data_relocs();
32+
+ // been called upon instantiation, see
33+
+ // Writer::createStartFunction().
34+
+ if (instance.exports.__wasm_apply_data_relocs) {
35+
+ instance.exports.__wasm_apply_data_relocs();
36+
+ }
37+
38+
instance.exports._initialize();
39+
};
40+
--
41+
GitLab

0 commit comments

Comments
 (0)