Skip to content

Forward -B linker search path in thin/patch link args on Linux#5443

Merged
jkelleyrtp merged 1 commit intoDioxusLabs:mainfrom
Wilovy09:fix/lld_on_rust
Apr 3, 2026
Merged

Forward -B linker search path in thin/patch link args on Linux#5443
jkelleyrtp merged 1 commit intoDioxusLabs:mainfrom
Wilovy09:fix/lld_on_rust

Conversation

@Wilovy09
Copy link
Copy Markdown
Contributor

@Wilovy09 Wilovy09 commented Apr 3, 2026

Since Rust 1.86, the toolchain injects two flags when linking on Linux to use the bundled lld instead of the system ld:

  • B/path/to/rustup/.../gcc-ld — tells cc where to find linker programs
  • fuse-ld=lld — tells cc to select lld

The fat link captures the full set of args from the initial cargo build and replays them verbatim, so it already picked up both flags and worked correctly on systems without binutils installed.

The patch link (thin) builds its own arg list in thin_link_args. It forwarded -fuse-ld but not -B, so cc -fuse-ld=lld could not locate ld.lld from the Rust toolchain and fell back to the system ld, failing with:

collect2: fatal error: cannot find 'ld'

Fix: add -B to the pass-through filter so the patch linker invocation forwards the same gcc-ld search path that cargo injects.

Implementation notes - Rust RFC

On the x86_64-unknown-linux-gnu target, when using the default linker flavor (using cc as the linker driver) and linker features (to try using lld), rustc will try to use the self-contained linker by passing a -B /path/to/sysroot/ link argument to the driver to find rust-lld in the sysroot. For backwards-compatibility, and to limit name and PATH collisions, this is done using a shim executable (the lld-wrapper tool) that forwards execution to the rust-lld executable itself.

Thanks to:

  • @marc2332 , for testing on Ubuntu 24.04 with Rust 1.94
  • @SergioRibera , for testing on NixOS 26.03
  • @MarioYellowy , for testing on PopOS 24.04 with Rust 1.94.1
    I tested it on MacOS 23.3.1(a) with Rust 1.93

@Wilovy09 Wilovy09 requested a review from a team as a code owner April 3, 2026 00:08
@Wilovy09
Copy link
Copy Markdown
Contributor Author

Wilovy09 commented Apr 3, 2026

@jkelleyrtp formatted!

@jkelleyrtp
Copy link
Copy Markdown
Member

Thanks!!

@jkelleyrtp jkelleyrtp merged commit 291c110 into DioxusLabs:main Apr 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants