Skip to content

Commit 17bdcd1

Browse files
committed
wasm-cross (partial): arch(wasm32) shared-triple + RtsStartup wasm call guard
Two of the fixes #181 (feat/wasm-cross-ghcup) carries but the stable-ghc-9.14 / #188 base lacks, needed to build stage3-wasm32-unknown-wasi: * cabal.project.stage3: replace the stale `if os(wasi) { package * shared:True }` (which alone leaves GHC's wasm link pipeline inconsistent — fails at the ghc-internal link with [GHC-74335]) with #181's `if arch(wasm32)` triple (shared + executable-dynamic + rts +dynamic). * rts/RtsStartup.c: guard the promoteBootLibrariesToGlobal() *call site* with !defined(wasm32_HOST_ARCH) to match its definition (which is already wasm-excluded; it uses dladdr/dlopen). Without this the wasm rts fails to compile ("call to undeclared function 'promoteBootLibrariesToGlobal'"). NOTE: these are necessary but NOT sufficient. stage3-wasm still fails at the ghc-internal shared-lib link ([GHC-74335] "-dynamic ignored when linking binaries on WASM" -> mismatched interface profile tag) because the real fix is in the GHC COMPILER, on #181 but not here: - 4d84ace "compiler: per-target settings drive GHC Dynamic / Profiled" (Platform/Settings/Settings.IO/Driver.Session: targetIsDynamic etc.) - 7396909 "rts+compiler: wasm32 cross-target patches" (esp. compiler/GHC/Linker/Dynamic.hs — the wasm dynamic-link handling) Porting those is the #181 <-> stable-ghc-9.14 wasm integration, tracked separately. (7396909 also rewrites compiler/Setup.hs + ghc-boot/Setup.hs, which conflicts with the modern-pin VerbosityHandles restore here.)
1 parent 4f28184 commit 17bdcd1

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

cabal.project.stage3

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
-- Configuration common to all stages
22
import: cabal.project.common
33

4+
-- WASM target libraries are built shared so end-user TH/GHCi works at
5+
-- runtime via dyld.mjs (miso, jsaddle, aeson, …): the wasm libs then ship
6+
-- .dyn_hi + .so. Scoped to `arch(wasm32)` so it applies ONLY when cabal
7+
-- builds against the wasm32 --with-compiler — the native build-compiler
8+
-- packages (happy-lib, alex, Setup.hs) and the JS target are unaffected.
9+
--
10+
-- IMPORTANT: must be shared + executable-dynamic + `rts +dynamic` *together*.
11+
-- A `package * { shared: True }` alone (no executable-dynamic / rts +dynamic)
12+
-- under `if os(wasi)` leaves GHC's link pipeline inconsistent and fails at the
13+
-- ghc-internal link step ("[GHC-74335] -dynamic is ignored when linking
14+
-- binaries on WASM" → "mismatched interface file profile tag wanted \"\" got
15+
-- \"dyn\""). The full dynamic-everywhere triple is what makes the wasm link
16+
-- pipeline accept it. (Verified: this is the variant #181 ships green.)
17+
if arch(wasm32)
18+
package *
19+
shared: True
20+
executable-dynamic: True
21+
constraints:
22+
rts +dynamic
23+
424
-- Disable Hackage, we explicitly include the packages we need.
525
active-repositories: :none
626

@@ -173,13 +193,8 @@ package *
173193
package libffi-clib
174194
ghc-options: -no-rts
175195

176-
-- WASM/WASI-specific overrides:
177-
-- - shared: True is required for GHCi/TH via dyld.mjs
178-
-- - +use-system-libffi is already set unconditionally on package rts above,
179-
-- but we keep this block for clarity and future conditional changes.
180-
if os(wasi)
181-
package *
182-
shared: True
196+
-- WASM/WASI shared-library overrides live in the `if arch(wasm32)` block near
197+
-- the top of this file (shared + executable-dynamic + rts +dynamic, together).
183198

184199
package ghc
185200
flags: +build-tool-depends +internal-interpreter

rts/RtsStartup.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,12 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
424424

425425
init_ghc_hs_iface();
426426

427-
#if !defined(mingw32_HOST_OS) && defined(RTLD_NOLOAD)
427+
/* Must match the definition's #if at line 108: wasm32 is excluded there
428+
* (promoteBootLibrariesToGlobal uses dladdr/dlopen, unavailable on wasm),
429+
* but wasm DOES define RTLD_NOLOAD, so without the wasm32 exclusion here the
430+
* call fires against an undefined function ("call to undeclared function
431+
* 'promoteBootLibrariesToGlobal'"). */
432+
#if !defined(mingw32_HOST_OS) && !defined(wasm32_HOST_ARCH) && defined(RTLD_NOLOAD)
428433
/* Promote boot libraries to RTLD_GLOBAL for dynamic code loading.
429434
* See Note [Promoting Boot Libraries to RTLD_GLOBAL] */
430435
promoteBootLibrariesToGlobal();

0 commit comments

Comments
 (0)