Use the `mold` linker instead of `ld` or `lld`
mold is a faster linker that benefits from parallelization. It should be easy enough to use as a drop-in replacement, there are even Rust-specific instructions:
If using Rust, create a .cargo/config.toml in your project directory with the following:
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]
Other relevant details here: https://stackoverflow.com/questions/67511990/how-to-use-the-mold-linker-with-cargo
Possible problem here:
- gcc can use mold via
-fuse-ld=mold - clang can use mold via
--ld-path=$(which mold)
However mold can work for both if it is used like so:
mold -run cargo build
But then, it becomes harder to support both mold and another linker.
Hmm I see. I haven't toyed with using mold yet but once I get around to it I will comment back here with our options for supporting it. If we move to a cargo-driven build system (instead of make-based) then the mold -run ... option might work.