From cec1a8a3d6849815918ca565178661e79248617a Mon Sep 17 00:00:00 2001 From: Cheng Shao <terrorjack@type.dance> Date: Mon, 7 Oct 2024 21:01:15 +0000 Subject: [PATCH] driver: ensure static archives are picked when linking static .wasm modules This commit ensures static archives are picked when linking .wasm modules which are supposed to be fully static, even when ghc may be invoked with -dynamic, see added comment for explanation. (cherry picked from commit 47baa9044a786ab04b6b68cf008f1254471c3cc1) (cherry picked from commit 1638d829e8c4c34d1a430799ea6c1a762bad9b38) --- compiler/GHC/Linker/Static.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/GHC/Linker/Static.hs b/compiler/GHC/Linker/Static.hs index 909086466fa..bf9ecd08ac7 100644 --- a/compiler/GHC/Linker/Static.hs +++ b/compiler/GHC/Linker/Static.hs @@ -77,7 +77,17 @@ linkBinary' staticLink logger tmpfs dflags unit_env o_files dep_units = do arch_os = platformArchOS platform output_fn = exeFileName arch_os staticLink (outputFile_ dflags) namever = ghcNameVersion dflags - ways_ = ways dflags + -- For the wasm target, when ghc is invoked with -dynamic, + -- when linking the final .wasm binary we must still ensure + -- the static archives are selected. Otherwise wasm-ld would + -- fail to find and link the .so library dependencies. wasm-ld + -- can link PIC objects into static .wasm binaries fine, so we + -- only adjust the ways in the final linking step, and only + -- when linking .wasm binary (which is supposed to be fully + -- static), not when linking .so shared libraries. + ways_ + | ArchWasm32 <- platformArch platform = removeWay WayDyn $ targetWays_ dflags + | otherwise = ways dflags full_output_fn <- if isAbsolute output_fn then return output_fn -- GitLab