[Git][ghc/ghc][master] driver: Link object files in a deterministic order
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: e8d1a0d6 by Bernhard M. Wiedemann at 2026-08-10T21:31:23-04:00 driver: Link object files in a deterministic order The object files handed to the linker come from the HomePackageTable, which is ordered by the order in which modules finished compiling. With -j1 that is the build plan order, with -jN it is whatever the scheduler produced, so the same sources can link to different (but equivalent) binaries. The order reaches the output: .text and .rodata contributions are concatenated in link order, so e.g. building the hdav executable of the DAV package twice, once with -j1 and once with -j4, yields two binaries that differ in ~100kB of section contents. Sort the home modules by module before collecting their linkables, guarded under `Opt_ObjectDeterminism` . Fixes #27612 Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de> - - - - - 2 changed files: - + changelog.d/link-deterministic-order - compiler/GHC/Driver/Pipeline.hs Changes: ===================================== changelog.d/link-deterministic-order ===================================== @@ -0,0 +1,5 @@ +section: compiler +synopsis: -fobject-determinism sorts the list of object files to be linked for reproducible builds +issues: #27612 +mrs: !16457 + ===================================== compiler/GHC/Driver/Pipeline.hs ===================================== @@ -410,8 +410,14 @@ link' hsc_env batch_attempt_linking mHscMessager hpt -- know which packages are actually needed at the runtime stage. pkg_deps <- map snd . Set.toList <$> hptCollectDependencies hpt - -- the linkables to link - home_mods <- hptCollectHomeModInfo hpt + -- the linkables to link; under -fobject-determinism sorted, because + -- the HPT holds modules in the order in which they finished compiling, + -- which varies with -j + let det_sort + | gopt Opt_ObjectDeterminism dflags + = sortWith (mi_module . hm_iface) + | otherwise = id + home_mods <- det_sort <$> hptCollectHomeModInfo hpt let home_modules = map (mi_module . hm_iface) home_mods debugTraceMsg logger 3 (text "link: hmi ..." $$ vcat (map ppr home_modules)) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e8d1a0d68067ba344fdff816f6b84f01... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e8d1a0d68067ba344fdff816f6b84f01... 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)