Enabling rust-lld for aarch64-unknown-linux-gnu

Hello,

I've been very excited with the latest rust-lld faster linking times promise in nightly so I gave it a go and indeed it lived up to my expectations :upside_down_face: ! Hats off to everyone involved :tophat:

For my x86 targets, other than using the nightly toolchain I didn't do anything specific.

I was wondering if there's a way to test rust-lld on aarch64 as well. I wasn't able to pull it off using -C linker=rust-lld, I get the following errors:

  = note: rust-lld: error: unable to find library -lgcc_s
          rust-lld: error: unable to find library -lutil
          rust-lld: error: unable to find library -lrt
          rust-lld: error: unable to find library -lpthread
          rust-lld: error: unable to find library -lm
          rust-lld: error: unable to find library -ldl
          rust-lld: error: unable to find library -lc

I was wondering what I'm doing here.

Thanks a lot!

Directly using lld as linker does not work on any UNIX target. On UNIX you are expected to invoke gcc or clang and then gcc/clang will invoke the linker and pass all arguments necessary for producing a valid binary for the target like the linker search path.

You have to use -Zlinker-features=+lld (or if you are on stable, install lld using your package manager and use -Clink-arg=-fuse-ld=lld) to make rustc tell gcc/clang to invoke lld as linker in the place of whatever default there is.

But wouldn't that just use the regular lld?

I'm interested in the rust-lld with the link-time optimization - just not sure which parameters I need to provide for it to properly work or what x86 nightly does now by default.

Yes

x86 nightly uses -Zlinker-features=+lld by default.

If you are doing regular LTO, the linker is not involved at all in Rust, so using the system lld is completely fine. If you use -Clinker-plugin-lto for cross-language LTO you can could use the default linker (for which rustc ships with a linker plugin) or use -Zlinker-features=+lld.

ok thanks, I now have a better grasp of what happens.

I do have another quirk though -

When I'm trying to compile with Zlinker-features=+lld on my machine (ubuntu 22.04.01 aarch64) - everything works fine with.

Trying to compile on an official docker image though (rust:1.79) yields an error:

error: linking with `cc` failed: exit status: 1
...
...
  = note: collect2: fatal error: cannot find 'ld'
          compilation terminated.
          

error: could not compile `proc-macro2` (build script) due to 1 previous error

this happens for libc crate as well.

Not sure why my local setup actually works while the official docker image doesn't - if you have any idea, I'd love to hear.

Thanks for all the help again, I appreciate it!

EDIT: turns out apt install lld makes it work but that left me befuddled - shouldn't the built-in rust-lld be used to link? or is it doing some sort of mix-n-match for certain crates?

Thanks!

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.