Cheng Shao pushed to branch wip/T26166 at Glasgow Haskell Compiler / GHC
Commits:
-
fb3efe76
by Cheng Shao at 2025-10-16T13:06:28+02:00
-
4e712580
by Cheng Shao at 2025-10-16T13:32:30+02:00
4 changed files:
- compiler/GHC/Linker/Static.hs
- libraries/ghc-internal/cbits/RtsIface.c
- rts/wasm/JSFFI.c
- utils/jsffi/dyld.mjs
Changes:
| ... | ... | @@ -250,13 +250,6 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do |
| 250 | 250 | ++ pkg_lib_path_opts
|
| 251 | 251 | ++ extraLinkObj
|
| 252 | 252 | ++ noteLinkObjs
|
| 253 | - -- See Note [RTS/ghc-internal interface]
|
|
| 254 | - -- (-u<sym> must come before -lghc-internal...!)
|
|
| 255 | - ++ (if ghcInternalUnitId `elem` map unitId pkgs
|
|
| 256 | - then [concat [ "-Wl,-u,"
|
|
| 257 | - , ['_' | platformLeadingUnderscore platform]
|
|
| 258 | - , "init_ghc_hs_iface" ]]
|
|
| 259 | - else [])
|
|
| 260 | 253 | ++ pkg_link_opts
|
| 261 | 254 | ++ pkg_framework_opts
|
| 262 | 255 | ++ (if platformOS platform == OSDarwin
|
| ... | ... | @@ -8,14 +8,6 @@ |
| 8 | 8 | |
| 9 | 9 | #include "Rts.h"
|
| 10 | 10 | |
| 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 | 11 | void init_ghc_hs_iface(void);
|
| 20 | 12 | |
| 21 | 13 | // Forward declarations
|
| ... | ... | @@ -68,7 +68,14 @@ static void __init_ghc_hs_iface_jsffi(void) { |
| 68 | 68 | // Therefore, on wasm32, we designate priority 101 to ctors generated
|
| 69 | 69 | // by the GHC codegen, and priority 102 to the initialization logic
|
| 70 | 70 | // here to ensure hs_init_ghc() sees everything it needs to see.
|
| 71 | -__attribute__((constructor(102))) static void __ghc_wasm_jsffi_init(void) {
|
|
| 71 | + |
|
| 72 | +#if defined(__PIC__)
|
|
| 73 | +__attribute__((export_name("__ghc_wasm_jsffi_init"))) void __ghc_wasm_jsffi_init(void);
|
|
| 74 | +#else
|
|
| 75 | +__attribute__((constructor(102))) static void __ghc_wasm_jsffi_init(void);
|
|
| 76 | +#endif
|
|
| 77 | + |
|
| 78 | +void __ghc_wasm_jsffi_init(void) {
|
|
| 72 | 79 | // If linking static code without -no-hs-main, then the driver
|
| 73 | 80 | // emitted main() is in charge of its own RTS initialization, so
|
| 74 | 81 | // skip.
|
| ... | ... | @@ -1076,37 +1076,20 @@ class DyLD { |
| 1076 | 1076 | continue;
|
| 1077 | 1077 | }
|
| 1078 | 1078 | |
| 1079 | - const init = () => {
|
|
| 1080 | - // See
|
|
| 1081 | - // https://gitlab.haskell.org/haskell-wasm/llvm-project/-/blob/release/20.x/lld/wasm/Writer.cpp#L1450,
|
|
| 1082 | - // __wasm_apply_data_relocs is now optional so only call it if
|
|
| 1083 | - // it exists (we know for sure it exists for libc.so though).
|
|
| 1084 | - // There's also __wasm_init_memory (not relevant yet, we don't
|
|
| 1085 | - // use passive segments) & __wasm_apply_global_relocs but
|
|
| 1086 | - // those are included in the start function and should have
|
|
| 1087 | - // been called upon instantiation, see
|
|
| 1088 | - // Writer::createStartFunction().
|
|
| 1089 | - if (instance.exports.__wasm_apply_data_relocs) {
|
|
| 1079 | + // See
|
|
| 1080 | + // https://gitlab.haskell.org/haskell-wasm/llvm-project/-/blob/release/21.x/lld/wasm/Writer.cpp#L1451,
|
|
| 1081 | + // __wasm_apply_data_relocs is now optional so only call it if
|
|
| 1082 | + // it exists (we know for sure it exists for libc.so though).
|
|
| 1083 | + // There's also __wasm_init_memory (not relevant yet, we don't
|
|
| 1084 | + // use passive segments) & __wasm_apply_global_relocs but
|
|
| 1085 | + // those are included in the start function and should have
|
|
| 1086 | + // been called upon instantiation, see
|
|
| 1087 | + // Writer::createStartFunction().
|
|
| 1088 | + if (instance.exports.__wasm_apply_data_relocs) {
|
|
| 1090 | 1089 | instance.exports.__wasm_apply_data_relocs();
|
| 1091 | - }
|
|
| 1092 | - |
|
| 1093 | - instance.exports._initialize();
|
|
| 1094 | - };
|
|
| 1095 | - |
|
| 1096 | - // rts init must be deferred until ghc-internal symbols are
|
|
| 1097 | - // exported. We hard code this hack for now.
|
|
| 1098 | - if (/libHSrts-\d+(\.\d+)*/i.test(soname)) {
|
|
| 1099 | - this.rts_init = init;
|
|
| 1100 | - continue;
|
|
| 1101 | 1090 | }
|
| 1102 | - if (/libHSghc-internal-\d+(\.\d+)*/i.test(soname)) {
|
|
| 1103 | - init();
|
|
| 1104 | - this.rts_init();
|
|
| 1105 | - delete this.rts_init;
|
|
| 1106 | 1091 | |
| 1107 | - continue;
|
|
| 1108 | - }
|
|
| 1109 | - init();
|
|
| 1092 | + instance.exports._initialize();
|
|
| 1110 | 1093 | }
|
| 1111 | 1094 | }
|
| 1112 | 1095 | |
| ... | ... | @@ -1158,6 +1141,7 @@ export async function main({ rpc, libdir, ghciSoPath, args }) { |
| 1158 | 1141 | writer.write(new Uint8Array(buf));
|
| 1159 | 1142 | };
|
| 1160 | 1143 | |
| 1144 | + dyld.exportFuncs.__ghc_wasm_jsffi_init();
|
|
| 1161 | 1145 | await dyld.exportFuncs.defaultServer(cb_sig, cb_recv, cb_send);
|
| 1162 | 1146 | } finally {
|
| 1163 | 1147 | rpc.close();
|