Lots of libraries can't be found

I was just

‘strace ls’

as you do…

on Nixos 20.03… .

However , the command works fine, but it’s seems to be missing a lof of libraries.

The are not specified in ‘ldd ls’

Is this just dark magic of nixos linker or something else.

execve("/run/current-system/sw/bin/ls", ["ls"], 0x7ffff782e390 /* 72 vars */) = 0
brk(NULL)                               = 0x11a1000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f916de5b000
access("/etc/ld-nix.so.preload", R_OK)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/rq9vqzjqay8fz8qdidmbgs3lqpq0y6zb-acl-2.2.53/lib/tls/x86_64/x86_64/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/nix/store/rq9vqzjqay8fz8qdidmbgs3lqpq0y6zb-acl-2.2.53/lib/tls/x86_64/x86_64", 0x7ffc2f7b43f0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/rq9vqzjqay8fz8qdidmbgs3lqpq0y6zb-acl-2.2.53/lib/tls/x86_64/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/nix/store/rq9vqzjqay8fz8qdidmbgs3lqpq0y6zb-acl-2.2.53/lib/tls/x86_64", 0x7ffc2f7b43f0) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/rq9vqzjqay8fz8qdidmbgs3lqpq0y6zb-acl-2.2.53/lib/tls/x86_64/librt.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

ldd shows

ldd /run/current-system/sw/bin/ls
        linux-vdso.so.1 (0x00007ffc2f6e6000)
        librt.so.1 => /nix/store/xg6ilb9g9zhi2zg1dpi4zcp288rhnvns-glibc-2.30/lib/librt.so.1 (0x00007ff403554000)
        libacl.so.1 => /nix/store/rq9vqzjqay8fz8qdidmbgs3lqpq0y6zb-acl-2.2.53/lib/libacl.so.1 (0x00007ff403549000)
        libattr.so.1 => /nix/store/b3yikpnxly8vgr2c0sspwqckx44hb474-attr-2.4.48/lib/libattr.so.1 (0x00007ff403541000)
        libcrypto.so.1.1 => /nix/store/hysf4ll023i4q51hymgcqzxik4inq8gm-openssl-1.1.1g/lib/libcrypto.so.1.1 (0x00007ff403255000)
        libpthread.so.0 => /nix/store/xg6ilb9g9zhi2zg1dpi4zcp288rhnvns-glibc-2.30/lib/libpthread.so.0 (0x00007ff403234000)
        libc.so.6 => /nix/store/xg6ilb9g9zhi2zg1dpi4zcp288rhnvns-glibc-2.30/lib/libc.so.6 (0x00007ff403073000)
        libdl.so.2 => /nix/store/xg6ilb9g9zhi2zg1dpi4zcp288rhnvns-glibc-2.30/lib/libdl.so.2 (0x00007ff40306e000)
        /nix/store/xg6ilb9g9zhi2zg1dpi4zcp288rhnvns-glibc-2.30/lib/ld-linux-x86-64.so.2 => /nix/store/xg6ilb9g9zhi2zg1dpi4zcp288rhnvns-glibc-2.30/lib64/ld-linux-x86-64.so.2 (0x00007ff403560000)

These seems to be there, is it just some danging dependcies? or libraries that are trying to load other libraries that don’t exist?

This is normal.

ELF records these libraries in DT_NEEDED entries, containing the name of the library, e.g. librt.so.1. Then there is DT_RUNPATH entry listing the paths where to search for the libraries:

$ readelf -d result/bin/ls | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [/nix/store/camix5721pydww6zwwd4wg77krk61gf1-acl-2.2.53/lib:/nix/store/3y5s6iyzqg2rwy8qz79i5f6cfmwqiaav-attr-2.4.48/lib:/nix/store/3wa1xwnfv8ada1za1r8m4vmsiz1jifqq-glibc-2.32-35/lib]

The path will be searched in order until the needed libraries are discovered, hence the many misses.

On regular Linux distributions, there are only few paths to look for (e.g. /usr/lib) so the rpath is typically empty but for Nix, we need to use rpath to make the packages self-contained. Alternative would be just stuffing absolute paths to DT_NEEDED entries.

1 Like

Thanks for a quick reply and a explanation of this behaviour.