[Git][ghc/ghc][master] Link the on-demand iserv without --gc-sections
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: fbd49db2 by Sylvain Henry at 2026-11-17T09:27:09-05:00 Link the on-demand iserv without --gc-sections GHC links an iserv program each time a session needs the external interpreter. The link is static, against the ghci library and the boot libraries. Like all executable links, it passed -Wl,--gc-sections to a GNU linker. On libraries built with -split-sections (the release bindists), the section garbage collection of ld.bfd is the largest part of that link: with binutils 2.45, the link takes 3 times longer with --gc-sections than without. The program is temporary and its size is not important. Thus the iserv link does not use --gc-sections. Other executable links do not change. In CI, each ext-interp or ghci-ext test takes 12 to 18 times longer in the x86_64-linux-fedora43-release test job (split sections) than in the x86_64-linux-deb13-validate test job (no split sections) on the same runner, while a normal-way test takes the same time in both. This link is most of that difference. See Note [No --gc-sections for the on-demand iserv] in GHC.Runtime.Interpreter.C. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> - - - - - 3 changed files: - + changelog.d/iserv-no-gc-sections.md - compiler/GHC/Linker/Executable.hs - compiler/GHC/Runtime/Interpreter/C.hs Changes: ===================================== changelog.d/iserv-no-gc-sections.md ===================================== @@ -0,0 +1,11 @@ +section: ghci +synopsis: Link the on-demand external interpreter without ``--gc-sections`` +issues: #27228 +mrs: !16974 +description: { + GHC no longer links the ``iserv`` program with ``--gc-sections``. GHC + links this program each time it needs the external interpreter. On + libraries built with ``-split-sections``, such as the release binary + distributions, the section garbage collection of ``ld.bfd`` made each + ``-fexternal-interpreter`` compilation several seconds slower. +} ===================================== compiler/GHC/Linker/Executable.hs ===================================== @@ -60,6 +60,11 @@ data ExecutableLinkOpts = ExecutableLinkOpts , leUseXLinkerRPath :: !Bool , leSingleLibFolder :: !Bool , leWholeArchiveHsLibs :: !Bool + , leGcSections :: !Bool + -- ^ Let a GNU linker remove the sections that nothing references + -- (@--gc-sections@). + -- See Note [No --gc-sections for the on-demand iserv] in + -- GHC.Runtime.Interpreter.C. , leGenManifest :: !Bool , leRPath :: !Bool , leCompactUnwind :: !Bool @@ -99,6 +104,7 @@ initExecutableLinkOpts dflags blm = , leUseXLinkerRPath = useXLinkerRPath dflags os , leSingleLibFolder = gopt Opt_SingleLibFolder dflags , leWholeArchiveHsLibs = gopt Opt_WholeArchiveHsLibs dflags + , leGcSections = True , leGenManifest = gopt Opt_GenManifest dflags , leRPath = gopt Opt_RPath dflags , leCompactUnwind = gopt Opt_CompactUnwind dflags @@ -296,7 +302,8 @@ linkExecutable logger tmpfs opts unit_env o_files dep_units = do -- We should rather be asking does it support --gc-sections? ++ (if linkerIsGnuLd (leLinkerConfig opts) && - not (leWholeArchiveHsLibs opts) + not (leWholeArchiveHsLibs opts) && + leGcSections opts then ["-Wl,--gc-sections"] else []) ===================================== compiler/GHC/Runtime/Interpreter/C.hs ===================================== @@ -61,6 +61,9 @@ generateIservC dflags logger tmpfs opts unit_env = do -- must retain CAFs for running interpreted code. , leKeepCafs = True + -- See Note [No --gc-sections for the on-demand iserv] + , leGcSections = False + -- link with -threaded if target has threaded RTS , leWays = let ways = leWays opts @@ -90,3 +93,18 @@ generateIservC dflags logger tmpfs opts unit_env = do linkExecutable logger tmpfs opts' unit_env [] [ghci_unit_id] pure exe_file + +-- Note [No --gc-sections for the on-demand iserv] +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-- GHC links the iserv program each time a session needs the external +-- interpreter. The link is static, against the ghci library and all the +-- boot libraries. Executable links add -Wl,--gc-sections with a GNU +-- linker. On libraries built with -split-sections (the release +-- bindists), the section garbage collection of ld.bfd is the largest +-- part of that link: with binutils 2.45, the link takes 3 times longer +-- with --gc-sections than without. The program lives in a temporary +-- directory and its size is not important. Thus the iserv link does not +-- use --gc-sections. +-- +-- Against libraries without split sections (the validate bindists), the +-- flag makes no difference to the link time. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fbd49db2712ade5a3e7dbcbac9b35301... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fbd49db2712ade5a3e7dbcbac9b35301... 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
participants (1)
-
Marge Bot (@marge-bot)