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 WIP: remove wasm dyld hack - - - - - 4e712580 by Cheng Shao at 2025-10-16T13:32:30+02:00 WIP: don't make init_ghc_hs_iface a constructor & remove driver hack - - - - - 4 changed files: - compiler/GHC/Linker/Static.hs - libraries/ghc-internal/cbits/RtsIface.c - rts/wasm/JSFFI.c - utils/jsffi/dyld.mjs Changes: ===================================== compiler/GHC/Linker/Static.hs ===================================== @@ -250,13 +250,6 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do ++ pkg_lib_path_opts ++ extraLinkObj ++ noteLinkObjs - -- See Note [RTS/ghc-internal interface] - -- (-u<sym> must come before -lghc-internal...!) - ++ (if ghcInternalUnitId `elem` map unitId pkgs - then [concat [ "-Wl,-u," - , ['_' | platformLeadingUnderscore platform] - , "init_ghc_hs_iface" ]] - else []) ++ pkg_link_opts ++ pkg_framework_opts ++ (if platformOS platform == OSDarwin ===================================== libraries/ghc-internal/cbits/RtsIface.c ===================================== @@ -8,14 +8,6 @@ #include "Rts.h" -#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 ===================================== rts/wasm/JSFFI.c ===================================== @@ -68,7 +68,14 @@ static void __init_ghc_hs_iface_jsffi(void) { // Therefore, on wasm32, we designate priority 101 to ctors generated // by the GHC codegen, and priority 102 to the initialization logic // here to ensure hs_init_ghc() sees everything it needs to see. -__attribute__((constructor(102))) static void __ghc_wasm_jsffi_init(void) { + +#if defined(__PIC__) +__attribute__((export_name("__ghc_wasm_jsffi_init"))) void __ghc_wasm_jsffi_init(void); +#else +__attribute__((constructor(102))) static void __ghc_wasm_jsffi_init(void); +#endif + +void __ghc_wasm_jsffi_init(void) { // If linking static code without -no-hs-main, then the driver // emitted main() is in charge of its own RTS initialization, so // skip. ===================================== utils/jsffi/dyld.mjs ===================================== @@ -1076,37 +1076,20 @@ class DyLD { continue; } - const init = () => { - // See - // https://gitlab.haskell.org/haskell-wasm/llvm-project/-/blob/release/20.x/lld..., - // __wasm_apply_data_relocs is now optional so only call it if - // it exists (we know for sure it exists for libc.so though). - // There's also __wasm_init_memory (not relevant yet, we don't - // use passive segments) & __wasm_apply_global_relocs but - // those are included in the start function and should have - // been called upon instantiation, see - // Writer::createStartFunction(). - if (instance.exports.__wasm_apply_data_relocs) { + // See + // https://gitlab.haskell.org/haskell-wasm/llvm-project/-/blob/release/21.x/lld..., + // __wasm_apply_data_relocs is now optional so only call it if + // it exists (we know for sure it exists for libc.so though). + // There's also __wasm_init_memory (not relevant yet, we don't + // use passive segments) & __wasm_apply_global_relocs but + // those are included in the start function and should have + // been called upon instantiation, see + // Writer::createStartFunction(). + if (instance.exports.__wasm_apply_data_relocs) { instance.exports.__wasm_apply_data_relocs(); - } - - instance.exports._initialize(); - }; - - // rts init must be deferred until ghc-internal symbols are - // exported. We hard code this hack for now. - if (/libHSrts-\d+(\.\d+)*/i.test(soname)) { - this.rts_init = init; - continue; } - if (/libHSghc-internal-\d+(\.\d+)*/i.test(soname)) { - init(); - this.rts_init(); - delete this.rts_init; - continue; - } - init(); + instance.exports._initialize(); } } @@ -1158,6 +1141,7 @@ export async function main({ rpc, libdir, ghciSoPath, args }) { writer.write(new Uint8Array(buf)); }; + dyld.exportFuncs.__ghc_wasm_jsffi_init(); await dyld.exportFuncs.defaultServer(cb_sig, cb_recv, cb_send); } finally { rpc.close(); View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8f1564dcba343fd33fe50980015de07... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/8f1564dcba343fd33fe50980015de07... You're receiving this email because of your account on gitlab.haskell.org.