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

匿名 (未验证) 提交于 2019-12-03 02:05:01

问题:

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

I suspect this is because ld is slow.

How can I improve link times by switching to the gold linker?

回答1:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!