summaryrefslogtreecommitdiff
path: root/hadrian
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-12-07 11:04:59 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2023-01-04 11:58:42 +0000
commitfec6638e2468c78f136f2363d8b3239a9bfd4f91 (patch)
treede7978f28db584b51c7d3a0394314852a4bad4c9 /hadrian
parent15bee1239877a4629a245fe457f06e5f96668423 (diff)
downloadhaskell-fec6638e2468c78f136f2363d8b3239a9bfd4f91.tar.gz
hadrian: Add no_split_sections tranformer
This transformer reverts the effect of `split_sections`, which we intend to use for platforms which don't support split sections. In order to achieve this we have to modify the implemntation of the split_sections transformer to store whether we are enabling split_sections directly in the `Flavour` definition. This is because otherwise there's no convenient way to turn off split_sections due to having to pass additional linker scripts when merging objects.
Diffstat (limited to 'hadrian')
-rw-r--r--hadrian/doc/flavours.md4
-rw-r--r--hadrian/hadrian.cabal1
-rw-r--r--hadrian/src/Flavour.hs32
-rw-r--r--hadrian/src/Flavour/Type.hs2
-rw-r--r--hadrian/src/Settings/Builders/SplitSections.hs36
-rw-r--r--hadrian/src/Settings/Default.hs3
6 files changed, 53 insertions, 25 deletions
diff --git a/hadrian/doc/flavours.md b/hadrian/doc/flavours.md
index 9aeabcc49d..af94fde32f 100644
--- a/hadrian/doc/flavours.md
+++ b/hadrian/doc/flavours.md
@@ -217,6 +217,10 @@ The supported transformers are listed below:
library due to the long linking times that this causes).</td>
</tr>
<tr>
+ <td><code>no_split_sections</code></td>
+ <td>Disable section splitting for all libraries.</td>
+ </tr>
+ <tr>
<td><code>thread_sanitizer</code></td>
<td>Build the runtime system with ThreadSanitizer support</td>
</tr>
diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal
index b220f27462..0c1f3c63be 100644
--- a/hadrian/hadrian.cabal
+++ b/hadrian/hadrian.cabal
@@ -112,6 +112,7 @@ executable hadrian
, Settings.Builders.Ld
, Settings.Builders.Make
, Settings.Builders.MergeObjects
+ , Settings.Builders.SplitSections
, Settings.Builders.RunTest
, Settings.Builders.Win32Tarballs
, Settings.Builders.Xelatex
diff --git a/hadrian/src/Flavour.hs b/hadrian/src/Flavour.hs
index f1e4aba881..9f8bd1d955 100644
--- a/hadrian/src/Flavour.hs
+++ b/hadrian/src/Flavour.hs
@@ -5,7 +5,7 @@ module Flavour
-- * Flavour transformers
, flavourTransformers
, addArgs
- , splitSections, splitSectionsIf
+ , splitSections
, enableThreadSanitizer
, enableDebugInfo, enableTickyGhc
, viaLlvmBackend
@@ -37,7 +37,6 @@ import Text.Parsec.Char as P
import Control.Monad.Except
import UserSettings
import Oracles.Flag
-import Oracles.Setting
flavourTransformers :: Map String (Flavour -> Flavour)
@@ -46,6 +45,7 @@ flavourTransformers = M.fromList
, "debug_info" =: enableDebugInfo
, "ticky_ghc" =: enableTickyGhc
, "split_sections" =: splitSections
+ , "no_split_sections" =: noSplitSections
, "thread_sanitizer" =: enableThreadSanitizer
, "llvm" =: viaLlvmBackend
, "profiled_ghc" =: enableProfiledGhc
@@ -181,31 +181,13 @@ enableHaddock =
]
-- | Transform the input 'Flavour' so as to build with
--- @-split-sections@ whenever appropriate. You can
--- select which package gets built with split sections
--- by passing a suitable predicate. If the predicate holds
--- for a given package, then @split-sections@ is used when
--- building it. Note that this transformer doesn't do anything
+-- @-split-sections@ whenever appropriate.
+-- Note that this transformer doesn't do anything
-- on darwin because on darwin platforms we always enable subsections
-- via symbols.
-splitSectionsIf :: (Package -> Bool) -> Flavour -> Flavour
-splitSectionsIf pkgPredicate = addArgs $ do
- pkg <- getPackage
- osx <- expr isOsxTarget
- not osx ? -- osx doesn't support split sections
- pkgPredicate pkg ? mconcat -- Only apply to these packages
- [ builder (Ghc CompileHs) ? arg "-split-sections"
- , builder MergeObjects ? ifM (expr isWinTarget)
- (pure ["-t", "driver/utils/merge_sections_pe.ld"])
- (pure ["-t", "driver/utils/merge_sections.ld"])
- ]
-
--- | Like 'splitSectionsIf', but with a fixed predicate: use
--- split sections for all packages but the GHC library.
-splitSections :: Flavour -> Flavour
-splitSections = splitSectionsIf (/=ghc)
--- Disable section splitting for the GHC library. It takes too long and
--- there is little benefit.
+splitSections, noSplitSections :: Flavour -> Flavour
+splitSections f = f { ghcSplitSections = True }
+noSplitSections f = f { ghcSplitSections = False }
-- | Build GHC and libraries with ThreadSanitizer support. You likely want to
-- configure with @--disable-large-address-space@ when using this.
diff --git a/hadrian/src/Flavour/Type.hs b/hadrian/src/Flavour/Type.hs
index 60021268fa..da236cbba3 100644
--- a/hadrian/src/Flavour/Type.hs
+++ b/hadrian/src/Flavour/Type.hs
@@ -43,6 +43,8 @@ data Flavour = Flavour {
-- | Build the GHC executable against the threaded runtime system.
ghcThreaded :: Stage -- ^ stage of the /built/ compiler
-> Bool,
+
+ ghcSplitSections :: Bool, -- ^ Whether to enable split sections
-- | Whether to build docs and which ones
-- (haddocks, user manual, haddock manual)
ghcDocs :: Action DocTargets }
diff --git a/hadrian/src/Settings/Builders/SplitSections.hs b/hadrian/src/Settings/Builders/SplitSections.hs
new file mode 100644
index 0000000000..215d164b55
--- /dev/null
+++ b/hadrian/src/Settings/Builders/SplitSections.hs
@@ -0,0 +1,36 @@
+-- | Settings required when split-sections is enabled.
+module Settings.Builders.SplitSections where
+
+import Expression
+import Packages
+import Settings
+import Flavour.Type
+
+import Oracles.Setting
+
+-- | Does it make sense to enable or disable split sections?
+splitSectionsArgs :: Args
+splitSectionsArgs = do
+ pkg <- getPackage
+ osx <- expr isOsxTarget
+ notSt0 <- notStage0
+ flav <- expr flavour
+ if ( ghcSplitSections flav
+ -- Flavour enables split-sections
+ && not osx
+ -- OS X doesn't support split sections
+ && notSt0
+ -- Disable for stage 0 because we aren't going to ship
+ -- the resulting binaries and consequently there is no
+ -- reason to minimize size.
+ && (pkg /= ghc)
+ -- Disable section splitting for the GHC library.
+ -- It takes too long and there is little benefit.
+ ) then
+ ( mconcat
+ [ builder (Ghc CompileHs) ? arg "-fsplit-sections"
+ , builder MergeObjects ? ifM (expr isWinTarget)
+ (pure ["-t", "driver/utils/merge_sections_pe.ld"])
+ (pure ["-t", "driver/utils/merge_sections.ld"])
+ ]
+ ) else mempty
diff --git a/hadrian/src/Settings/Default.hs b/hadrian/src/Settings/Default.hs
index 312747141b..5df34a18c4 100644
--- a/hadrian/src/Settings/Default.hs
+++ b/hadrian/src/Settings/Default.hs
@@ -41,6 +41,7 @@ import Settings.Builders.Ar
import Settings.Builders.Ld
import Settings.Builders.Make
import Settings.Builders.MergeObjects
+import Settings.Builders.SplitSections
import Settings.Builders.RunTest
import Settings.Builders.Xelatex
import Settings.Packages
@@ -243,6 +244,7 @@ defaultFlavour = Flavour
, ghcDebugged = const False
, ghcThreaded = const True
, ghcDebugAssertions = const False
+ , ghcSplitSections = False
, ghcDocs = cmdDocsArgs }
-- | Default logic for determining whether to build
@@ -279,6 +281,7 @@ defaultBuilderArgs = mconcat
, validateBuilderArgs
, xelatexBuilderArgs
, win32TarballsArgs
+ , splitSectionsArgs
-- Generic builders from the Hadrian library:
, builder (Sphinx HtmlMode ) ? Hadrian.Builder.Sphinx.args HtmlMode
, builder (Sphinx LatexMode) ? Hadrian.Builder.Sphinx.args LatexMode