From 410c76eea7370f2d1143cf79aa524fcdec184f89 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sat, 5 Feb 2022 15:27:20 -0500 Subject: Use static archives as an alternative to object merging Unfortunately, `lld`'s COFF backend does not currently support object merging. With ld.bfd having broken support for high image-load base addresses, it's necessary to find an alternative. Here I introduce support in the driver for generating static archives, which we use on Windows instead of object merging. Closes #21068. --- compiler/GHC/Driver/Pipeline/Execute.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'compiler/GHC/Driver/Pipeline/Execute.hs') diff --git a/compiler/GHC/Driver/Pipeline/Execute.hs b/compiler/GHC/Driver/Pipeline/Execute.hs index 909102b573..55a1573d92 100644 --- a/compiler/GHC/Driver/Pipeline/Execute.hs +++ b/compiler/GHC/Driver/Pipeline/Execute.hs @@ -130,7 +130,7 @@ runPhase (T_Cmm pipe_env hsc_env input_fn) = do output_fn <- phaseOutputFilenameNew next_phase pipe_env hsc_env Nothing mstub <- hscCompileCmmFile hsc_env input_fn output_fn stub_o <- mapM (compileStub hsc_env) mstub - let foreign_os = (maybeToList stub_o) + let foreign_os = maybeToList stub_o return (foreign_os, output_fn) runPhase (T_Cc phase pipe_env hsc_env input_fn) = runCcPhase phase pipe_env hsc_env input_fn @@ -1117,7 +1117,8 @@ via gcc. -} joinObjectFiles :: HscEnv -> [FilePath] -> FilePath -> IO () -joinObjectFiles hsc_env o_files output_fn = do +joinObjectFiles hsc_env o_files output_fn + | 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) ( @@ -1147,7 +1148,12 @@ joinObjectFiles hsc_env o_files output_fn = do GHC.SysTools.FileOption "" filelist] else ld_r (map (GHC.SysTools.FileOption "") o_files) + + | otherwise = do + withAtomicRename output_fn $ \tmp_ar -> + liftIO $ runAr logger dflags Nothing $ map Option $ ["rc", tmp_ar] ++ o_files where + can_merge_objs = False -- XXX dflags = hsc_dflags hsc_env tmpfs = hsc_tmpfs hsc_env logger = hsc_logger hsc_env -- cgit v1.2.1