You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LLD linker does not have required nixpkgs wrapper script and flags #24744
2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: haskellGeneral-purpose, statically typed, purely functional programming language6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related
# Second, for each directory in the library search path (-L...),
# First, find all -L... switches.
# Second, for each directory in the library search path (-L...),
# see if it contains a dynamic library used by a -l... flag. If
# so, add the directory to the rpath.
Reacted by Bas van Dijk, William Casarin, Dmitrii Kovanikov, Remy Goldschmidt, Domen Kožar, Orivej Desh, Fabian Beuke, Langston Barrett, Arne Keller, Matthew Planchard and 20 more
As part of my work this summer on speeding up Nix Haskell builds for Awake Networks, I'm interested in tackling this issue (and upstreaming a fix). Does it just amount to adding something similar to the code snippet below to pkgs/build-support/cc-wrapper/default.nix (around line 180)?
if [ -e ${binutils_bin}/bin/ld.gold ]; then
wrap ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/ld.gold
fi
or should I be modifying the lld package itself to use the ld-wrapper.sh script?
Also, if someone could cook up an example Nix expression that should build iff I have correctly wrapped lld, that would be quite useful in implementing a fix for this.
@taktoa I can't answer conclusively, but I suspect it won't be as trivial as using the exiting scripts.
The right approach is likely to first do a proper reads through all things nixpkgs does to ld or gold, and then check which of those have to be done to lld as well.
For example, I know that lld searches through some default paths. We probably want to patch them out, or pass flags so that it doesn't do that.
Indeed linking takes a hell lot of time, but buildTarget fix in Cabal master will help a lot, limiting what executables are built for the given package.
Assuming the relevant linker options have the same syntax, I'd expect that the same wrapping approach should work. The way cc-wrapper is written now, I'd suggest to first try adding an option that makes it include ld.lld. (And maybe an option to make it the default ld, though I don't know if that's the standard way to exchange linkers.)
I have now added the lldClang stdenv. We could expose this better as needed if people want lld to be installable. Otherwise, without anything actionable I think this can be closed?
for instance, you can run llvm linker:
with import <nixpkgs> { system = "x86_64-linux"; };
let stdenv' = overrideCC stdenv llvmPackages_8.lldClang;
in stdenv'.mkDerivation {
name = "test";
buildCommand = ''
cc ${./test.c} -o test
./test
'';
}
Otherwise, without anything actionable I think this can be closed?
@matthewbauer The actionable part from the issue description was:
Executables that it produces have entries in lld being not found (rpaths are missing).
But lld currently doesn't have such a wrapper [that fixes the rpaths].
Concretely, we want to be able to:
Use a nix-provided lld in nix-build and nix-shell to link executables, also on non-NixOS platforms like Ubuntu
nix-shell support means it should work without sandbox, without lld picking up some global paths that it has hardcoded; it should be patched or wrapped to not do that, like binutils ld is
Use lld for general nix builds of specific or all packages (lddClang sounds like it does exactly that)
If your lldClang env fixes all those points, then this can be closed; if it does not fix/wrap/patch lld so that the nix-shell-on-Ubuntu use case works, then we still have to do that.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
Search for maintainers and people that previously touched the related code and @ mention them in a comment.
# Define settings# Toolchain.gccVersion="13";gccPkg=pkgs."gcc${gccVersion}";llvmVersion="17";llvmPkgs=pkgs."llvmPackages_${llvmVersion}";clangStdEnv=pkgs.stdenvAdapters.overrideCCllvmPkgs.stdenv(llvmPkgs.clang.override{bintools=llvmPkgs.bintools;gccForLibs=gccPkg.cc;# This is the unwrapped gcc.});clangStdEnv.mkDerivation(...)
This issue causes .so not found of the executable built by rust-nightly using dynamic library. As rust-nightly changed the default linker from ld to lld . nix-community/fenix#191rust-lang/rust#124129
Any chance you have a sense of what the practical the implication of this is @PeterWang-dev ? Are newer versions of nightly rust using fenix just not usable because they won't link? Related: do you know if this also applies to oxalica's rust overlay?
Note: I'm interested, so I intend to try both toolchains and see if linking works when I have a few free minutes. I will update this post with the results
Any chance you have a sense of what the practical the implication of this is @PeterWang-dev ? Are newer versions of nightly rust using fenix just not usable because they won't link? Related: do you know if this also applies to oxalica's rust overlay?
Note: I'm interested, so I intend to try both toolchains and see if linking works when I have a few free minutes. I will update this post with the results
I didn't try oxalica's rust overlay. The newest fenix just not usable because it cannot get correct library path of dynamic library. It can compile, but just cannot run without specifying LD_LIBRARY_PATH
Related: do you know if this also applies to oxalica's rust overlay?
Can confirm that I've had this issue on oxalica's overlay. Using this rustflag solved it: -Zlinker-features=-lld.
It seems I only need to use this flag when specifying a target, but it should be mentioned that on the host target I'm setting the dynamic library searchpath through rpath with rustflags, instead of using LD_LIBRARY_PATH.
2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: haskellGeneral-purpose, statically typed, purely functional programming language6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related
Activity
domenkozar commentedon Apr 27, 2017
This would be a nice addition to speed up Haskell builds by reducing time in linking phase.
taktoa commentedon Jun 6, 2017
As part of my work this summer on speeding up Nix Haskell builds for Awake Networks, I'm interested in tackling this issue (and upstreaming a fix). Does it just amount to adding something similar to the code snippet below to
pkgs/build-support/cc-wrapper/default.nix(around line 180)?or should I be modifying the
lldpackage itself to use theld-wrapper.shscript?Also, if someone could cook up an example Nix expression that should build iff I have correctly wrapped
lld, that would be quite useful in implementing a fix for this.nh2 commentedon Jun 6, 2017
@taktoa I can't answer conclusively, but I suspect it won't be as trivial as using the exiting scripts.
The right approach is likely to first do a proper reads through all things nixpkgs does to
ldorgold, and then check which of those have to be done tolldas well.For example, I know that
lldsearches through some default paths. We probably want to patch them out, or pass flags so that it doesn't do that.domenkozar commentedon Jun 6, 2017
@taktoa we're interested in this project at https://github.com/input-output-hk as well - maybe we could have quick chat and join some forces :)
we invested a bit of time into parallel GC and general GHC option tuning for scaling the compilation into multiple cores: https://github.com/input-output-hk/iohk-nixops/pull/49/files
Indeed linking takes a hell lot of time, but
buildTargetfix in Cabal master will help a lot, limiting what executables are built for the given package.domenkozar commentedon Jun 6, 2017
@taktoa for this particular change, I'd talk to @vcunat or @wkennington
vcunat commentedon Jun 6, 2017
Assuming the relevant linker options have the same syntax, I'd expect that the same wrapping approach should work. The way cc-wrapper is written now, I'd suggest to first try adding an option that makes it include
ld.lld. (And maybe an option to make it the defaultld, though I don't know if that's the standard way to exchange linkers.)matthewbauer commentedon May 1, 2019
I have now added the
lldClangstdenv. We could expose this better as needed if people want lld to be installable. Otherwise, without anything actionable I think this can be closed?for instance, you can run llvm linker:
Also install lld using:
nh2 commentedon May 1, 2019
@matthewbauer The actionable part from the issue description was:
Concretely, we want to be able to:
lldinnix-buildandnix-shellto link executables, also on non-NixOS platforms like Ubuntunix-shellsupport means it should work without sandbox, withoutlldpicking up some global paths that it has hardcoded; it should be patched or wrapped to not do that, like binutilsldislddClangsounds like it does exactly that)If your
lldClangenv fixes all those points, then this can be closed; if it does not fix/wrap/patchlldso that the nix-shell-on-Ubuntu use case works, then we still have to do that.domenkozar commentedon Aug 8, 2019
Can't easily override stdenv in haskell #66267, but could be checked by overriding it in nixpkgs and see if darwin builds.
clickhouse: link with lld
stale commentedon Jun 2, 2020
Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
12 remaining items
matklad commentedon Mar 29, 2022
@happysalada https://matklad.github.io/2022/03/14/rpath-or-why-lld-doesnt-work-on-nixos.html includes some notes on debugging. Useful things:
readelf -d target/debug/examples/my-binary | rg PATHto get the actual RPATHcat (which ld.lld)to check if it's actually a scriptccisclanghappysalada commentedon Mar 30, 2022
for me adding
lld_13to the list of buildInputs did the trick. It makes lld work on darwin as well.Thanks again for the help!
nixos-discourse commentedon Apr 7, 2022
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/using-mold-as-linker-prevents-libraries-from-being-found/18530/2
nixos-discourse commentedon Apr 7, 2022
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/using-mold-as-linker-prevents-libraries-from-being-found/18530/3
gabyx commentedon Feb 5, 2024
I used the following to make
lldwork:szlend commentedon May 4, 2024
Here's a wrapped
bintoolsthat's cross-platform and includeslld(tested onlinuxanddarwin):domenkozar commentedon May 10, 2024
@szlend however on linux it shouldn't be using clangStdenv?
Fix use `llvmPackages.bintools` with wrapper for rpath config
szlend commentedon May 10, 2024
Yeah. For my use case I wanted to use
clangon all platforms.PeterWang-dev commentedon Jun 9, 2025
This issue causes
.sonot found of the executable built by rust-nightly using dynamic library. As rust-nightly changed the default linker fromldtolld. nix-community/fenix#191 rust-lang/rust#124129DieracDelta commentedon Jun 17, 2025
Any chance you have a sense of what the practical the implication of this is @PeterWang-dev ? Are newer versions of nightly rust using fenix just not usable because they won't link? Related: do you know if this also applies to oxalica's rust overlay?
Note: I'm interested, so I intend to try both toolchains and see if linking works when I have a few free minutes. I will update this post with the results
PeterWang-dev commentedon Jun 18, 2025
I didn't try oxalica's rust overlay. The newest fenix just not usable because it cannot get correct library path of dynamic library. It can compile, but just cannot run without specifying
LD_LIBRARY_PATHswagtop commentedon Jun 18, 2025
Can confirm that I've had this issue on oxalica's overlay. Using this rustflag solved it:
-Zlinker-features=-lld.It seems I only need to use this flag when specifying a target, but it should be mentioned that on the host target I'm setting the dynamic library searchpath through
rpathwith rustflags, instead of usingLD_LIBRARY_PATH.