I'm using lld as my linker currently for Rust, but recently encountered the mold project, which is faster than lld. I'd like to try it for Rust compilation, but I'm not sure how to pass it in as my linker. In my .cargo/config file I've got:
[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C", "link-arg=-fuse-ld=lld",
]
But I can't just change that lld to mold, or provide the path to the mold executable. Is there a way to get gcc to accept a path to a linker?
Mold can now be used with Clang by simply adding this to
~/.cargo/config.tomlNote: Mold may be installed at
/usr/local/bin/moldif installed from source so the flags should berustflags = ["-C", "link-arg=--ld-path=/usr/local/bin/mold"]. Run$ which moldto double check where it's installedYou can check it's worked by running
readelf -p .comment target/<type>/<binary_name>