Using LLVM-LLD linker on Windows for faster linking

I want to switch to LLD since it's supposed to be faster:
https://www.reddit.com/r/rust/comments/e7120k/inside_rust_at_embark/f9vcqo6/
(I'm using rust-msvc on WIn10.)
So I installed llvm via "scoop install llvm" but when I run it, it says:

C:\Users\me\scoop\apps\llvm\current\bin\ld.lld.exe: supported targets: elf

Shouldn't it also support PE format? How can I get PE support in LLD?


Btw, why do they recommend setting CARGO_INCREMENTAL to 1, isn't it always enabled nowadays?

When I have this in my .cargo/config:

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

Linking fails with e.g.:

  = note: ld.lld: error: unknown argument '-fuse-ld=lld'
          ld.lld: error: target\debug\examples\foo.14gfm8v01jrpb9h3.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.152hunya2u14zs3j.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.16wtfld0tm4j8kul.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.19uicbouf0aodyys.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1auxzbcnjrawl49u.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1dam70r36p5pe9kk.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1kcmzgjzfojub285.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1kl7h1lde268xurn.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1m43c9cs3e1ijtw1.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1p9r11qtc9ldzzr4.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1q7131m7m7t535g8.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1qo9n44kmgcjvnui.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1r8tpj82p7f9hsnu.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1s8c1ps78pi4muyg.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1s9e79x86d2iso27.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1u2xdwgs0r2rx4lg.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1vnic966a1dm3xtf.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1wa58ys3l5kc8kzx.rcgu.o: unknown file type
          ld.lld: error: target\debug\examples\foo.1wtrfcipe2885nnk.rcgu.o: unknown file type
          ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

Ah, I had to write linker = "lld-link.exe" in my config, now it works..

Btw, any idea why they are disabling LTO in the above reddit post?
Wouldn't it be enough to just not enable it in a debug profile?

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.