Skip to content

Dynamically load compression libraries - #31550

Merged
daandemeyer merged 3 commits into
systemd:mainfrom
teknoraver:dlopen_compress
Mar 5, 2024
Merged

Dynamically load compression libraries#31550
daandemeyer merged 3 commits into
systemd:mainfrom
teknoraver:dlopen_compress

Conversation

@teknoraver

Copy link
Copy Markdown
Member

Dynamically load compression libraries (LZ4, ZSTD, LZMA) so we can reduce the size of the initram images by omitting libraries which aren't really used.

@github-actions github-actions Bot added build-system util-lib tests meson please-review PR is ready for (re-)review by a maintainer labels Feb 29, 2024
@YHNdnzj

YHNdnzj commented Feb 29, 2024

Copy link
Copy Markdown
Member

I'd really like to know if we can replace all these with libarchive first (see also #31131 (comment))

@poettering

Copy link
Copy Markdown
Member

I'd really like to know if we can replace all these with libarchive first (see also #31131 (comment))

hmm, so we link against these libraries in journald for example to compress individual fields, does it really make sense to involve libarchive in that?

does libarchive support uncompressing blobs that aren't tarballs/zipfiles?

i kinda like the fact that if we make the individual compression libs dlopen-deps we truly minimize the dep tree, because people can pick one compressor only. After all libarchive itself does not employ dlopen() afaics.

I mean:

 lddtree /usr/lib64/libarchive.so
libarchive.so => /usr/lib64/libarchive.so (interpreter => none)
    libcrypto.so.3 => /lib64/libcrypto.so.3
    libacl.so.1 => /lib64/libacl.so.1
        libattr.so.1 => /lib64/libattr.so.1
    liblzma.so.5 => /lib64/liblzma.so.5
    libzstd.so.1 => /lib64/libzstd.so.1
    liblz4.so.1 => /lib64/liblz4.so.1
    libbz2.so.1 => /lib64/libbz2.so.1
    libz.so.1 => /lib64/libz.so.1
    libxml2.so.2 => /lib64/libxml2.so.2
        libm.so.6 => /lib64/libm.so.6
            ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
    libc.so.6 => /lib64/libc.so.6

Hence I am very much inclined to merging this PR.

In particular libbz2 I think is something we should try to get out of the deptree. By using libarchive for everyting we'd still link to it indirectly.

Comment thread src/basic/meson.build Outdated
Comment thread src/test/meson.build Outdated
Comment thread src/test/meson.build Outdated
Comment thread src/basic/compress.c Outdated
Comment thread src/basic/compress.c
Comment thread src/basic/compress.c
@poettering

Copy link
Copy Markdown
Member

lgtm, but some issues, see above.

And I guess the CIs need some updating before we can merge this, because the deps are now implicit rather than explicit.

@mrc0mmand any chance you can look into that?

@poettering

Copy link
Copy Markdown
Member

Please also add an extra commit that deletes/updates the relevant lines in the TODO file in the toplevel dir. the one containing "bzip2, xz, lz4"

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Mar 1, 2024
@YHNdnzj

YHNdnzj commented Mar 1, 2024

Copy link
Copy Markdown
Member

does libarchive support uncompressing blobs that aren't tarballs/zipfiles?

Yes, see archive_write_set_format_raw.

i kinda like the fact that if we make the individual compression libs dlopen-deps we truly minimize the dep tree, because people can pick one compressor only. After all libarchive itself does not employ dlopen() afaics.

Indeed. However, as discussed in the other PR, libkmod depends on some of those libs anyway too. And bzip2 is required by things like gnupg/ffmpeg/...

While it would be great if bzip2 can be eliminated from the whole system, that won't happen any time soon. So instead of adding more dlopen()-ed deps, which are hard to manage, it seems more practical to me to reduce the number of direct deps first.

@YHNdnzj

YHNdnzj commented Mar 1, 2024

Copy link
Copy Markdown
Member

IOW, the reduced dependency tree isn't really observable by users, in which case adding more code and introducing more packaging/CI changes really sounds like a pure burden.

@poettering

Copy link
Copy Markdown
Member

Indeed. However, as discussed in the other PR, libkmod depends on some of those libs anyway too. And bzip2 is required by things like gnupg/ffmpeg/...

well, the focus here is really on building tiny systems for initrds for example. I don't see why you'd need gunpg/ffmpeg/… in an initrd...

i mean, sure, on a full blown desktop they will end up int he full install, but even then, i see no reason they need to be in the initrd.

While it would be great if bzip2 can be eliminated from the whole system, that won't happen any time soon. So instead of adding more dlopen()-ed deps, which are hard to manage, it seems more practical to me to reduce the number of direct deps first.

but libarchive itself doesn#t need to be in the initrd, no?

Comment thread src/test/test-compress.c Outdated
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Mar 1, 2024
@teknoraver

Copy link
Copy Markdown
Member Author

Should I call dlopen_* functions also in decompress_startswith_* functions?

This could be the cause of systemd:libsystemd/test-journal-enum failing since they're are referenced in src/libsystemd/sd-journal/journal-file.c

@teknoraver
teknoraver force-pushed the dlopen_compress branch 2 times, most recently from 7c5a90d to 0631df0 Compare March 1, 2024 22:29

@daandemeyer daandemeyer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-dlopen-so.c should be modified as well to test the new dlopen functions

Comment thread src/basic/compress.c
Comment thread src/test/test-compress.c
Comment thread src/test/test-compress.c Outdated
Comment thread src/basic/compress.c
Comment thread src/basic/compress.c
Comment thread src/basic/compress.c
@aafeijoo-suse

Copy link
Copy Markdown
Contributor

Sorry for interrupting your work :-p

No problem at all! Thanks for fixing it so quickly.

yuwata added a commit to yuwata/systemd that referenced this pull request Mar 6, 2024
@teknoraver
teknoraver deleted the dlopen_compress branch March 6, 2024 12:49
bluca pushed a commit that referenced this pull request Mar 6, 2024
@bluca bluca linked an issue Mar 31, 2024 that may be closed by this pull request
nemobis added a commit to nemobis/systemd that referenced this pull request Apr 1, 2024
nemobis added a commit to nemobis/systemd that referenced this pull request Apr 1, 2024
@nemobis nemobis mentioned this pull request Apr 1, 2024
aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this pull request Apr 4, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019

Closes dracutdevs#2642
aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this pull request Apr 4, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019
aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this pull request Apr 4, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019
Conan-Kudo pushed a commit to dracut-ng/dracut that referenced this pull request Apr 8, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019

Closes #2642
@mrc0mmand mrc0mmand added login and removed logind labels Apr 19, 2024
pvalena pushed a commit to pvalena/dracut-fedora that referenced this pull request May 15, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019

Closes #2642
pvalena pushed a commit to redhat-plumbers/dracut-fedora that referenced this pull request May 15, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019

Closes #2642
pvalena pushed a commit to pvalena/dracut-fedora that referenced this pull request May 16, 2024
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019

Closes #2642
aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this pull request Jan 17, 2025
…y included

Some required libraries that used to be statically included are in the process
to be opened via `dlopen()`.

References:
- systemd/systemd#31131
- systemd/systemd#31550
- systemd/systemd#32019
Yamakuzure pushed a commit to elogind/elogind that referenced this pull request Jan 29, 2025
Follow-up for 1c20c9f4fce3b2eb501a776fb6025d6b5567fc00.

Fixes systemd/systemd#31550 (comment).
@nullbio

nullbio commented Feb 26, 2026

Copy link
Copy Markdown

Thanks for saving the world @teknoraver - not sure if you've seen the latest Veritasium video. :-)

@bmkmanoj

Copy link
Copy Markdown

Thanks for saving the world @teknoraver - not sure if you've seen the latest Veritasium video. :-)

This is the video - The Internet Was Weeks Away From Disaster and No One Knew :)

@miladsoltany

Copy link
Copy Markdown

Jesus Christ! I just saw the video. Thank you @teknoraver.

@vinciest

Copy link
Copy Markdown

At first people thought it was just a normal PR.
Thank you! Matteo
Thank you! Andres
Salute from Veritasium's video! o7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Reduce dependencies of libsystemd