Is it possible to compile & link Clang/LLVM using the gold linker?
Asked Answered
J

1

6

I'm writing a custom pass for LLVM/Clang, and recompiling tends to take a while and use a lot of memory. I've heard that the gold linker (1) takes less time and (2) uses less memory than the standard ld linker.

Is there a way to pass flags into the LLVM/Clang build process and change to the gold linker? As per this answer, I've been attempting to use an override file, but I don't seem to be having a lot of success.

I'll also note that I'm compiling the latest Clang/LLVM build (4.0) using Clang 3.9; I don't mind switching back to GCC if necessary but would rather avoid it.

Jillion answered 10/11, 2016 at 20:32 Comment(3)
Just install the gold package and it will be used instead of ld.Potomac
You might want to consider lld instead of ld, it claims to be faster, too. Not sure how it performances compared to gold.Potomac
Possible duplicate of CMake: use a custom linkerPotomac
L
14

Post-4.0 (after commit rL292047), you should set LLVM_USE_LINKER to gold like so:

cmake ... -DLLVM_USE_LINKER=gold ...

Refer to http://llvm.org/docs/CMake.html#llvm-specific-variables


While you can still use gold, these days (October 2021) you should probably use lld if it's present in your host toolchain. If your host toolchain is a clang+llvm distribution from llvm.org, it probably will. If your host toolchain is from a linux distribution's package manager, it will likely be available but installed as a separate independent package.

cmake ... -DLLVM_ENABLE_LLD=ON ...
Liesa answered 20/1, 2017 at 20:20 Comment(1)
Unfortunately I was (and am) stuck with an earlier version of Clang, but this perfectly answers the question. Accepted!Jillion

© 2022 - 2024 — McMap. All rights reserved.