From 631cefec222e2db951c58db0b15a8d80ef5549cb Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Thu, 2 May 2024 08:15:57 +0000 Subject: [PATCH] driver: always merge objects when possible This patch makes the driver always merge objects with `ld -r` when possible, and only fall back to calling `ar -L` when merge objects command is unavailable. This completely reverts !8887 and !12313, given more fixes in Cabal seems to be needed to avoid breaking certain configurations and the maintainence cost is exceeding the behefits in this case :/ --- compiler/GHC/Driver/Pipeline/Execute.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/compiler/GHC/Driver/Pipeline/Execute.hs b/compiler/GHC/Driver/Pipeline/Execute.hs index 908422f54785..338d5f26038c 100644 --- a/compiler/GHC/Driver/Pipeline/Execute.hs +++ b/compiler/GHC/Driver/Pipeline/Execute.hs @@ -1045,17 +1045,12 @@ However, `ld -r` is broken in some cases: * The LLD linker that we use on Windows does not support the `-r` flag needed to support object merging (see #21068). For this reason on Windows we do not support GHCi objects. - * `wasm-ld -r` is prohibitively slow, especially when handling large - input objects (e.g. profiled objects). In these cases, we bundle a module's own object file with its foreign stub's object file, instead of merging them. Consequently, we can end up producing `.o` files which are in fact static archives. This can only work if `ar -L` is supported, so the archive `.o` files can be -properly added to the final static library. We must also take care not -to produce archive `.dyn_o` when building dynamic objects, otherwise -we end up with broken `.so` files when GHC is built with `llvm-ar` -(#22210). +properly added to the final static library. Note that this has somewhat non-obvious consequences when producing initializers and finalizers. See Note [Initializers and finalizers in Cmm] @@ -1081,7 +1076,7 @@ via gcc. -- | See Note [Object merging]. joinObjectFiles :: HscEnv -> [FilePath] -> FilePath -> IO () joinObjectFiles hsc_env o_files output_fn - | can_merge_objs && (not dashLSupported || is_dyn) = do + | can_merge_objs = do let toolSettings' = toolSettings dflags ldIsGnuLd = toolSettings_ldIsGnuLd toolSettings' ld_r args = GHC.SysTools.runMergeObjects (hsc_logger hsc_env) (hsc_tmpfs hsc_env) (hsc_dflags hsc_env) ( @@ -1109,7 +1104,6 @@ joinObjectFiles hsc_env o_files output_fn withAtomicRename output_fn $ \tmp_ar -> liftIO $ runAr logger dflags Nothing $ map Option $ ["qc" ++ dashL, tmp_ar] ++ o_files where - is_dyn = ways dflags `hasWay` WayDyn dashLSupported = sArSupportsDashL (settings dflags) dashL = if dashLSupported then "L" else "" can_merge_objs = isJust (pgm_lm (hsc_dflags hsc_env)) -- GitLab