-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lld doesn't work on NixOS #125321
Comments
related: (same error) |
cc @lqd (at least, I know they were driving the "use lld by default" effort a la rust-lang/compiler-team#510 ) presumably this was injected by #124129 |
I don't know NixOS, so I'm not going to be of much help. I believe it has issues with lld in general, for example NixOS/nixpkgs#24744 that could be related, or this could be a duplicate of that issue. Changes such as NixOS/nixpkgs#24744 (comment) could be needed to make both lld and rust-lld work there.
To see if we can rule out the first case, I'd like to know the contents of the directories we tell
If the contents of the directories match what we expect, I would guess the issue is more NixOS/nixpkgs#24744. |
It does: ls /home/notyou/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin
gcc-ld rust-lld
Don't know if that requirement is satisfied: ls /home/notyou/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld
ld64.lld ld.lld lld-link wasm-ld If this issue is nix-specific we should probably make it extra clear what the work-around is until the issue is resolved. I added this to my [target.x86_64-unknown-linux-gnu]
rustflags = ["-Zlinker-features=-lld"] # fix nightly bug |
The expected executables are there, the toolchain looks complete AFAICT. Again I don't know NixOs, but there are wasm and aarch64 targets that already use rust-lld by default, so I would expect these to fail there, regardless of #124129. Similarly, we now just do what users did to change the linker, with regular link args like The way to revert to the default linker like you did is indeed explicitly mentioned in the blog post announcing the change. It seems less like a nightly bug to me than a known nix-specific issue. |
How are you installing the nightly? It erroring out at that stage seems like it's not "fixing" the |
With rust-lang/rust#124129, x64 linux switches to use LLD by default, but this causes dependency issues on NixOS. Disable LLD for now. This is tracked by rust-lang/rust#125321.
If it's via nixpkgs-rustup, I assume this patch needs updating as it doesn't match these new file paths: https://github.com/NixOS/nixpkgs/blob/4cc02342ff90b8484f11e68bdac985837bb956f9/pkgs/development/tools/rust/rustup/0001-dynamically-patchelf-binaries.patch (but that will just get it to the same state as |
Nixpkgs issue: NixOS/nixpkgs#312661 |
Using rustup. |
Summarizing the discussion from this zulip thread. It's unfortunate but there's nothing we can really do on our side: NixOS' packaging needs to be updated for This issue is technically a duplicate of open issues in https://github.com/NixOS/nixpkgs/ but we won't close it yet for visibility, so that people can see this summary if they encounter the issue themselves. @DianQK mentions a possible temporary workaround by patching rustc's lld wrapper: Disabling |
@lqd , is there a way to override globally and tell cargo which After installing Creating a symlink helps: rm ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/ld.lld
ln -s $(which ld.lld) ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/ld.lld |
The symlink may be broken the next you time do a rustup update, but |
You can tell There's two useful debugging flags when testing this: first enable logging the linker command |
also $ readelf -p .comment target/debug/helloworld
String dump of section '.comment':
[ 0] Linker: LLD 18.1.6
[ 13] rustc version 1.80.0-nightly (84b40fc90 2024-05-27)
[ 48] GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 and to add a bit to Nemo's explanation, nightly has two things enabled on x64 linux:
|
As a note, the mentioned rust-overlay issue is fixed. rust-overlay now wraps the shipped |
@oxalica I have added |
Indeed it works for me. |
NixOS/nixpkgs#314268 is now available in |
Btw setting |
@spearman how are you passing the flag? Remember that rustdoc uses RUSTDOCFLAGS, not RUSTFLAGS. |
@DianQK can you please share an absolutely minimal recipe on how to use this? I would really interested in how to couple this with home-manager |
I think you can just check this: https://github.com/Nilstrieb/nixos/blob/d16cacb11f7f08d42bf5ed3ffcdc4d5ed9dccc6e/home-manager/common.nix#L12. Just change your channel to |
Although rustup on NixOS isn't very user-friendly, this issue has been resolved in version 24.05. We can close it now. |
Code
Compilation for the cargo hello-world template with the new nightly failed.
It compiles when I either switch to the stable toolchain,
or set the RUSTFLAGS="-Z linker-features=-lld" env variable
Version it worked on
It most recently worked on: nightly-2024-05-17
Version with regression
rustc --version --verbose
:Backtrace
Backtrace
The text was updated successfully, but these errors were encountered: