dlopen-note: move all dlopen notes to dlopen-note.h

This also switches all these notes to be defined via SD_ELF_NOTE_DLOPEN_ANCHORED().
Consequently, any notes added within unreachable or unused functions will be
automatically garbage-collected by the linker (--gc-sections) instead of
bloating the final binary.

E.g. unused p11-kit library dependency is now dropped from
systemd-repart.standalone binary.

Before:
```
$ systemd-analyze dlopen-metadata build/systemd-repart.standalone
FEATURE    DESCRIPTION                                                SONAME                        PRIORITY
cryptsetup Support for disk encryption, integrity, and authentication libcryptsetup.so.12           recommended
blkid      Support for block device identification                    libblkid.so.1                 required
libcrypto  Support for cryptographic operations                       libcrypto.so.4 libcrypto.so.3 recommended
mount      Support for mount enumeration                              libmount.so.1                 required
fdisk      Support for reading and writing partition tables           libfdisk.so.1                 required
blkid      Support for block device identification                    libblkid.so.1                 recommended
libcrypto  Support for cryptographic operations                       libcrypto.so.4 libcrypto.so.3 suggested
cryptsetup Support for disk encryption, integrity, and authentication libcryptsetup.so.12           suggested
fdisk      Support for reading and writing partition tables           libfdisk.so.1                 suggested
idn        Support for internationalized domain names                 libidn2.so.0                  suggested
mount      Support for mount enumeration                              libmount.so.1                 recommended
selinux    Support for SELinux                                        libselinux.so.1               recommended
tpm        Support for TPM                                            libtss2-esys.so.0             suggested
tpm        Support for TPM                                            libtss2-rc.so.0               suggested
tpm        Support for TPM                                            libtss2-mu.so.0               suggested
tpm        Support for TPM                                            libtss2-tcti-device.so.0      suggested
p11-kit    Support for PKCS11 hardware tokens                         libp11-kit.so.0               suggested
```

After:
```
$ systemd-analyze dlopen-metadata build/systemd-repart.standalone
FEATURE    DESCRIPTION                                                SONAME                        PRIORITY
cryptsetup Support for disk encryption, integrity, and authentication libcryptsetup.so.12           recommended
blkid      Support for block device identification                    libblkid.so.1                 required
libcrypto  Support for cryptographic operations                       libcrypto.so.4 libcrypto.so.3 recommended
mount      Support for mount enumeration                              libmount.so.1                 required
fdisk      Support for reading and writing partition tables           libfdisk.so.1                 required
blkid      Support for block device identification                    libblkid.so.1                 recommended
libcrypto  Support for cryptographic operations                       libcrypto.so.4 libcrypto.so.3 suggested
cryptsetup Support for disk encryption, integrity, and authentication libcryptsetup.so.12           suggested
fdisk      Support for reading and writing partition tables           libfdisk.so.1                 suggested
mount      Support for mount enumeration                              libmount.so.1                 recommended
selinux    Support for SELinux                                        libselinux.so.1               recommended
tpm        Support for TPM                                            libtss2-esys.so.0             suggested
tpm        Support for TPM                                            libtss2-rc.so.0               suggested
tpm        Support for TPM                                            libtss2-mu.so.0               suggested
tpm        Support for TPM                                            libtss2-tcti-device.so.0      suggested
```
This commit is contained in:
Yu Watanabe
2026-07-10 16:34:26 +09:00
parent aa0db003cf
commit a74b3e1778
114 changed files with 772 additions and 575 deletions
+91
View File
@@ -0,0 +1,91 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "sd-dlopen.h"
#include "basic-forward.h"
#include "strv.h"
/* Avoid invalid priority. */
#define _DLOPEN_CHECK_PRIORITY_required 1
#define _DLOPEN_CHECK_PRIORITY_recommended 1
#define _DLOPEN_CHECK_PRIORITY_suggested 1
/* Unlike SD_ELF_NOTE_DLOPEN_ANCHORED(), this takes feature and priority without quotation. */
#define ELF_NOTE_DLOPEN_ANCHORED(feature, description, priority, ...) \
assert_cc(_DLOPEN_CHECK_PRIORITY_##priority); \
SD_ELF_NOTE_DLOPEN_ANCHORED( \
feature##_##priority, \
STRINGIFY(feature), \
description, \
STRINGIFY(priority), \
__VA_ARGS__)
#if HAVE_BZIP2
# define LIBBZ2_NOTE(priority) \
ELF_NOTE_DLOPEN_ANCHORED( \
bzip2, \
"Support bzip2 compression and decompression", \
priority, \
"libbz2.so.1")
#else
# define LIBBZ2_NOTE(priority)
#endif
#if HAVE_LZ4
# define LIBLZ4_NOTE(priority) \
ELF_NOTE_DLOPEN_ANCHORED( \
lz4, \
"Support lz4 compression in journal and coredump files", \
priority, \
"liblz4.so.1")
#else
# define LIBLZ4_NOTE(priority)
#endif
#if HAVE_XZ
# define LIBLZMA_NOTE(priority) \
ELF_NOTE_DLOPEN_ANCHORED( \
lzma, \
"Support lzma compression in journal and coredump files", \
priority, \
"liblzma.so.5")
#else
# define LIBLZMA_NOTE(priority)
#endif
#if HAVE_ZLIB
# define LIBZ_NOTE(priority) \
ELF_NOTE_DLOPEN_ANCHORED( \
zlib, \
"Support gzip compression and decompression", \
priority, \
"libz.so.1")
#else
# define LIBZ_NOTE(priority)
#endif
#if HAVE_ZSTD
# define LIBZSTD_NOTE(priority) \
ELF_NOTE_DLOPEN_ANCHORED( \
zstd, \
"Support zstd compression in journal and coredump files", \
priority, \
"libzstd.so.1")
#else
# define LIBZSTD_NOTE(priority)
#endif
#define COMPRESS_NOTE(priority) \
LIBBZ2_NOTE(priority); \
LIBLZ4_NOTE(priority); \
LIBLZMA_NOTE(priority); \
LIBZ_NOTE(priority); \
LIBZSTD_NOTE(priority)
#define COMPRESS_DEFAULT_NOTE \
LIBBZ2_NOTE(suggested); \
LIBLZ4_NOTE(COMPRESSION_PRIORITY_LZ4); \
LIBLZMA_NOTE(COMPRESSION_PRIORITY_XZ); \
LIBZ_NOTE(suggested); \
LIBZSTD_NOTE(COMPRESSION_PRIORITY_ZSTD)