I think this is pretty new. When I run cargo build --release --target x86_64-unknown-linux-musl the binary gets built but I get
WARN rustc_codegen_ssa::back::link Linker does not support -static-pie command line option. Retrying with -static instead.
warning: the gold linker is deprecated and has known bugs with Rust
|
= help: consider using LLD or ld from GNU binutils instead
What do I have to do here?
Hm, playing around. Using Aurora Linux I have installed brew install lld
Finally created ./.cargo/config.toml with
[target.x86_64-unknown-linux-musl]
linker = "ld.lld"
Now the warning is gone.
unsure if relevant, but similar issue on the bazel build ruyst rules repo
opened 02:19AM - 09 Sep 25 UTC
needs-triage
With the exception of wasm, rules_rust currently always uses the linker specifie… d in the relevant cc_toolchain: https://github.com/bazelbuild/rules_rust/blob/6d532fd5e170ca5cfe2ab0acb83d67527bafc4e5/rust/private/rustc.bzl#L1053-L1063. However, it would be good to let users configure what linker to use for Rust:
* On Linux, rules_cc defaults to LLD, then gold, then the default ld (ld.bfd). If LLD is not installed globally, then it'll use gold, but gold is deprecated and [not appropriate](https://github.com/rust-lang/rust/issues/141748) for Rust.
* On several platforms, Rust comes bundled with [`rust-lld`](https://blog.rust-lang.org/2024/05/17/enabling-rust-lld-on-linux/). In fact, Rust 1.90.0 will make it so that it uses `rust-lld` [by default](https://blog.rust-lang.org/2025/09/01/rust-lld-on-1.90.0-stable/) on x86-64 Linux.
* LLD is [much faster](https://www.phoronix.com/news/LLD-Linker-Why-So-Fast) than both ld.bfd and gold.
It would be nice to be able to use rust-lld for linking, either through a `gcc` driver, or directly. (I.e., `-Clinker-flavor=`[`ld.lld`](https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor)/[`gnu-lld`](https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/codegen-options.html#linker-flavor) and [`gnu-lld-cc`](https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/codegen-options.html#linker-flavor).)
----
As breadcrumbs, I was able to get the equivalent of `linker-flavor=gnu-lld-cc` working locally by applying:
* https://github.com/bazelbuild/rules_rust/pull/3600
* <details><summary><s>A patch to expand <code>$(RUST_SYSROOT)</code> in <code>extra_exec_rustc_flags</code></s></summary>
```diff
diff -ur rules_rust/rust/private/rustc.bzl rules_rust-patched/rust/private/rustc.bzl
--- rules_rust/rust/private/rustc.bzl 2025-09-09 01:16:47.480776299 +0000
+++ rules_rust-patched/rust/private/rustc.bzl 2025-09-09 01:20:48.211779196 +0000
@@ -1099,10 +1099,12 @@
if crate_info.type in toolchain.extra_rustc_flags_for_crate_types.keys():
rustc_flags.add_all(toolchain.extra_rustc_flags_for_crate_types[crate_info.type], map_each = map_flag)
- if is_exec_configuration(ctx):
- rustc_flags.add_all(toolchain.extra_exec_rustc_flags, map_each = map_flag)
- else:
- rustc_flags.add_all(toolchain.extra_rustc_flags, map_each = map_flag)
+ for flag in (toolchain.extra_exec_rustc_flags if is_exec_configuration(ctx) else toolchain.extra_rustc_flags):
+ if map_flag:
+ flag = map_flag(flag)
+ if flag != None:
+ flag = flag.replace("$(RUST_SYSROOT)", toolchain.sysroot)
+ rustc_flags.add(flag)
# extra_rustc_flags apply to the target configuration, not the exec configuration.
if hasattr(ctx.attr, "_extra_rustc_flags") and not is_exec_configuration(ctx):
```
</details>
https://github.com/bazelbuild/rules_rust/pull/3640
* Finally, `extra_rustc_flags` to tell the GCC driver to use lld
```starlark
rust_register_toolchains(
versions = ["1.89.0"],
extra_rustc_flags = {
"x86_64-unknown-linux-gnu": [
"--codegen=link-arg=-B$(RUST_SYSROOT)/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld",
"--codegen=link-arg=-fuse-ld=lld",
],
},
)
```
With https://github.com/bazelbuild/rules_rust/pull/3601 applied, we would be able to also do the same with `extra_exec_rustc_flags`
On Linux, rules_cc defaults to LLD, then gold, then the default ld (ld.bfd). If LLD is not installed globally, then it'll use gold, but gold is deprecated and not appropriate for Rust.
I have put the config.toml file into ~/.cargo/ directory. Now the setting is available globally for my user.
Nevertheless, I wasn't satisfied and tried to understand better. Here is what I found.
Building with --target x86_64-unknown-linux-musl on Fedora/Aurora produces:
WARN rustc_codegen_ssa::back::link Linker does not support -static-pie command line option. Retrying with -static instead.
warning: the gold linker is deprecated and has known bugs with Rust
The warning doesn't appear in an Arch based distrobox
Running ld --version I get
Fedora/Aurora base system: GNU gold (version 2.45.1-4.fc43) 1.16
Arch based distrobox: GNU ld (GNU Binutils) 2.46
So my guess is that this is the root cause.