How to link with the GNU gold linker instead of ld in Haskell

前端 未结 1 1634
悲哀的现实
悲哀的现实 2020-12-24 06:03

My Haskell project spends lots of time in Linking dist/build/myapp/myapp ... and also in loading shared libraries when executing TemplateHaskell co

相关标签:
1条回答
  • 2020-12-24 06:23

    Link 3x faster with gold

    Since GHC 7.8, you can tell GHC and cabal (at run time without having to recompile GHC) to link with GNU gold.

    You need in your .cabal file:

    library:
      ghc-options: -optl-fuse-ld=gold
      ld-options:  -fuse-ld=gold
    
    executable myExecutable
      ghc-options: -optl-fuse-ld=gold
      ld-options:  -fuse-ld=gold
    

    (Note you might want to pass these flags to stack/cabal/Setup.hs on the command line instead of hardcoding them in the .cabal file in order to not reduce the portability of the package.)

    For me it's 3.5x faster, bringing down the total link time of a project from 150 seconds to 40 seconds.


    Update: Link 10x faster with lld

    See https://github.com/nh2/link-with-lld-example for a full example; key parts:

    library
      ghc-options: "-pgmP clang" "-pgmc clang" "-pgma clang" "-pgml clang" "-optl-fuse-ld=lld"
      ld-options:  -fuse-ld=lld
    
    executable myExecutable
      ghc-options: "-pgmP clang" "-pgmc clang" "-pgma clang" "-pgml clang"
      ld-options:  -fuse-ld=lld
    

    Comparison of link time for the final executable link times my project:

    ld   124 seconds
    gold  36 seconds
    lld   11 seconds
    
    0 讨论(0)
提交回复
热议问题