如何在 Haskell 中使用 GNU 黄金链接器而不是 ld 链接 [英] How to link with the GNU gold linker instead of ld in Haskell
问题描述
我的 Haskell 项目花费大量时间在 Linking dist/build/myapp/myapp ...
以及在执行 TemplateHaskell
代码时加载共享库.
My Haskell project spends lots of time in Linking dist/build/myapp/myapp ...
and also in loading shared libraries when executing TemplateHaskell
code.
我怀疑这是因为 ld
很慢.
I suspect this is because ld
is slow.
如何通过切换到 gold
链接器来缩短链接时间?
How can I improve link times by switching to the gold
linker?
推荐答案
使用 gold
链接速度提高 3 倍自 GHC 7.8 起,您可以区分 GHC 和 cabal(在运行时无需重新编译 GHC) 即可与 GNU gold 链接.
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.
你需要在你的 .cabal
文件中:
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
(请注意,您可能希望在命令行上将这些标志传递给 stack
/cabal
/Setup.hs
,而不是将它们硬编码到.cabal 文件,以免降低包的可移植性.)
(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.)
对我来说,它的速度要快 3.5 倍
,将项目的总链接时间从 150 秒缩短到 40 秒.
For me it's 3.5x
faster, bringing down the total link time of a project from 150 seconds to 40 seconds.
参见 https://github.com/nh2/link-with-lld-example 一个完整的例子;关键部分:
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
这篇关于如何在 Haskell 中使用 GNU 黄金链接器而不是 ld 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!