Theseus icon indicating copy to clipboard operation
Theseus copied to clipboard

Use the `mold` linker instead of `ld` or `lld`

Open kevinaboos opened this issue 2 years ago • 2 comments

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

kevinaboos avatar Jun 29 '22 17:06 kevinaboos

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.

NathanRoyer avatar Jul 18 '22 12:07 NathanRoyer

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.

kevinaboos avatar Jul 18 '22 17:07 kevinaboos