Adding LLD as a CMake linker option

Over the last couple days I have experimented with using LLD instead of gold as a linker on Linux. I have seen some significant speedups for clean builds and for rebuilds, and I think this would be a nice option to add to CMake; however, I’m not sure if there are any side effects of using a different linker. Would this be something that could be easily added like in this patch?

As an example of the speedups, here are some of my build times. I have a few options (like Cycles) disabled in my builds.

     | Clean Build | Rebuild
Gold |     17m 50s | 34s-35s
LLD  |     12m 33s | 14s-16s
1 Like

Adding this option seems reasonable to me, I’d even consider enabling it by default if it’s that much faster, just like we did we gold before.

LLD is supposed to be a drop-in replacement, but there can always be incompatibilities so it needs to be tested with a feature complete build.

@brecht I agree more testing would be good. I’ve been doing more tests over the last few days and it appears that at times LLD was actually slower than gold while linking, but it has always been faster at a rebuild (when most time is spent Linking CXX executable bin/blender). That last step is always at least twice as fast. I have a thought that it might be parts of extern that actually link slower with LLD, but I am not positive. I’ve only seen this occasional LLD slowdown with make though, not ninja.

Today I made two new build folders (one for gold and one for LLD) and did some tests. Here are my results:

     | New Build | Clean Rebuild | Rebuild
gold |   14m 16s |        1m 21s |     26s
LLD  |   13m 49s |           27s |     12s

New Build: first time building in that folder
Clean Rebuild: a build after running ninja clean
Rebuild: a build after modifying one file

Configuration: ninja, ccache, Debug build, and ASAN. Without Cycles, buildinfo, LIBMV_SCHUR_SPECIALIZATIONS.

So at least with ninja and ccache I am seeing some reliable benefits. I would love to see if anyone else sees a speedup. Perhaps this CMake option could be committed so it can be tested in various setups more easily, then made default if it truly is faster and compatible.

I did a few more tests with different configurations. Overall it appears LLD gives a benefit for debug builds, but I couldn’t get conclusive results for release builds. I’m done testing for now, so it would be great to test a complete build and hear from others too.

     | New Build | Rebuild
gold |   12m 42s |     25s
LLD  |   12m 23s |     12s
Developer build, no cycles, make

     | New Build | Clean Rebuild | Rebuild
gold |   14m 03s |           50s |     26s
LLD  |   12m 57s |           37s |     12s
Developer build, no cycles, ccache, make

     | New Build | Rebuild
gold |  10m 22s* |      5s
LLD  |  10m  7s* |      3s
Release, no cycles, make

*These times fluctuated and I couldn’t get a consistent result. Sometimes gold was faster than make.

Another thing to consider is that LLD is not the same on each distribution. Arch and Ubuntu 20.04 both have version 10.0.0 by default, but Mint has version 6.0.0 which does not work. More recent versions can be installed, but cannot be specified with -fuse-ld=lld. On Mint the only workaround I found was to install version 9.0.0 and make a symbolic link named ld.lld.

Just compared LLD 10.0.0 against GNU gold (GNU Binutils 2.34) 1.16.

  • LLD
    • ccache’d build:
    • linking blender after touching creator.c:
  • Binutils
    • ccache’d build:
    • linking blender after touching creator.c:

+1 to add this as an option, the patch you linked to looks good as-is.

(edit, committed)

1 Like