Repository navigation
Closed
Closed
Copy link
Description
Maybe this is naive of me, but I thought there was some way on linux to link a dynamic library with an absolute path which would not be affected by LD_LIBRARY_PATH.
I'm on an ubuntu 14.04 system on a shared account where, for whatever reason, LD_LIBRARY was set to include some extra directories. That causes nix-env to segfault:
$ nix-env -q
Segmentation fault (core dumped)
$ ldd `which nix-env`
linux-vdso.so.1 => (0x00007ffde2da7000)
libnixexpr.so => /nix/store/9n8c3g541qn43yjjs94f1a0m69wp8scg-nix-1.11.2/lib/libnixexpr.so (0x00007f72a54ac000)
libgc.so.1 => /nix/store/f24zx1r39kalz01q9kw7zcg1ngj7w2db-boehm-gc-7.2f/lib/libgc.so.1 (0x00007f72a5243000)
libnixmain.so => /nix/store/9n8c3g541qn43yjjs94f1a0m69wp8scg-nix-1.11.2/lib/libnixmain.so (0x00007f72a5031000)
libnixstore.so => /nix/store/9n8c3g541qn43yjjs94f1a0m69wp8scg-nix-1.11.2/lib/libnixstore.so (0x00007f72a4d6f000)
libnixutil.so => /nix/store/9n8c3g541qn43yjjs94f1a0m69wp8scg-nix-1.11.2/lib/libnixutil.so (0x00007f72a4b3d000)
libnixformat.so => /nix/store/9n8c3g541qn43yjjs94f1a0m69wp8scg-nix-1.11.2/lib/libnixformat.so (0x00007f72a4933000)
libstdc++.so.6 => /nix/store/kxac9yv62zff2pj6k1j4d6hiz8jdi2f3-gcc-5.3.0-lib/lib/libstdc++.so.6 (0x00007f72a45b9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f72a42b3000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f72a409c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72a3cd7000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72a3ad3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72a38b5000)
/nix/store/phffgv3pwihmpdyk8xsz3wv8ydysch8w-glibc-2.23/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x0000$f72a573a000)
libsqlite3.so.0 => /nix/store/1w64w28j9vz57g2k5bivh2wpk8q9j6vj-sqlite-3.12.2/lib/libsqlite3.so.0 (0x00007f72a35e0000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f72a33d0000)
libcurl.so.4 => /nix/store/9whcgafma7473b4xpyb88hbhi8w5414z-curl-7.47.1/lib/libcurl.so.4 (0x00007f72a3160000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f72a2f3e000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f72a2b62000)
libnghttp2.so.14 => /nix/store/vv2n25vgck007mjph2ay8g4ab58igzp2-nghttp2-1.9.2-lib/lib/libnghttp2.so.14 (0x00007f72a293$000)
libssh2.so.1 => /nix/store/y8jcz5g52265i18kr63d6lim4k1d7jgn-libssh2-1.7.0/lib/libssh2.so.1 (0x00007f72a2711000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f72a24b2000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f72a2299000)
Whereas simply unsetting LD_LIBRARY_PATH makes nix-env run fine:
$ LD_LIBRARY_PATH= nix-env -q
bash-4.3-p42
That's an easy fix, sure. But shouldn't nix-env be robust against LD_LIBRARY_PATH if possible?
Reacted by Jeff Hykin, Katekov Anton, Glenn Pratt, dzmitry-lahoda and ento
Metadata
Metadata
Assignees
Labels
No labels
Activity
rrnewton commentedon May 15, 2016
I'm not even sure what it means when
lddreports<absolute path> => <absolute path>in its output. That's what it does forld-linux-x86-64.so.Likewise, here's the ldd printout for bash, this time without any LD_LIBRARY_PATH shenanigans:
readelf -dmakes it look like libc.so is in fact a bare name, not an absolute path:What I wanted to see was the nix binary using only its own ld-linux.so and pointing to its own libs exclusively, with absolute paths. Since bash is a core package built from source, it should specify these linker options in the derivation (and not need PatchElf), right?
vcunat commentedon May 16, 2016
This belongs to nixpkgs, really, but let's leave it here.
The way we've always done this:
ld-linux*.so*),libdl.so.2, and they're searched in a list of absolute RPATHs coded into the ELFs;$LD_LIBRARY_PATHcan be used to add directories where to search before RPATH (IIRC we use a nixpkgs-specific patch for the loader to change the priority here).Recently there was a suggestion on ML to use absolute-path so-names instead of RPATH, but I've seen no code yet and I suspect that way might be (significantly) more complicated to implement than what we're doing nowadays.
rrnewton commentedon May 18, 2016
Ok, so it sounds like it's a known problem that LD_LIBRARY_PATH can break executables in /nix/store.
I spent some time reading about rpath, but I wasn't having luck controlling rpath or the loader directly from my own nix build (where I'm going through
gcc-wrapper).If we're always running a custom load, what the heck does it mean that
ld-linux-x86-64.soclaims to point to an Ubuntu system version under/lib64? E.g.:vcunat commentedon May 18, 2016
I'd think that
lddshows this one wrong. IIRC runninglddfrom a different Linux can show information different from what really happens during running. Best uselddfrom nixpkgs.copumpkin commentedon May 18, 2016
@rrnewton just because it's known doesn't mean it's good or that we want it to persist. Is there another ticket tracking this issue? If not, I'd just leave it open.
vcunat commentedon May 18, 2016
There are some places where we rely on
$LD_LIBRARY_PATH. We would have to adapt those.rrnewton commentedon May 18, 2016
@copumpkin, yes indeed it would be great to fix it. I really want to be able to tell people "run this command; it's nix so I can guarantee it will do the same thing for you as for me". But in a multi-user environment sitting on top of another distro... we just haven't fully been able to realize that dream. This is one the things we trip over.
vcunat commentedon May 18, 2016
I don't think distros normally define
$LD_LIBRARY_PATHby default. (Well, NixOS does.) On non-NixOS there's also often problem with libGL, which is related.Really, it's difficult to balance what the user wants there, e.g. we've been arguing whether to use
/etc/foofrom the host OS – IMHO basically noone wants nix stuff completely disregard config from the host machine (includes also~/.*and env vars).rrnewton commentedon May 19, 2016
Yeah, but on shared machines where people can't install in
/usrthen users end up with libraries installed in their home directories and then they set their LD_LIBRARY_PATH to make it work. This is probably a terrible thing. But there have to be some non-zero number of people in the world who set an LD_LIBRARY_PATH in their bashrc or profile.I'm not sure what other people want regarding the isolation of nix on other distros, but whenever we've "mixed" the two worlds, things go south really fast. (E.g. install a compiler via nix and build something outside of nix with it.)
rrnewton commentedon May 19, 2016
I'm perfectly happy if the manual is just updated to say loudly and clearly "unset LD_LIBRARY_PATH before calling any Nix-built binary".
vcunat commentedon May 19, 2016
Yeah, we could document that.
amosbird commentedon Jul 7, 2016
Can I add a post install hook that change all RUNPATH to RPATH? I have customized toolchain that relies on
LD_LIBRARY_PATHwhile I still want to use binaries from nix-env like cmake and ninja.vcunat commentedon Jul 7, 2016
@amosbird: I think the easiest way for you is to wrap the cmake/ninja executables to unsed that variable for them.
16 remaining items
Atry commentedon Aug 14, 2023
#248547 would fix this issue
jeff-hykin commentedon Aug 14, 2023
I don't think so, if we want reproducable behavior then the linked-libraries can't be part of my-machines coincidentally what-env-vars-I-have-at-the-moment.
Adding another ENV var just makes runtime behavior even more complex and difficult reproduce.
nixos-discourse commentedon Nov 3, 2023
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/envfs-fix-shebangs-on-nixos/11234/2
nixos-discourse commentedon Nov 11, 2023
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/envfs-fix-shebangs-on-nixos/11234/4
SomeoneSerge commentedon Nov 28, 2023
Only partially, I believe. There's something fundamentally problematic with DT_RUNPATH's priority, and we'd still suffer e.g. from #287764, because apparently some distributions do set
LD_LIBRARY_PATHIs deprecated upstream. We should collect and summarize all of the issues we've been having with
DT_RUNPATHandLD_LIBRARY_PATH, and open a ticket in glibc support.Just for future readers: at least in year 2023 (the quote is from 2016 and idk how it was back then) NixOS does not set
LD_LIBRARY_PATH, not out of the box. Some of the wrappers in Nixpkgs do extendLD_LIBRARY_PATH, which is a different story.nixos-discourse commentedon Dec 20, 2023
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/on-nixpkgs-and-the-ai-follow-up-to-2023-nix-developer-dialogues/37087/2
nixos-discourse commentedon May 13, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/library-not-found-with-libc-so-6-version-glibc-2-34-not-found/45339/1
DDoSolitary commentedon Jul 19, 2024
FWIW, I took the idea of using LD_AUDIT modules mentioned in #248547 (comment) and wrote an audit module to force ld.so to search DT_RUNPATH before LD_LIBRARY_PATH
https://github.com/DDoSolitary/ld-audit-prefer-runpath
Atry commentedon Jun 19, 2025
I found https://github.com/DDoSolitary/ld-audit-search-mod really helps. @DDoSolitary Do you think it could be a NixOS module, as an alternative to https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/programs/nix-ld.nix ?
Atry commentedon Jun 19, 2025
@DDoSolitary Would you like to add a license file to make
ld-audit-search-modopen source, so that it can be added to nixpkgs?DDoSolitary commentedon Jun 19, 2025
@Atry
Actually I just forgot to add the license file. Thanks for the reminder.
Some notes:
Atry commentedon Jun 19, 2025
I did not encounter glibc crash if I set
export GLIBC_TUNABLES=glibc.rtld.optional_static_tls=2000Atry commentedon Aug 22, 2025
Since #418244 is merged, there is already a way to not break nix-env's absolute paths for dynamic libs.