diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index 614de758045..0412429959c 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -689,7 +689,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do , ghcOptFPic = toFlag True , ghcOptHiSuffix = toFlag "dyn_hi" , ghcOptObjSuffix = toFlag "dyn_o" - , ghcOptExtra = hcSharedOptions GHC libBi + , ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi } profArgs = vanillaArgs @@ -701,13 +701,38 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do (withProfLibDetail lbi) , ghcOptHiSuffix = toFlag "p_hi" , ghcOptObjSuffix = toFlag "p_o" - , ghcOptExtra = hcProfOptions GHC libBi + , ghcOptExtra = hcOptions GHC libBi ++ hcProfOptions GHC libBi } +<<<<<<< HEAD ghcArgs | withVanillaLib lbi = vanillaArgs | withSharedLib lbi = sharedArgs | withProfLib lbi = profArgs | otherwise = error "libAbiHash: Can't find an enabled library way" +======= + profDynArgs = + vanillaArgs + `mappend` mempty + { ghcOptProfilingMode = toFlag True + , ghcOptProfilingAuto = + Internal.profDetailLevelFlag + True + (withProfLibDetail lbi) + , ghcOptDynLinkMode = toFlag GhcDynamicOnly + , ghcOptFPic = toFlag True + , ghcOptHiSuffix = toFlag "p_dyn_hi" + , ghcOptObjSuffix = toFlag "p_dyn_o" + , ghcOptExtra = hcOptions GHC libBi ++ hcProfSharedOptions GHC libBi + } + ghcArgs = + let (libWays, _, _) = buildWays lbi + in case libWays (componentIsIndefinite clbi) of + (ProfDynWay : _) -> profDynArgs + (ProfWay : _) -> profArgs + (StaticWay : _) -> vanillaArgs + (DynWay : _) -> sharedArgs + _ -> error "libAbiHash: Can't find an enabled library way" +>>>>>>> 9c775f2f6 (Always pass `ghc-options` (#8717)) (ghcProg, _) <- requireProgram verbosity ghcProgram (withPrograms lbi) diff --git a/Cabal/src/Distribution/Simple/GHCJS.hs b/Cabal/src/Distribution/Simple/GHCJS.hs index 4e14bc04d5d..681fbf7f023 100644 --- a/Cabal/src/Distribution/Simple/GHCJS.hs +++ b/Cabal/src/Distribution/Simple/GHCJS.hs @@ -569,7 +569,7 @@ buildOrReplLib mReplFlags verbosity numJobs _pkg_descr lbi lib clbi = do , ghcOptFPic = toFlag True , -- ghcOptHiSuffix = toFlag "dyn_hi", -- ghcOptObjSuffix = toFlag "dyn_o", - ghcOptExtra = hcSharedOptions GHC libBi + ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi , ghcOptHPCDir = hpcdir Hpc.Dyn } @@ -758,7 +758,7 @@ buildOrReplLib mReplFlags verbosity numJobs _pkg_descr lbi lib clbi = do , ghcOptDynLinkMode = toFlag GhcDynamicOnly , ghcOptInputFiles = toNubListR dynamicObjectFiles , ghcOptOutputFile = toFlag sharedLibFilePath - , ghcOptExtra = hcSharedOptions GHC libBi + , ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi , -- For dynamic libs, Mac OS/X needs to know the install location -- at build time. This only applies to GHC < 7.8 - see the -- discussion in #1660. @@ -1309,7 +1309,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do ghcOptFPic = toFlag True , ghcOptHiSuffix = toFlag "dyn_hi" , ghcOptObjSuffix = toFlag "dyn_o" - , ghcOptExtra = hcSharedOptions GHC bnfo + , ghcOptExtra = hcOptions GHC bnfo ++ hcSharedOptions GHC bnfo , ghcOptHPCDir = hpcdir Hpc.Dyn } dynTooOpts = @@ -1743,7 +1743,7 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do , ghcOptFPic = toFlag True , ghcOptHiSuffix = toFlag "js_dyn_hi" , ghcOptObjSuffix = toFlag "js_dyn_o" - , ghcOptExtra = hcSharedOptions GHC libBi + , ghcOptExtra = hcOptions GHC libBi ++ hcSharedOptions GHC libBi } profArgs = vanillaArgs diff --git a/changelog.d/pr-8717 b/changelog.d/pr-8717 new file mode 100644 index 00000000000..b0ac7e09388 --- /dev/null +++ b/changelog.d/pr-8717 @@ -0,0 +1,25 @@ +synopsis: Always pass `ghc-options` to GHC +packages: Cabal +prs: #8717 +issues: + +description: { + +Previously, options set in the package field `ghc-options` would not be passed +to GHC during the link phase for shared objects (where multiple `.o` or +`.dyn_o` files are merged into a single object file). This made it impossible +to use `ghc-options` to use a different linker by setting (for example) +`ghc-options: -optl-fuse-ld=mold -optlm-fuse-ld=mold`; the options would be +dropped in the link phase, falling back to the default linker. + +It was possible to work around this by duplicating the `ghc-options` to +`ghc-shared-options`, which _are_ passed in the shared link phase, but that had +the (undocumented and unfortunate) side-effect of disabling the GHC +`-dynamic-too` flag, effectively doubling compilation times when +`ghc-shared-options` are set. + +Now, `ghc-options` are combined with `ghc-shared-options` (to accurately +reflect the documentation on this feature) and the fact that +`ghc-shared-options` disables `-dynamic-too` is documented. + +} diff --git a/doc/cabal-package-description-file.rst b/doc/cabal-package-description-file.rst index 60902c36e21..32d701d4f76 100644 --- a/doc/cabal-package-description-file.rst +++ b/doc/cabal-package-description-file.rst @@ -1920,6 +1920,21 @@ system-dependent values for these fields. ones specified via :pkg-field:`ghc-options`, and are passed to GHC during both the compile and link phases. +<<<<<<< HEAD +======= +.. pkg-field:: ghc-prof-shared-options: token list + + Additional options for GHC when the package is built as shared profiling + library. The options specified via this field are combined with the + ones specified via :pkg-field:`ghc-options`, and are passed to GHC during + both the compile and link phases. + + Note that if any :pkg-field:`ghc-shared-options` are set, the + ``-dynamic-too` option will never be passed to GHC, leading to all modules + being compiled twice (once to generate the ``.o`` files and another to + generate the ``.dyn_o`` files). + +>>>>>>> 9c775f2f6 (Always pass `ghc-options` (#8717)) .. pkg-field:: ghcjs-options: token list Like :pkg-field:`ghc-options` but applies to GHCJS