GHC 8.0.2: use -split-sections

-split-sections replaced -split-objs with following upsides:

1) -split-objs adds considerable overhead to compile time

2) combined with stripping, it causes issues when cross-compiling

For upstream see https://ghc.haskell.org/trac/ghc/ticket/8405

This is supported only for Linux/Windows using ld linker.

GHC master also turns on -split-sections by default.

Example using stack:

Without splitting

  $ du /nix/store/5paayhibayr73zqfaj458g4k4mv108jn-stack-1.3.2
  4       /nix/store/5paayhibayr73zqfaj458g4k4mv108jn-stack-1.3.2/share/bash-completion/completions
  4       /nix/store/5paayhibayr73zqfaj458g4k4mv108jn-stack-1.3.2/share/bash-completion
  4       /nix/store/5paayhibayr73zqfaj458g4k4mv108jn-stack-1.3.2/share
  23416   /nix/store/5paayhibayr73zqfaj458g4k4mv108jn-stack-1.3.2/bin
  23420   /nix/store/5paayhibayr73zqfaj458g4k4mv108jn-stack-1.3.2

With -split-objs

  $ du /nix/store/fypymm529adpx71gdzm0851xz42wdbz0-stack-1.3.2
  20632   /nix/store/fypymm529adpx71gdzm0851xz42wdbz0-stack-1.3.2/bin
  4 /nix/store/fypymm529adpx71gdzm0851xz42wdbz0-stack-1.3.2/share/bash-completion/completions
  4 /nix/store/fypymm529adpx71gdzm0851xz42wdbz0-stack-1.3.2/share/bash-completion
  4       /nix/store/fypymm529adpx71gdzm0851xz42wdbz0-stack-1.3.2/share
  20636   /nix/store/fypymm529adpx71gdzm0851xz42wdbz0-stack-1.3.2

With -split-sections

  $ du /nix/store/40l6krinx1zx41lr87c4m12hxj4ldf3x-stack-1.3.2
  4       /nix/store/40l6krinx1zx41lr87c4m12hxj4ldf3x-stack-1.3.2/share/bash-completion/completions
  4       /nix/store/40l6krinx1zx41lr87c4m12hxj4ldf3x-stack-1.3.2/share/bash-completion
  4       /nix/store/40l6krinx1zx41lr87c4m12hxj4ldf3x-stack-1.3.2/share
  20672   /nix/store/40l6krinx1zx41lr87c4m12hxj4ldf3x-stack-1.3.2/bin
  20676   /nix/store/40l6krinx1zx41lr87c4m12hxj4ldf3x-stack-1.3.2

Note: you currently need following overrides to build stack on 802:

   vector-algorithms = dontCheck super.vector-algorithms;
   path-io = doJailbreak super.path-io;
   stack = doJailbreak super.stack;

Note: Should also work on GHC 8.0.1, but I'm being careful here.
      We could backport later on.
This commit is contained in:
Domen Kožar 2017-01-02 17:19:28 +01:00
parent 83865b2c6c
commit f031f3105a
No known key found for this signature in database
GPG Key ID: C2FFBCAFD2C24246
2 changed files with 9 additions and 4 deletions

View File

@ -20,7 +20,8 @@
# TODO enable shared libs for cross-compiling
, enableSharedExecutables ? !isCross && (((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version))
, enableSharedLibraries ? !isCross && (((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version))
, enableSplitObjs ? !stdenv.isDarwin # http://hackage.haskell.org/trac/ghc/ticket/4013
, enableSplitObjs ? null # OBSOLETE, use enableDeadCodeElimination
, enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin
, enableStaticLibraries ? true
, extraLibraries ? [], librarySystemDepends ? [], executableSystemDepends ? []
, homepage ? "http://hackage.haskell.org/package/${pname}"
@ -53,6 +54,8 @@
} @ args:
assert editedCabalFile != null -> revision != null;
# OBSOLETE, use enableDeadCodeElimination
assert enableSplitObjs == null;
let
@ -108,13 +111,15 @@ let
(optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names")
(optionalString enableParallelBuilding "--ghc-option=-j$NIX_BUILD_CORES")
(optionalString useCpphs "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp")
(enableFeature enableSplitObjs "split-objs")
(enableFeature (enableDeadCodeElimination && (stdenv.lib.versionAtLeast "8.0.1" ghc.version)) "split-objs")
(enableFeature enableLibraryProfiling "library-profiling")
(enableFeature enableExecutableProfiling (if versionOlder ghc.version "8" then "executable-profiling" else "profiling"))
(enableFeature enableSharedLibraries "shared")
(optionalString (isGhcjs || versionOlder "7" ghc.version) (enableFeature enableStaticLibraries "library-vanilla"))
(optionalString (isGhcjs || versionOlder "7.4" ghc.version) (enableFeature enableSharedExecutables "executable-dynamic"))
(optionalString (isGhcjs || versionOlder "7" ghc.version) (enableFeature doCheck "tests"))
] ++ optionals (enableDeadCodeElimination && (stdenv.lib.versionOlder "8.0.1" ghc.version)) [
"--ghc-option=-split-sections"
] ++ optionals isGhcjs [
"--with-hsc2hs=${nativeGhc}/bin/hsc2hs"
"--ghcjs"

View File

@ -50,8 +50,8 @@ rec {
enableSharedLibraries = drv: overrideCabal drv (drv: { enableSharedLibraries = true; });
disableSharedLibraries = drv: overrideCabal drv (drv: { enableSharedLibraries = false; });
enableSplitObjs = drv: overrideCabal drv (drv: { enableSplitObjs = true; });
disableSplitObjs = drv: overrideCabal drv (drv: { enableSplitObjs = false; });
enableDeadCodeElimination = drv: overrideCabal drv (drv: { enableDeadCodeElimination = true; });
disableDeadCodeElimination = drv: overrideCabal drv (drv: { enableDeadCodeElimination = false; });
enableStaticLibraries = drv: overrideCabal drv (drv: { enableStaticLibraries = true; });
disableStaticLibraries = drv: overrideCabal drv (drv: { enableStaticLibraries = false; });