I have a program that links with the ghc package. On my local Fedora 43 install, linking takes about a minute to finish. However, linking on GitHub CI with Ubuntu is fast and takes only around one second. I would really like some advice on how to diagnose this problem.
My local set up:
Fedora Linux 43 (Workstation Edition)
GHC 9.10.2 installed from GHCup stable channel
cabal-install 3.14.2.0 (probably irrelevant)
GHCup 0.1.50.2 (probably irrelevant)
CPU: AMD Ryzen™ 7 4800HS with Radeon™ Graphics × 16
First thing to check is to see how much memory and swap you’re using. I have a project that takes about 10 minutes to compile if I allocate 16GB to my WSL environment and less than a minute when I increase that to 24GB purely because of swap disk/io
I would imagine the issue is that your system linker is ld.bfd, which is known to be very slow linking Haskell programs.
Until recently, the ecosystem was using primarily using ld.gold if it was available but now ghcup and (more recently - 9.14) default GHC installation don’t select gold since it is deprecated (see https://www.phoronix.com/news/GNU-Gold-Linker-Deprecated).
If you would prefer to use gold still then when you install using ghcup, then you can try to follow the advice on the ghcup website to use --enable-ld-override - User Guide - GHCup
I think this is indeed the problem. I never had gold installed, so the change in GHCup was not affecting me at all (in other words, I have been using ld.bfd from the very beginning, and only when linking ghc the linking speed starts to become a problem ). Since gold is deprecated and removed on Fedora, I tried switching to lld by adding the following lines to my global cabal configuration (~/.config/cabal/config):
I have one remaining question, though. What is the best way (in your opinion) to set lld as the default linker for GHC (or should I do it in the first place)?
Use global cabal configuration (as above): I am not sure if the above covers all cases.
Use LD and CC with GHCup: is it possible to configure these so that they are the default whenever I install a new version of GHC? (Also, I heard that I need another CONF_... variable to make sure GHC uses proper -fuse-ld=... flags, but I do not remember the details.)
Use --enable-ld-override in GHCup: since I do not have ld.gold installed, I think ld.lld will be preferred by GHC configure, and everything should be fine?
Use update-alternatives to link ld to lld: I am reluctant to do so, because I do not fully understand the consequences…
I eventually settled on setting --enable-ld-override for GHCup. AFAIK the only problem with this approach is that if I later remove lld, I will be left with a broken GHC installation. I do not intend to do so, and even if I do, the installation can be fixed easily by reinstalling GHC, so I think this is the simplest solution for me.