Mold linker not working properly with Rust

I am trying to use the mold linker with the Rust compiler, but I am having a hard time with it. I am trying this method specified in the mold repository README:

rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]

I added this to the .config/cargo.toml file, but it deosn't seem to work. When I set the mold path as /usr/bin/mold, I get errors saying that the linker was not found. When I set the path as mold, it compiles successfully. When running readelf -p .comment target/release/binary, I can see the mold comment there. But while compiling, I am not seeing any difference in the time spent on linking. Also, when monitoring my CPU I can see that only one core is used when linking. What is going wrong here?

EDIT: If it matters, I noticed the exact same behaviour when trying to use the lld linker.

EDIT2: Turns out, I'm a complete idiot. Mold is working as it should, what's taking the time is the fat LTO. After switching to thin LTO, the build time dropped from 2 minutes to 1 minute 15 seconds. Still, I'm not sure if I want to use thin LTO as it produces slightly bigger binaries and may not be as performant.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.