Commit c9444e4
committed
fix: promote ghc-internal to RTLD_GLOBAL to prevent duplicate loading
When ghc-iserv loads user code that depends on ghc-internal via dlopen,
the dynamic linker may load a second copy of libHSghc-internal.so if the
original was loaded with RTLD_LOCAL (which is required by Note [RTLD_LOCAL]
in rts/Linker.c for symbol override behavior).
This causes heap corruption because:
1. The first copy's init_ghc_hs_iface() initializes ghc_hs_iface in the RTS
2. User code compiled against the second copy creates closures with info
tables from the second copy
3. The GC uses ghc_hs_iface (pointing to first copy's info tables) to
validate closures
4. The mismatch causes "strange closure type" errors during GC
This fix uses dladdr to find the shared library containing init_ghc_hs_iface
(a known symbol from ghc-internal), then uses dlopen with RTLD_NOLOAD |
RTLD_GLOBAL to promote it to global scope before running any Haskell code.
See Note [Promoting ghc-internal to RTLD_GLOBAL] in iservmain.c.1 parent 1241092 commit c9444e4
2 files changed
+56
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
73 | 113 | | |
74 | 114 | | |
75 | 115 | | |
| |||
267 | 307 | | |
268 | 308 | | |
269 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
270 | 316 | | |
271 | 317 | | |
272 | 318 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
7 | 17 | | |
8 | 18 | | |
9 | 19 | | |
| |||
0 commit comments