# \[hxcpp on Linux\] Tip: Replace ld linker with lld to seriously improve compilation time

**URL:** <https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134>\
**Category:** Haxe\
**Tags:** haxe-cpp\
**Created:** [November 8, 2019, 10:02am UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134 "2019-11-08T10:02:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emugel](https://community.haxe.org/user_avatar/community.haxe.org/emugel/32/909_2.png) [@emugel](https://community.haxe.org/u/emugel)\
**Post date:** [November 8, 2019, 10:02am UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134/1 "2019-11-08T10:02:43Z")

</div>

This more than doubled the speed of my builds for my average size project for hxcpp on Linux (with `-debug`). I post this for independant developers like me, because bigger teams with specialists surely are very far ahead in the game.

Observing my compilation times for some days, I remarked while `haxe` + `gcc` were taking a few seconds, the last stage -the linking-, was taking about 10 times that amount of time! Observing with something like `htop`, we can see `gcc` is using all the cores of the CPU, while `ld` only uses one.

`lld` is a drop-in replacement for `ld`. It is the LLVM project linker, it uses multiple cores and is very much faster (for some big projects in debug mode it is reported it links at 10 times the speed of `ld`, though 2 times the speed is a more prudent expectation).

Since it’s a drop-in for `ld`; this means it is perfectly compatible with it, option by option, and thus that it is usable by hxcpp.

The good thing is you don’t need to uninstall `ld`, you can simply install `lld` and put a symbolic link in a folder of your `$PATH` having a better priority to where `ld` actually sits (e.g. `/usr/local/bin` versus `/usr/bin`).

For example on Archlinux:

- `pacman -S lld`
- `cd /usr/local/bin; ln -s /usr/bin/lld ld`
- `haxe build.hxml --times`

Is enough. If at one point you don’t want `lld` anymore you can just remove the symlinks and it will use the classical `ld` from `gcc` suite.

(This will likely only help you if there is a disproportionate linking time as opposed to compilation time, i.e. compare the two first lines of `haxe build.hxml --times`, I don’t think this will be the case for all projects. The case where it would help most IMO is `-debug` + many libs).

[https://lld.llvm.org/](https://lld.llvm.org/)

---

<div class="post-metadata">

**Author:** ![davidbruce](https://community.haxe.org/user_avatar/community.haxe.org/davidbruce/32/555_2.png) [@davidbruce](https://community.haxe.org/u/davidbruce)\
**Post date:** [November 8, 2019, 9:34pm UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134/2 "2019-11-08T21:34:28Z")

</div>

Awesome find! How does it perform compared to gold? I remember using gold to speed up linking times when I wrote D code a couple years ago.

---

<div class="post-metadata">

**Author:** ![emugel](https://community.haxe.org/user_avatar/community.haxe.org/emugel/32/909_2.png) [@emugel](https://community.haxe.org/u/emugel)\
**Post date:** [November 9, 2019, 3:43am UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134/3 "2019-11-09T03:43:10Z")

</div>

Online tests and reviews tend to say `lld` almost consistently beat it.

I wouldn’t be surprised if it superceded `ld` in Linux distributions at some point (Edit: but that depends on the license I guess). I found some news like this one on March 2019:

> Nick Desaulniers of Google, one of the engineers there who has been part of the renewed effort to [build the Linux kernel with LLVM’s Clang compiler](https://www.phoronix.com/scan.php?page=news_item&px=Clang-Kernel-2018), upstreamed a new patch to fix an issue that held back using the LLVM linker in some configurations.
> 
> Besides Google’s interest in using Clang to build the Linux kernel, they’ve also been interested in the LLVM linker (and in fact [divesting from GNU’s Gold linker](https://www.phoronix.com/scan.php?page=news_item&px=GNU-Gold-Stagnate-F31)) due to the greater performance and LLD still being a drop-in replacement to the GNU linkers.

---

<div class="post-metadata">

**Author:** ![davidbruce](https://community.haxe.org/user_avatar/community.haxe.org/davidbruce/32/555_2.png) [@davidbruce](https://community.haxe.org/u/davidbruce)\
**Post date:** [November 9, 2019, 5:20am UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134/4 "2019-11-09T05:20:33Z")

</div>

Huh cool, I’ll give it a whirl. Thanks again for the find!

---

<div class="post-metadata">

**Author:** ![dazKind](https://community.haxe.org/user_avatar/community.haxe.org/dazkind/32/2578_2.png) [@dazKind](https://community.haxe.org/u/dazKind)\
**Post date:** [November 13, 2019, 12:43pm UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134/5 "2019-11-13T12:43:27Z")

</div>

Nice! Just tried it and it works like a charm! Thanks for the heads up!

---

<div class="post-metadata">

**Author:** ![YRTV](https://community.haxe.org/user_avatar/community.haxe.org/yrtv/32/1095_2.png) [@YRTV](https://community.haxe.org/u/YRTV)\
**Post date:** [November 24, 2019, 5:38pm UTC](https://community.haxe.org/t/hxcpp-on-linux-tip-replace-ld-linker-with-lld-to-seriously-improve-compilation-time/2134/6 "2019-11-24T17:38:57Z")

</div>

You do not need to simlink it for gcc 9+ (on debian longer it’s their patch) just use compiler flag `-fuse-ld=lld` .
