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

**URL:** <https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243>\
**Category:** uncategorized\
**Created:** [June 20, 2024, 6:15pm UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243 "2024-06-20T18:15:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![echelonh](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@echelonh](https://users.rust-lang.org/u/echelonh)\
**Post date:** [June 20, 2024, 6:15pm UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/1 "2024-06-20T18:15:48Z")

</div>

Hello,

I've been very excited with the latest `rust-lld` [faster linking times](https://blog.rust-lang.org/2024/05/17/enabling-rust-lld-on-linux.html) promise in nightly so I gave it a go and indeed it lived up to my expectations 🙃 ! Hats off to everyone involved 🎩

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:

```rust
  = 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!

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [June 20, 2024, 6:43pm UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/2 "2024-06-20T18:43:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![echelonh](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@echelonh](https://users.rust-lang.org/u/echelonh)\
**Post date:** [June 23, 2024, 6:40am UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/3 "2024-06-23T06:40:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [June 23, 2024, 9:41am UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/4 "2024-06-23T09:41:53Z")

</div>

> [@echelonh](#):
>
> But wouldn't that just use the regular `lld`?

Yes

> [@echelonh](#):
>
> just not sure which parameters I need to provide for it to properly work or what x86 nightly does now by default.

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

> [@echelonh](#):
>
> I'm interested in the `rust-lld` with the link-time optimization

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`.

---

<div class="post-metadata">

**Author:** ![echelonh](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@echelonh](https://users.rust-lang.org/u/echelonh)\
**Post date:** [June 23, 2024, 7:21pm UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/5 "2024-06-23T19:21:18Z")

</div>

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:

```rust
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!

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [September 21, 2024, 7:21pm UTC](https://users.rust-lang.org/t/enabling-rust-lld-for-aarch64-unknown-linux-gnu/113243/6 "2024-09-21T19:21:22Z")

</div>

Closed on September 21, 2024, 7:21pm UTC

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.
