From f031f3105a814ec8e9c8d3930c7d3cdd9c3dc9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Mon, 2 Jan 2017 17:19:28 +0100 Subject: [PATCH] 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. --- pkgs/development/haskell-modules/generic-builder.nix | 9 +++++++-- pkgs/development/haskell-modules/lib.nix | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 7a421e4f7b68..09ab30bb1761 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -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" diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix index 246a9f305dba..f7c9811234ec 100644 --- a/pkgs/development/haskell-modules/lib.nix +++ b/pkgs/development/haskell-modules/lib.nix @@ -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; });