rustlinkerlld

Does rust use lld linker as standard


I have started on the "zero to performance in rust" book. This discusses using the lld linker instead of the standard rust linker to speed up compile times. However, the book is now about a year old and it mentions that there is/was work in progress to make lld the standard linker in rust wherever possible.

Does anyone know the stage of this work? Is rust using the ldd linker as standard and if not is there still a significant difference in compile time when using it.


Solution

  • As of rust 1.70, lld is the default linker for {arm,thumb}v4t-none-eabi toolchains.

    If you want to use lld before 1.70 or for different toolchains where it is not the default, you can modify your .cargo/config.toml to set the linker rustc will use.

    [target.x86_64-pc-windows-msvc]
    rustflags = ["-C", "link-arg=-fuse-ld=lld"]
    
    [target.x86_64-pc-windows-gnu]
    rustflags = ["-C", "link-arg=-fuse-ld=lld"]
    
    [target.x86_64-unknown-linux-gnu]
    rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]