3

I see the following when running strace free:

hans@devad22:~$ strace free 2>&1 | grep openat
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libprocps.so.8", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libsystemd.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/liblzma.so.5", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libzstd.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/liblz4.so.1", O_RDONLY|O_CLOEXEC) = 3
(...)

Why is free opening a bunch of compression libraries? What does free need liblzma for?

terdon
  • 100,812
hanshenrik
  • 324
  • 2
  • 15

1 Answers1

6

This basically a copy of an earlier answer of mine, mutatis mutandis:


It's not free itself that depends on liblzma. Use lddtree from pax-utils (sudo apt install pax-utils) to see the dependency tree:

# lddtree $(command -v free)
free => /usr/bin/free (interpreter => /lib/ld-linux-aarch64.so.1)
    libprocps.so.8 => /lib/aarch64-linux-gnu/libprocps.so.8
        libsystemd.so.0 => /lib/aarch64-linux-gnu/libsystemd.so.0
            liblzma.so.5 => /lib/aarch64-linux-gnu/liblzma.so.5
            libzstd.so.1 => /lib/aarch64-linux-gnu/libzstd.so.1
            liblz4.so.1 => /lib/aarch64-linux-gnu/liblz4.so.1
            libcap.so.2 => /lib/aarch64-linux-gnu/libcap.so.2
            libgcrypt.so.20 => /lib/aarch64-linux-gnu/libgcrypt.so.20
                libgpg-error.so.0 => /lib/aarch64-linux-gnu/libgpg-error.so.0
    libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6
    ld-linux-aarch64.so.1 => /lib/ld-linux-aarch64.so.1

ldd shows all shared libraries that the file links to, including indirect dependencies.


free is from the procps collection of tools, and naturally these tools use a shared library for common functionality. Some of this functionality might be used by only some procps tools, though. In this case, ps and other tools support systemd-related constructs (e.g., ps can output the systemd unit of a process). So it links to the systemd library, which in turn brings in these compression libraries. (Not sure what systemd uses them for, maybe compressing core dump files or something like that.)

However, free doesn't seem to use any systemd-related functionality, AFAICT. (The source code is relatively simple, if you want to check it out.) It just happens to link to a library the links to a systemd library that links to several compression libraries.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Seems legit - and my answer was unfortunately based on assumptions. – Artur Meinild Aug 22 '23 at 10:34
  • systemd supports compressed logs, might be related to compressed logs too – hanshenrik Aug 22 '23 at 10:36
  • Possibly. Anyway, basically the entirety of actual free execution begins around openat(AT_FDCWD, "/proc/meminfo", O_RDONLY|O_LARGEFILE) in the strace output. The system calls before those are mostly various libraries setting up. – muru Aug 22 '23 at 10:42