Cheng Shao pushed to branch wip/T26166 at Glasgow Haskell Compiler / GHC Commits: e0ffb03a by Cheng Shao at 2025-10-13T18:54:49+02:00 WIP partial fixes for wasm - - - - - 5 changed files: - libraries/ghc-internal/cbits/RtsIface.c - libraries/ghc-internal/include/RtsIfaceSymbols.h - rts/RtsStartup.c - rts/include/rts/RtsToHsIface.h - rts/wasm/JSFFI.c Changes: ===================================== libraries/ghc-internal/cbits/RtsIface.c ===================================== @@ -8,7 +8,15 @@ #include "Rts.h" -void init_ghc_hs_iface(void) __attribute__((constructor)); +#if defined(wasm32_HOST_ARCH) +// See Note [JSFFI initialization], on wasm we must ensure this +// constructor has the highest priority among all GHC related +// constructors +__attribute__((constructor(100))) +#else +__attribute__((constructor)) +#endif +void init_ghc_hs_iface(void); // Forward declarations #define CLOSURE(module, symbol) \ ===================================== libraries/ghc-internal/include/RtsIfaceSymbols.h ===================================== @@ -62,10 +62,6 @@ INFO_TBL(GHCziInternalziCString, unpackCStringzh_info) INFO_TBL(GHCziInternalziCString, unpackCStringUtf8zh_info) #if defined(wasm32_HOST_ARCH) CLOSURE(GHCziInternalziWasmziPrimziImports, raiseJSException_closure) -CLOSURE(GHCziInternalziWasmziPrim, JSVal_con_info) -CLOSURE(GHCziInternalziWasmziPrim, threadDelay_closure) -#else -UNDEF_CLOSURE(GHCziInternalziWasmziPrimziImports, raiseJSException_closure) -UNDEF_CLOSURE(GHCziInternalziWasmziPrim, JSVal_con_info) -UNDEF_CLOSURE(GHCziInternalziWasmziPrim, threadDelay_closure) +INFO_TBL(GHCziInternalziWasmziPrimziTypes, JSVal_con_info) +CLOSURE(GHCziInternalziWasmziPrimziConcziInternal, threadDelay_closure) #endif ===================================== rts/RtsStartup.c ===================================== @@ -236,6 +236,8 @@ hs_init_with_rtsopts(int *argc, char **argv[]) hs_init_ghc(argc, argv, rts_opts); } +void init_ghc_hs_iface(void); + void hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config) { @@ -263,10 +265,7 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config) setlocale(LC_CTYPE,""); - if (ghc_hs_iface == NULL) { - errorBelch("hs_init_ghc: ghc_hs_iface is uninitialized"); - stg_exit(1); - } + init_ghc_hs_iface(); /* Initialise the stats department, phase 0 */ initStats0(); ===================================== rts/include/rts/RtsToHsIface.h ===================================== @@ -61,9 +61,11 @@ typedef struct { StgClosure *unpackCStringzh_closure; // GHC.Internal.CString.unpackCStringzh_closure StgInfoTable *unpackCStringzh_info; // GHC.Internal.CString.unpackCStringzh_info StgInfoTable *unpackCStringUtf8zh_info; // GHC.Internal.CString.unpackCStringUtf8zh_info +#if defined(wasm32_HOST_ARCH) StgClosure *raiseJSException_closure; // GHC.Internal.Wasm.Prim.Imports.raiseJSException_closure - StgClosure *JSVal_con_info; // GHC.Internal.Wasm.Prim.JSVal_con_info - StgClosure *threadDelay_closure; // GHC.Internal.Wasm.Prim.threadDelay_closure + StgInfoTable *JSVal_con_info; // GHC.Internal.Wasm.Prim.Types.JSVal_con_info + StgClosure *threadDelay_closure; // GHC.Internal.Wasm.Prim.Conc.Internal.threadDelay_closure +#endif } HsIface; extern const HsIface *ghc_hs_iface; ===================================== rts/wasm/JSFFI.c ===================================== @@ -11,8 +11,6 @@ extern HsBool rts_JSFFI_flag; extern HsStablePtr rts_threadDelay_impl; -extern StgClosure ghczminternal_GHCziInternalziWasmziPrimziImports_raiseJSException_closure; -extern StgClosure ghczminternal_GHCziInternalziWasmziPrimziConcziInternal_threadDelay_closure; __attribute__((__weak__)) int __main_argc_argv(int argc, char *argv[]); @@ -124,7 +122,6 @@ typedef __externref_t HsJSVal; typedef StgInt JSValKey; extern const StgInfoTable stg_JSVAL_info; -extern const StgInfoTable ghczminternal_GHCziInternalziWasmziPrimziTypes_JSVal_con_info; // See Note [JSVal representation for wasm] for detailed explanation. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e0ffb03a773415a286a7d0f583a130aa... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e0ffb03a773415a286a7d0f583a130aa... You're receiving this email because of your account on gitlab.haskell.org.