如何在Haskell中与GNU黄金链接器而不是ld链接 [英] How to link with the GNU gold linker instead of ld in Haskell
问题描述
我的Haskell项目花费了大量时间在链接dist / build / myapp / myapp ...
,并且在执行 TemplateHaskell时加载共享库
code。
我怀疑这是因为 ld
很慢。
如何通过切换至黄金
连结器来改善连结时间?
使用 gold链接3倍速度
由于GHC 7.8 ,你可以告诉GHC和cabal(在运行时无需重新编译GHC)链接使用GNU gold。
您需要在 .cabal
文件中:
库:
ghc -options:-optl-fuse-ld = gold
ld-options:-fuse-ld = gold
可执行文件myExecutable
ghc-options:-optl-fuse-ld = gold
ld-options:-fuse-ld = gold
(请注意,您可能希望将这些标志传递给 stack
/ cabal
/ Setup.hs
而不是硬编码.cabal文件,以减少软件包的可移植性。)
对我来说,它是 3.5x
更快,将项目的总链接时间从150秒缩短到40秒。
更新: code> lld
请参阅 https://github.com/nh2/link-with-lld-example 查看完整示例;关键部分:
图书馆
ghc-options:-pgmP铿锵声-pgmc铿锵声-pgma铿锵声-pgml clang-optl-fuse-ld = lld
ld-options:-fuse-ld = lld
可执行文件myExecutable
ghc-options: - pgmP clang-pgmc clang-pgma clang-pgml clang
ld-options:-fuse-ld = lld
比较我的项目的最终可执行链接时间的链接时间:
ld 124秒
金36秒
lld 11秒
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?
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
这篇关于如何在Haskell中与GNU黄金链接器而不是ld链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!