Simon Marlow pushed to branch wip/simonmar/rts-ld-options at Glasgow Haskell Compiler / GHC Commits: d5836dd8 by Simon Marlow at 2026-11-05T10:54:31+00:00 Move `-u init_ghc_hs_iface` from the compiler to rts.cabal Having special flags in `.cabal` files rather than built into the compiler is better. I ran into this when trying to build GHC with Buck2, which wants to do some linking by itself so would have to replicate the magic from the compiler - instead, moving the magic into `rts.cabal` keeps it in one place. But this changes the logic slightly, because previously the magic flag was added whenever `ghc-internal` is being linked, whereas with this change the magic flag is added whenever `rts` is linked. It seems to me the latter is more correct (and this is how it was done prior to #26166, which introduced the compiler magic). I hope this doesn't reintroduce the problem that #26166 was fixing, but it's not clear to me exactly what that problem was. There is and always has been a recursive dependency between `rts` and `ghc-internal`; the fix in #26166 only changed it to a single function symbol reference rather than dozens of data references. This fix doesn't change that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> - - - - - 3 changed files: - compiler/GHC/Linker/Executable.hs - rts/RtsToHsIface.c - rts/rts.cabal Changes: ===================================== compiler/GHC/Linker/Executable.hs ===================================== @@ -321,13 +321,6 @@ linkExecutable logger tmpfs opts 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 ===================================== rts/RtsToHsIface.c ===================================== @@ -38,8 +38,8 @@ * explicit. * * Note that the init_ghc_hs_iface symbol is explicitly included in the final - * binary via the linker flag `-uinit_ghc_hs_iface`, when an executable is - * linked against ghc-internal by GHC. + * binary via the linker flag `-uinit_ghc_hs_iface`, which we put + * in the rts package's ld-options. * * `-uinit_ghc_hs_iface` ensures that the `init_ghc_hs_iface` symbol is * included in the final link, even when we link against `ghc-internal.a` ===================================== rts/rts.cabal ===================================== @@ -351,6 +351,14 @@ library stg/Ticky.h stg/Types.h + -- The RTS calls init_ghc_hs_iface, which ghc-internal defines: see Note + -- [RTS/ghc-internal interface] in RtsToHsIface.c. What links the RTS + -- must take it from ghc-internal's archive. + if flag(leading-underscore) + ld-options: -Wl,-u,_init_ghc_hs_iface + else + ld-options: -Wl,-u,init_ghc_hs_iface + if os(osx) ld-options: "-Wl,-search_paths_first" if !arch(x86_64) && !arch(aarch64) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d5836dd89107508bfd5f9009a0a58301... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d5836dd89107508bfd5f9009a0a58301... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help