bazelbuild / bazelbuild/rules_rust

Linking errors with LTO on Ubuntu 24.04 and rules_rust 0.60.0

Open
#3,409 10 comments 0 reactions 0 assignees View on GitHub
needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

`.bazelrc`:

```
build --compilation_mode=opt
build --@rules_rust//rust/settings:lto=thin
build --@rules_rust//rust/settings:extra_rustc_flag=-Copt-level=3
build --@rules_rust//rust/settings:extra_rustc_flag=-Ccodegen-units=1
build --@rules_rust//rust/settings:extra_rustc_flag=-Cdebug-assertions=off
build --@rules_rust//rust/settings:extra_rustc_flag=-Coverflow-checks=off
build --@rules_rust//rust/settings:extra_rustc_flag=-Cdebuginfo=1
build --@rules_rust//rust/settings:extra_rustc_flag=-Cincremental=false
```

`MODULE.bazel`:

```
bazel_dep(name = "rules_rust", version = "0.60.0")

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2021",
versions = ["1.86.0"],
)
use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")
```

on an Ubuntu 24.04 machine with LLVM 18 and 19 installed yields this error:

```
-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-shared" "-fuse-ld=lld" "-B/usr/bin" "-Wl,-no-as-needed" "-Wl,-z,relro,-z,now" "-pass-exit-codes" "-Wl,--gc-sections" "-Wl,--push-state,-as-needed" "-lstdc++" "-Wl,--pop-state" "-Wl,--push-state,-as-needed" "-lm" "-Wl,--pop-state"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: ld.lld: error: /home/gh-runner/.cache/bazel/_bazel_gh-runner/58b7b47ee097fdc1b06b3e6b39197a42/execroot/_main/bazel-out/k8-opt/bin/external/rules_rust++crate+crates__syn-1.0.109/libsyn-912657071.rlib(syn-912657071.1khmagf21y6tm6h2dkwmm30ld.rcgu.o):
Invalid attribute group entry (Producer: 'LLVM19.1.7-rust-1.86.0-stable' Reader: 'LLVM 18.1.3')
collect2: error: ld returned 1 exit status
```

Trying to set it to rust-lld expressly for linux:

```
build:linux --@rules_rust//rust/settings:extra_rustc_flag=-Clinker=rust-lld
```

yields this error:

```
"--gc-sections" "-shared" "-z" "relro" "-z" "now" "-O1" "--strip-debug" "-shared" "-fuse-ld=lld" "-B/usr/bin" "-Wl,-no-as-needed" "-Wl,-z,relro,-z,now" "-pass-exit-codes" "-Wl,--gc-sections" "-Wl,--push-state,-as-needed" "-lstdc++" "-Wl,--pop-state" "-Wl,--push-state,-as-needed" "-lm" "-Wl,--pop-state"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: rust-lld: error: unknown argument '-fuse-ld=lld'
rust-lld: error: unknown argument '-B/usr/bin'
rust-lld: error: unknown argument '-Wl,-no-as-needed'
rust-lld: error: unknown argument '-Wl,-z,relro,-z,now'
rust-lld: error: unknown argument '-pass-exit-codes'
rust-lld: error: unknown argument '-Wl,--gc-sections'
rust-lld: error: unknown argument '-Wl,--push-state,-as-needed'
rust-lld: error: unknown argument '-Wl,--pop-state'
rust-lld: error: unknown argument '-Wl,--push-state,-as-needed'
rust-lld: error: unknown argument '-Wl,--pop-state'
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
rust-lld: error: unable to find library -lstdc++
rust-lld: error: unable to find library -lm
```

Then I tried:

```
build:linux --@rules_rust//rust/settings:experimental_use_cc_common_link=True
build:linux --@rules_rust//rust/settings:extra_rustc_flag=-Clink-arg=-fuse-ld=lld
```

which got me:

```
Invalid attribute group entry (Producer: 'LLVM19.1.7-rust-1.86.0-stable' Reader: 'LLVM 18.1.3')
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.