Cheng Shao pushed to branch wip/T26166 at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • libraries/ghc-internal/cbits/RtsIface.c
    ... ... @@ -8,7 +8,15 @@
    8 8
     
    
    9 9
     #include "Rts.h"
    
    10 10
     
    
    11
    -void init_ghc_hs_iface(void) __attribute__((constructor));
    
    11
    +#if defined(wasm32_HOST_ARCH)
    
    12
    +// See Note [JSFFI initialization], on wasm we must ensure this
    
    13
    +// constructor has the highest priority among all GHC related
    
    14
    +// constructors
    
    15
    +__attribute__((constructor(100)))
    
    16
    +#else
    
    17
    +__attribute__((constructor))
    
    18
    +#endif
    
    19
    +void init_ghc_hs_iface(void);
    
    12 20
     
    
    13 21
     // Forward declarations
    
    14 22
     #define CLOSURE(module, symbol) \
    

  • libraries/ghc-internal/include/RtsIfaceSymbols.h
    ... ... @@ -62,10 +62,6 @@ INFO_TBL(GHCziInternalziCString, unpackCStringzh_info)
    62 62
     INFO_TBL(GHCziInternalziCString, unpackCStringUtf8zh_info)
    
    63 63
     #if defined(wasm32_HOST_ARCH)
    
    64 64
     CLOSURE(GHCziInternalziWasmziPrimziImports, raiseJSException_closure)
    
    65
    -CLOSURE(GHCziInternalziWasmziPrim, JSVal_con_info)
    
    66
    -CLOSURE(GHCziInternalziWasmziPrim, threadDelay_closure)
    
    67
    -#else
    
    68
    -UNDEF_CLOSURE(GHCziInternalziWasmziPrimziImports, raiseJSException_closure)
    
    69
    -UNDEF_CLOSURE(GHCziInternalziWasmziPrim, JSVal_con_info)
    
    70
    -UNDEF_CLOSURE(GHCziInternalziWasmziPrim, threadDelay_closure)
    
    65
    +INFO_TBL(GHCziInternalziWasmziPrimziTypes, JSVal_con_info)
    
    66
    +CLOSURE(GHCziInternalziWasmziPrimziConcziInternal, threadDelay_closure)
    
    71 67
     #endif

  • rts/RtsStartup.c
    ... ... @@ -236,6 +236,8 @@ hs_init_with_rtsopts(int *argc, char **argv[])
    236 236
         hs_init_ghc(argc, argv, rts_opts);
    
    237 237
     }
    
    238 238
     
    
    239
    +void init_ghc_hs_iface(void);
    
    240
    +
    
    239 241
     void
    
    240 242
     hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
    
    241 243
     {
    
    ... ... @@ -263,10 +265,7 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
    263 265
     
    
    264 266
         setlocale(LC_CTYPE,"");
    
    265 267
     
    
    266
    -    if (ghc_hs_iface == NULL) {
    
    267
    -        errorBelch("hs_init_ghc: ghc_hs_iface is uninitialized");
    
    268
    -        stg_exit(1);
    
    269
    -    }
    
    268
    +    init_ghc_hs_iface();
    
    270 269
     
    
    271 270
         /* Initialise the stats department, phase 0 */
    
    272 271
         initStats0();
    

  • rts/include/rts/RtsToHsIface.h
    ... ... @@ -61,9 +61,11 @@ typedef struct {
    61 61
         StgClosure *unpackCStringzh_closure;  // GHC.Internal.CString.unpackCStringzh_closure
    
    62 62
         StgInfoTable *unpackCStringzh_info;  // GHC.Internal.CString.unpackCStringzh_info
    
    63 63
         StgInfoTable *unpackCStringUtf8zh_info;  // GHC.Internal.CString.unpackCStringUtf8zh_info
    
    64
    +#if defined(wasm32_HOST_ARCH)
    
    64 65
         StgClosure *raiseJSException_closure;  // GHC.Internal.Wasm.Prim.Imports.raiseJSException_closure
    
    65
    -    StgClosure *JSVal_con_info;  // GHC.Internal.Wasm.Prim.JSVal_con_info
    
    66
    -    StgClosure *threadDelay_closure;  // GHC.Internal.Wasm.Prim.threadDelay_closure
    
    66
    +    StgInfoTable *JSVal_con_info;  // GHC.Internal.Wasm.Prim.Types.JSVal_con_info
    
    67
    +    StgClosure *threadDelay_closure;  // GHC.Internal.Wasm.Prim.Conc.Internal.threadDelay_closure
    
    68
    +#endif
    
    67 69
     } HsIface;
    
    68 70
     
    
    69 71
     extern const HsIface *ghc_hs_iface;

  • rts/wasm/JSFFI.c
    ... ... @@ -11,8 +11,6 @@
    11 11
     
    
    12 12
     extern HsBool rts_JSFFI_flag;
    
    13 13
     extern HsStablePtr rts_threadDelay_impl;
    
    14
    -extern StgClosure ghczminternal_GHCziInternalziWasmziPrimziImports_raiseJSException_closure;
    
    15
    -extern StgClosure ghczminternal_GHCziInternalziWasmziPrimziConcziInternal_threadDelay_closure;
    
    16 14
     
    
    17 15
     __attribute__((__weak__))
    
    18 16
     int __main_argc_argv(int argc, char *argv[]);
    
    ... ... @@ -124,7 +122,6 @@ typedef __externref_t HsJSVal;
    124 122
     typedef StgInt JSValKey;
    
    125 123
     
    
    126 124
     extern const StgInfoTable stg_JSVAL_info;
    
    127
    -extern const StgInfoTable ghczminternal_GHCziInternalziWasmziPrimziTypes_JSVal_con_info;
    
    128 125
     
    
    129 126
     // See Note [JSVal representation for wasm] for detailed explanation.
    
    130 127