Score:3

why is /usr/bin/free opening liblzma?

cn flag

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?

Score:6
us flag

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.

Artur Meinild avatar
vn flag
Seems legit - and my answer was unfortunately based on assumptions.
cn flag
systemd supports compressed logs, might be related to compressed logs too
muru avatar
us flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.