]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: add DLOPEN_* wrapper macros that stamp .note.dlopen on callers
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 30 May 2026 21:51:17 +0000 (22:51 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 1 Jun 2026 17:24:15 +0000 (18:24 +0100)
This macro emits an SD_ELF_NOTE_DLOPEN note so that calling sites,
and not just libsystemd-shared, get the ELF stamped with the notes
documenting the dependency. Currently most of the dlopen notes end
up in libsystemd-shared, and executables have no way to document
the optional dependencies they need. With this new macro, this
issue can be fixed.

Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
36 files changed:
src/basic/locale-util.c
src/basic/locale-util.h
src/shared/acl-util.c
src/shared/acl-util.h
src/shared/blkid-util.c
src/shared/blkid-util.h
src/shared/bpf-util.c
src/shared/bpf-util.h
src/shared/crypto-util.c
src/shared/crypto-util.h
src/shared/cryptsetup-util.c
src/shared/cryptsetup-util.h
src/shared/curl-util.c
src/shared/curl-util.h
src/shared/fdisk-util.c
src/shared/fdisk-util.h
src/shared/idn-util.c
src/shared/idn-util.h
src/shared/libarchive-util.c
src/shared/libarchive-util.h
src/shared/libmount-util.c
src/shared/libmount-util.h
src/shared/microhttpd-util.c
src/shared/microhttpd-util.h
src/shared/module-util.c
src/shared/module-util.h
src/shared/pam-util.c
src/shared/pam-util.h
src/shared/seccomp-util.c
src/shared/seccomp-util.h
src/shared/selinux-util.c
src/shared/selinux-util.h
src/shared/ssl-util.c
src/shared/ssl-util.h
src/shared/tpm2-util.c
src/shared/tpm2-util.h

index 6d4493c0bb450fef4a5930709707327292c837e9..2a8e676edad20870330d31462faa73f3884cb3eb 100644 (file)
@@ -39,11 +39,7 @@ int dlopen_libintl(int log_level) {
 #else
         static void *libintl_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "intl",
-                        "Support for message translation via gettext",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libintl.so.8");
+        LIBINTL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &libintl_dl,
index fb22953f16f0ef910d6ec899e30a686cd213605f..c2cbf3580a2afe596556971d3621ee6e82235fdf 100644 (file)
@@ -4,6 +4,8 @@
 #include <libintl.h>    /* IWYU pragma: export */
 #include <locale.h>     /* IWYU pragma: export */
 
+#include "sd-dlopen.h"  /* IWYU pragma: export */
+
 #include "basic-forward.h"
 #include "dlfcn-util.h"
 
@@ -14,6 +16,22 @@ extern DLSYM_PROTOTYPE(dgettext) __attribute__((format_arg(2)));
 
 int dlopen_libintl(int log_level);
 
+#ifdef __GLIBC__
+#define DLOPEN_LIBINTL(log_level, priority) dlopen_libintl(log_level)
+#else
+#define LIBINTL_NOTE(priority)                                          \
+        SD_ELF_NOTE_DLOPEN("intl",                                      \
+                           "Support for message translation via gettext", \
+                           priority,                                    \
+                           "libintl.so.8")
+
+#define DLOPEN_LIBINTL(log_level, priority)                             \
+        ({                                                              \
+                LIBINTL_NOTE(priority);                                 \
+                dlopen_libintl(log_level);                              \
+        })
+#endif
+
 typedef enum LocaleVariable {
         /* We don't list LC_ALL here on purpose. People should be
          * using LANG instead. */
index 3e6f75d52ac769d9686db5d7a75e45add7c0caca..84fca4da0e444b81b4cc0bdc2572937634969252 100644 (file)
@@ -49,11 +49,7 @@ int dlopen_libacl(int log_level) {
 #if HAVE_ACL
         static void *libacl_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "acl",
-                        "Support for file Access Control Lists (ACLs)",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libacl.so.1");
+        LIBACL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libacl_dl,
index 5e2aeb94a9f63e2da7939ad7966727e9a6803401..981f43a8cc082b349856c4ad5c4675e55d56bf55 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_ACL
@@ -60,6 +62,17 @@ static inline int acl_set_perm(acl_permset_t ps, acl_perm_t p, bool b) {
         return (b ? sym_acl_add_perm : sym_acl_delete_perm)(ps, p);
 }
 
+#define LIBACL_NOTE(priority)                                           \
+        SD_ELF_NOTE_DLOPEN("acl",                                       \
+                           "Support for file Access Control Lists (ACLs)", \
+                           priority,                                    \
+                           "libacl.so.1")
+
+#define DLOPEN_LIBACL(log_level, priority)                              \
+        ({                                                              \
+                LIBACL_NOTE(priority);                                  \
+                dlopen_libacl(log_level);                               \
+        })
 #else
 
 typedef void* acl_t;
@@ -90,6 +103,8 @@ static inline int devnode_acl(int fd, const Set *uids) {
 static inline int fd_add_uid_acl_permission(int fd, uid_t uid, unsigned mask) {
         return -EOPNOTSUPP;
 }
+
+#define DLOPEN_LIBACL(log_level, priority) dlopen_libacl(log_level)
 #endif
 
 int dlopen_libacl(int log_level);
index 022a43ffa90fd02579b4c520edf5e31b711a4ed8..233d45c4f0c876b3f7a94604cf188255afa49a2d 100644 (file)
@@ -99,11 +99,7 @@ int dlopen_libblkid(int log_level) {
 #if HAVE_BLKID
         static void *libblkid_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "blkid",
-                        "Support for block device identification",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libblkid.so.1");
+        LIBBLKID_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libblkid_dl,
index 718a0f15a917ff5b885bc2b00683c37cbf2d2cad..c211bbf3abc0f211ee7e1abd2c9de8ce4a087db1 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_BLKID
@@ -63,6 +65,20 @@ enum {
 
 int blkid_probe_lookup_value_id128(blkid_probe b, const char *field, sd_id128_t *ret);
 int blkid_probe_lookup_value_u64(blkid_probe b, const char *field, uint64_t *ret);
+
+#define LIBBLKID_NOTE(priority)                                         \
+        SD_ELF_NOTE_DLOPEN("blkid",                                     \
+                           "Support for block device identification",   \
+                           priority,                                    \
+                           "libblkid.so.1")
+
+#define DLOPEN_LIBBLKID(log_level, priority)                            \
+        ({                                                              \
+                LIBBLKID_NOTE(priority);                                \
+                dlopen_libblkid(log_level);                             \
+        })
+#else
+#define DLOPEN_LIBBLKID(log_level, priority) dlopen_libblkid(log_level)
 #endif
 
 int dlopen_libblkid(int log_level);
index ea703ce5891069a79db840438e91cfd5654c881a..92fc05f8fc8d5488dd920aed57523814c3c0340b 100644 (file)
@@ -87,11 +87,7 @@ int dlopen_bpf(int log_level) {
         if (cached < 0)
                 return cached; /* Already tried, and failed. */
 
-        SD_ELF_NOTE_DLOPEN(
-                        "bpf",
-                        "Support firewalling and sandboxing with BPF",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libbpf.so.1", "libbpf.so.0");
+        BPF_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         DISABLE_WARNING_DEPRECATED_DECLARATIONS;
 
index 622e4c2e2831f480cf71265c825f0da983704350..faf7349b8a0794ab7479932b6465573dda89971b 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <syslog.h>
 
+#include "sd-dlopen.h"
+
 #if HAVE_LIBBPF
 
 #include <bpf/bpf.h>    /* IWYU pragma: export */
@@ -88,6 +90,19 @@ static inline int compat_bpf_map_create(
  * we understand. */
 int bpf_get_error_translated(const void *ptr);
 
+#define BPF_NOTE(priority)                                              \
+        SD_ELF_NOTE_DLOPEN("bpf",                                       \
+                           "Support firewalling and sandboxing with BPF", \
+                           priority,                                    \
+                           "libbpf.so.1", "libbpf.so.0")
+
+#define DLOPEN_BPF(log_level, priority)                                 \
+        ({                                                              \
+                BPF_NOTE(priority);                                     \
+                dlopen_bpf(log_level);                                  \
+        })
+#else
+#define DLOPEN_BPF(log_level, priority) dlopen_bpf(log_level)
 #endif
 
 int dlopen_bpf(int log_level);
index bca43aebc9acb5df57a0e376d7e7f17f721621df..5359078f6cf20ec6e1c173c6897f0d8456fbee38 100644 (file)
@@ -336,11 +336,7 @@ int dlopen_libcrypto(int log_level) {
 #if HAVE_OPENSSL
         static void *libcrypto_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "libcrypto",
-                        "Support for cryptographic operations",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libcrypto.so.3");
+        LIBCRYPTO_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &libcrypto_dl,
index 7e975c024060326de904905925c84f0f05834b93..f3494bc6836b34bf313199e8dcbabbca384e1e1f 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 #include "iovec-util.h"
 #include "sha256.h"
@@ -31,6 +33,18 @@ int dlopen_libcrypto(int log_level);
 #define X509_FINGERPRINT_SIZE SHA256_DIGEST_SIZE
 
 #if HAVE_OPENSSL
+#define LIBCRYPTO_NOTE(priority)                                        \
+        SD_ELF_NOTE_DLOPEN("libcrypto",                                 \
+                           "Support for cryptographic operations",      \
+                           priority,                                    \
+                           "libcrypto.so.3")
+
+#define DLOPEN_LIBCRYPTO(log_level, priority)                           \
+        ({                                                              \
+                LIBCRYPTO_NOTE(priority);                               \
+                dlopen_libcrypto(log_level);                            \
+        })
+
 #  include <openssl/bio.h>              /* IWYU pragma: export */
 #  include <openssl/bn.h>               /* IWYU pragma: export */
 #  include <openssl/crypto.h>           /* IWYU pragma: export */
@@ -402,4 +416,6 @@ int openssl_extract_public_key(EVP_PKEY *private_key, EVP_PKEY **ret);
 OpenSSLAskPasswordUI* openssl_ask_password_ui_free(OpenSSLAskPasswordUI *ui);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(OpenSSLAskPasswordUI*, openssl_ask_password_ui_free, NULL);
 
+#else
+#define DLOPEN_LIBCRYPTO(log_level, priority) dlopen_libcrypto(log_level)
 #endif
index d80824578f252918f1910583ce3ca0be6be7d8e8..35a59721f88427e967e8d5ff056e1ecca6708ab7 100644 (file)
@@ -281,11 +281,7 @@ int dlopen_cryptsetup(int log_level) {
          * still available though, and given we want to support 2.2.0 for a while longer, we'll use the old
          * symbol if the new one is not available. */
 
-        SD_ELF_NOTE_DLOPEN(
-                        "cryptsetup",
-                        "Support for disk encryption, integrity, and authentication",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libcryptsetup.so.12");
+        CRYPTSETUP_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         r = dlopen_many_sym_or_warn(
                         &cryptsetup_dl, "libcryptsetup.so.12", log_level,
index 23d52d111ae0b2b985e4dfae0db170592239088c..1b3ab8b9604f0b4089328cac81d730176886d170 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "dlfcn-util.h"
 #include "shared-forward.h"
 
@@ -89,6 +91,20 @@ int cryptsetup_add_token_json(struct crypt_device *cd, sd_json_variant *v);
 int cryptsetup_get_volume_key_prefix(struct crypt_device *cd, const char *volume_name, char **ret);
 int cryptsetup_get_volume_key_id(struct crypt_device *cd, const char *volume_name, const void *volume_key,
                                  size_t volume_key_size,  char **ret);
+
+#define CRYPTSETUP_NOTE(priority)                                       \
+        SD_ELF_NOTE_DLOPEN("cryptsetup",                                \
+                           "Support for disk encryption, integrity, and authentication", \
+                           priority,                                    \
+                           "libcryptsetup.so.12")
+
+#define DLOPEN_CRYPTSETUP(log_level, priority)                          \
+        ({                                                              \
+                CRYPTSETUP_NOTE(priority);                              \
+                dlopen_cryptsetup(log_level);                           \
+        })
+#else
+#define DLOPEN_CRYPTSETUP(log_level, priority) dlopen_cryptsetup(log_level)
 #endif
 
 int dlopen_cryptsetup(int log_level);
index aabc3217290ebd51908f9c0a80f3aff048070d93..961a97ad2f79564729a5443db9ef0b36310e953f 100644 (file)
@@ -604,11 +604,7 @@ int dlopen_curl(int log_level) {
 #if HAVE_LIBCURL
         static void *curl_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "curl",
-                        "Support for downloading and uploading files over HTTP",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libcurl.so.4");
+        CURL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &curl_dl,
index c35de1cb7b2549fca304bd15e61ac4231ca31bd2..33bf3684c9eead88fdc16b6f3cbde5eb446f10de 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_LIBCURL
@@ -71,6 +73,19 @@ int curl_append_to_header(struct curl_slist **list, char **headers);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(CURL*, sym_curl_easy_cleanup, curl_easy_cleanupp, NULL);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct curl_slist*, sym_curl_slist_free_all, curl_slist_free_allp, NULL);
 
+#define CURL_NOTE(priority)                                             \
+        SD_ELF_NOTE_DLOPEN("curl",                                      \
+                           "Support for downloading and uploading files over HTTP", \
+                           priority,                                    \
+                           "libcurl.so.4")
+
+#define DLOPEN_CURL(log_level, priority)                                \
+        ({                                                              \
+                CURL_NOTE(priority);                                    \
+                dlopen_curl(log_level);                                 \
+        })
+#else
+#define DLOPEN_CURL(log_level, priority) dlopen_curl(log_level)
 #endif
 
 int dlopen_curl(int log_level);
index 5c55135842a2892b90c1698a21df26f64ab6daff..8efafbc96e469cfb703f81aee13d75e3d9989398 100644 (file)
@@ -83,11 +83,7 @@ int dlopen_fdisk(int log_level) {
 #if HAVE_LIBFDISK
         static void *fdisk_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "fdisk",
-                        "Support for reading and writing partition tables",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libfdisk.so.1");
+        FDISK_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &fdisk_dl,
index 66620c9c1cf50b3e82640efe06060f590014378c..367c6cd051e4436dcbcf98e8daa75f946fb7b059 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_LIBFDISK
@@ -84,6 +86,19 @@ int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret
 int fdisk_partition_get_attrs_as_uint64(struct fdisk_partition *pa, uint64_t *ret);
 int fdisk_partition_set_attrs_as_uint64(struct fdisk_partition *pa, uint64_t flags);
 
+#define FDISK_NOTE(priority)                                            \
+        SD_ELF_NOTE_DLOPEN("fdisk",                                     \
+                           "Support for reading and writing partition tables", \
+                           priority,                                    \
+                           "libfdisk.so.1")
+
+#define DLOPEN_FDISK(log_level, priority)                               \
+        ({                                                              \
+                FDISK_NOTE(priority);                                   \
+                dlopen_fdisk(log_level);                                \
+        })
+#else
+#define DLOPEN_FDISK(log_level, priority) dlopen_fdisk(log_level)
 #endif
 
 int dlopen_fdisk(int log_level);
index 01512b95dda411786692b6bd4025eba4e460eb03..01c808b57feadaebd985fb6bbc9a437e37e4bca8 100644 (file)
@@ -17,11 +17,7 @@ DLSYM_PROTOTYPE(idn2_to_unicode_8z8z) = NULL;
 
 int dlopen_idn(int log_level) {
 #if HAVE_LIBIDN2
-        SD_ELF_NOTE_DLOPEN(
-                        "idn",
-                        "Support for internationalized domain names",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libidn2.so.0");
+        IDN_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &idn_dl, "libidn2.so.0", log_level,
index 918f8c0a57fbd5e69753ce81bfa73ad53f77704c..9bed27140fde98fe200ca03d5803a2b0761cca35 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_LIBIDN2
 extern DLSYM_PROTOTYPE(idn2_lookup_u8);
 extern const char *(*sym_idn2_strerror)(int rc) _const_;
 extern DLSYM_PROTOTYPE(idn2_to_unicode_8z8z);
+
+#define IDN_NOTE(priority)                                              \
+        SD_ELF_NOTE_DLOPEN("idn",                                       \
+                           "Support for internationalized domain names", \
+                           priority,                                    \
+                           "libidn2.so.0")
+
+#define DLOPEN_IDN(log_level, priority)                                 \
+        ({                                                              \
+                IDN_NOTE(priority);                                     \
+                dlopen_idn(log_level);                                  \
+        })
+#else
+#define DLOPEN_IDN(log_level, priority) dlopen_idn(log_level)
 #endif
 
 int dlopen_idn(int log_level);
index c037f4a770b76925fc6adf57aa3f7f681b269e81..5879cf62721bce5ded9dd8025d576b32dc61a96b 100644 (file)
@@ -80,11 +80,7 @@ int dlopen_libarchive(int log_level) {
         static void *libarchive_dl = NULL;
         int r;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "archive",
-                        "Support for decompressing archive files",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libarchive.so.13");
+        LIBARCHIVE_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         r = dlopen_many_sym_or_warn(
                         &libarchive_dl,
index 9f47ea67eacd0d23dc2973bd09981cd647a7dbfd..afaf3712007a8cc53a925bd643929cb61a44f04a 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_LIBARCHIVE
@@ -79,9 +81,20 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive_entry*, sym_archive_entry
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive*, sym_archive_write_free, archive_write_freep, NULL);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive*, sym_archive_read_free, archive_read_freep, NULL);
 
-#else
+#define LIBARCHIVE_NOTE(priority)                                       \
+        SD_ELF_NOTE_DLOPEN("archive",                                   \
+                           "Support for decompressing archive files",   \
+                           priority,                                    \
+                           "libarchive.so.13")
 
+#define DLOPEN_LIBARCHIVE(log_level, priority)                          \
+        ({                                                              \
+                LIBARCHIVE_NOTE(priority);                              \
+                dlopen_libarchive(log_level);                           \
+        })
 
+#else
+#define DLOPEN_LIBARCHIVE(log_level, priority) dlopen_libarchive(log_level)
 #endif
 
 int dlopen_libarchive(int log_level);
index 065fcc2cb2656010e866acd2549b815ee40c1da4..fd83da136ff3d629b0a9875676e4cd01527432b6 100644 (file)
@@ -120,11 +120,7 @@ int dlopen_libmount(int log_level) {
 #if HAVE_LIBMOUNT
         static void *libmount_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "mount",
-                        "Support for mount enumeration",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libmount.so.1");
+        LIBMOUNT_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libmount_dl,
index 7eb7b230b2ff3e3fa1786e48ebb473cfdf6aecb0..44e58ec932040861d1c5a56c99b7562e49de8e0e 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_LIBMOUNT
@@ -73,6 +75,17 @@ int libmount_is_leaf(
                 struct libmnt_table *table,
                 struct libmnt_fs *fs);
 
+#define LIBMOUNT_NOTE(priority)                                         \
+        SD_ELF_NOTE_DLOPEN("mount",                                     \
+                           "Support for mount enumeration",             \
+                           priority,                                    \
+                           "libmount.so.1")
+
+#define DLOPEN_LIBMOUNT(log_level, priority)                            \
+        ({                                                              \
+                LIBMOUNT_NOTE(priority);                                \
+                dlopen_libmount(log_level);                             \
+        })
 #else
 
 struct libmnt_monitor;
@@ -83,6 +96,7 @@ static inline void* sym_mnt_unref_monitor(struct libmnt_monitor *p) {
         return NULL;
 }
 
+#define DLOPEN_LIBMOUNT(log_level, priority) dlopen_libmount(log_level)
 #endif
 
 int dlopen_libmount(int log_level);
index ade36a8c744a425f57d80232fbe870bc329e7732..9820a1e400015b92bf759416b3c10d37c530a95c 100644 (file)
@@ -36,11 +36,7 @@ int dlopen_microhttpd(int log_level) {
 #if HAVE_MICROHTTPD
         static void *microhttpd_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "microhttpd",
-                        "Support for embedded HTTP server via libmicrohttpd",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libmicrohttpd.so.12");
+        MICROHTTPD_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &microhttpd_dl,
index 488ba7ea6e883f3dd733769ca3d79aebaa5ba69d..39b2b9267b2e31fda7bb5d6a5031479b3dadc8f4 100644 (file)
@@ -1,11 +1,24 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 int dlopen_microhttpd(int log_level);
 
 #if HAVE_MICROHTTPD
+#define MICROHTTPD_NOTE(priority)                                       \
+        SD_ELF_NOTE_DLOPEN("microhttpd",                                \
+                           "Support for embedded HTTP server via libmicrohttpd", \
+                           priority,                                    \
+                           "libmicrohttpd.so.12")
+
+#define DLOPEN_MICROHTTPD(log_level, priority)                          \
+        ({                                                              \
+                MICROHTTPD_NOTE(priority);                              \
+                dlopen_microhttpd(log_level);                           \
+        })
 
 #include <microhttpd.h>
 
@@ -134,4 +147,6 @@ int setup_gnutls_logger(char **categories);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct MHD_Daemon*, sym_MHD_stop_daemon, MHD_stop_daemonp, NULL);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct MHD_Response*, sym_MHD_destroy_response, MHD_destroy_responsep, NULL);
 
+#else
+#define DLOPEN_MICROHTTPD(log_level, priority) dlopen_microhttpd(log_level)
 #endif
index 2fb5cd332914b502dc395c74dd1cd008e9495ff1..e060c69d9d6752d19650179d28f9d88b87a4af79 100644 (file)
@@ -173,11 +173,7 @@ int dlopen_libkmod(int log_level) {
 #if HAVE_KMOD
         static void *libkmod_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "kmod",
-                        "Support for loading kernel modules",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libkmod.so.2");
+        LIBKMOD_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libkmod_dl,
index 629979722c734758c0fecd5259c9553f5b9334dd..730e14c31b32a32840301ed7947e39d27d4b1d41 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_KMOD
@@ -35,6 +37,17 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct kmod_list*, sym_kmod_module_unref
 int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose);
 int module_setup_context(struct kmod_ctx **ret);
 
+#define LIBKMOD_NOTE(priority)                                          \
+        SD_ELF_NOTE_DLOPEN("kmod",                                      \
+                           "Support for loading kernel modules",        \
+                           priority,                                    \
+                           "libkmod.so.2")
+
+#define DLOPEN_LIBKMOD(log_level, priority)                             \
+        ({                                                              \
+                LIBKMOD_NOTE(priority);                                 \
+                dlopen_libkmod(log_level);                              \
+        })
 #else
 
 struct kmod_ctx;
@@ -48,6 +61,7 @@ static inline int module_load_and_warn(struct kmod_ctx *ctx, const char *module,
         return -EOPNOTSUPP;
 }
 
+#define DLOPEN_LIBKMOD(log_level, priority) dlopen_libkmod(log_level)
 #endif
 
 int dlopen_libkmod(int log_level);
index fb57dd97575fc8730c7846466ed9c84e814c6273..0fe4207a0b7a1be97dbee8d850dbbf221032aca0 100644 (file)
@@ -383,11 +383,7 @@ int dlopen_libpam(int log_level) {
 #if HAVE_PAM
         static void *libpam_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "pam",
-                        "Support for LinuxPAM",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libpam.so.0");
+        LIBPAM_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libpam_dl,
index ca3ed0c7c88a3a319c49adf8eb9a0afbdfd236ca..408c371e8d7432e87c27c2d907ad439e8b71260d 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_PAM
@@ -104,6 +106,19 @@ int pam_prompt_graceful(pam_handle_t *pamh, int style, char **ret_response, cons
  * and hands it to sym_pam_putenv(), then erases the buffer before freeing in case it carried a secret. */
 int pam_putenv_assign(pam_handle_t *pamh, const char *name, const char *value);
 
+#define LIBPAM_NOTE(priority)                                           \
+        SD_ELF_NOTE_DLOPEN("pam",                                       \
+                           "Support for LinuxPAM",                      \
+                           priority,                                    \
+                           "libpam.so.0")
+
+#define DLOPEN_LIBPAM(log_level, priority)                              \
+        ({                                                              \
+                LIBPAM_NOTE(priority);                                  \
+                dlopen_libpam(log_level);                               \
+        })
+#else
+#define DLOPEN_LIBPAM(log_level, priority) dlopen_libpam(log_level)
 #endif
 
 int dlopen_libpam(int log_level);
index d06dc4f82c15c74efb6ba8817037d94e727f6b0d..0ba0d6cd91c0fca99598469bda41de092cd82676 100644 (file)
@@ -2604,11 +2604,7 @@ int dlopen_libseccomp(int log_level) {
 #if HAVE_SECCOMP
         static void *libseccomp_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "seccomp",
-                        "Support for Seccomp Sandboxes",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libseccomp.so.2");
+        LIBSECCOMP_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libseccomp_dl,
index 7037ef52d17d7e51a1b861ca53d4a40bc61b71ba..89dcaf5ca74b07a754e1cf85c1ef35afc187857e 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "errno-util.h"
 #include "shared-forward.h"
 
@@ -155,6 +157,17 @@ int parse_syscall_and_errno(const char *in, char **name, int *error);
 
 int seccomp_suppress_sync(void);
 
+#define LIBSECCOMP_NOTE(priority)                                       \
+        SD_ELF_NOTE_DLOPEN("seccomp",                                   \
+                           "Support for Seccomp Sandboxes",             \
+                           priority,                                    \
+                           "libseccomp.so.2")
+
+#define DLOPEN_LIBSECCOMP(log_level, priority)                          \
+        ({                                                              \
+                LIBSECCOMP_NOTE(priority);                              \
+                dlopen_libseccomp(log_level);                           \
+        })
 #else
 
 static inline bool is_seccomp_available(void) {
@@ -162,6 +175,7 @@ static inline bool is_seccomp_available(void) {
 }
 
 
+#define DLOPEN_LIBSECCOMP(log_level, priority) dlopen_libseccomp(log_level)
 #endif
 
 int dlopen_libseccomp(int log_level);
index 81ec4a9ba6d283e0382c77043425567995449533..eb1f28a814429f6c2904f0bbb932e679d36e0fad 100644 (file)
@@ -94,11 +94,7 @@ int dlopen_libselinux(int log_level) {
 #if HAVE_SELINUX
         static void *libselinux_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "selinux",
-                        "Support for SELinux",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
-                        "libselinux.so.1");
+        LIBSELINUX_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
 
         return dlopen_many_sym_or_warn(
                         &libselinux_dl,
index f73503bc4b29e4252b7bbd65da0c1dfe101bdb6d..98cfb6bbe40b43b78b24ef00fc0fe10bceeb360d 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <sys/socket.h>
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 #if HAVE_SELINUX
@@ -50,12 +52,25 @@ extern DLSYM_PROTOTYPE(string_to_security_class);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(char*, sym_freecon, freeconp, NULL);
 
+#define LIBSELINUX_NOTE(priority)                                       \
+        SD_ELF_NOTE_DLOPEN("selinux",                                   \
+                           "Support for SELinux",                       \
+                           priority,                                    \
+                           "libselinux.so.1")
+
+#define DLOPEN_LIBSELINUX(log_level, priority)                          \
+        ({                                                              \
+                LIBSELINUX_NOTE(priority);                              \
+                dlopen_libselinux(log_level);                           \
+        })
 #else
 
 
 static inline void freeconp(char **p) {
         assert(*p == NULL);
 }
+
+#define DLOPEN_LIBSELINUX(log_level, priority) dlopen_libselinux(log_level)
 #endif
 
 int dlopen_libselinux(int log_level);
index 7b9314be96337def157555b65104cfebbd699a89..ce51c8cc598d256878b1fc817f94c8ebbe9ce084 100644 (file)
@@ -36,11 +36,7 @@ int dlopen_libssl(int log_level) {
 #if HAVE_OPENSSL
         static void *libssl_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "libssl",
-                        "Support for TLS",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libssl.so.3");
+        LIBSSL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &libssl_dl,
index 7deb028cfe3de2e9456aebb30c80e6af45b2fd5f..80c56fcbe1653af227e23c811e97839a1f478a7b 100644 (file)
@@ -1,11 +1,24 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "shared-forward.h"
 
 int dlopen_libssl(int log_level);
 
 #if HAVE_OPENSSL
+#define LIBSSL_NOTE(priority)                                           \
+        SD_ELF_NOTE_DLOPEN("libssl",                                    \
+                           "Support for TLS",                           \
+                           priority,                                    \
+                           "libssl.so.3")
+
+#define DLOPEN_LIBSSL(log_level, priority)                              \
+        ({                                                              \
+                LIBSSL_NOTE(priority);                                  \
+                dlopen_libssl(log_level);                               \
+        })
 
 #  include <openssl/ssl.h>              /* IWYU pragma: export */
 
@@ -43,4 +56,6 @@ extern DLSYM_PROTOTYPE(TLS_client_method);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(SSL*, sym_SSL_free, SSL_freep, NULL);
 
+#else
+#define DLOPEN_LIBSSL(log_level, priority) dlopen_libssl(log_level)
 #endif
index 3f29730c7f8cbc7cb7faa351f1dca7bddd6c658a..2e2c5d03b5ad992ce9c187e3bd0405996a4fa29d 100644 (file)
@@ -124,11 +124,7 @@ static int dlopen_tpm2_esys(int log_level) {
         static void *libtss2_esys_dl = NULL;
         int r;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "tpm",
-                        "Support for TPM",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libtss2-esys.so.0");
+        TPM2_ESYS_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         r = dlopen_many_sym_or_warn(
                         &libtss2_esys_dl, "libtss2-esys.so.0", log_level,
@@ -190,11 +186,7 @@ static int dlopen_tpm2_esys(int log_level) {
 static int dlopen_tpm2_rc(int log_level) {
         static void *libtss2_rc_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "tpm",
-                        "Support for TPM",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libtss2-rc.so.0");
+        TPM2_RC_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &libtss2_rc_dl, "libtss2-rc.so.0", log_level,
@@ -204,11 +196,7 @@ static int dlopen_tpm2_rc(int log_level) {
 static int dlopen_tpm2_mu(int log_level) {
         static void *libtss2_mu_dl = NULL;
 
-        SD_ELF_NOTE_DLOPEN(
-                        "tpm",
-                        "Support for TPM",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libtss2-mu.so.0");
+        TPM2_MU_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_many_sym_or_warn(
                         &libtss2_mu_dl, "libtss2-mu.so.0", log_level,
@@ -239,11 +227,7 @@ static int dlopen_tpm2_tcti_device(int log_level) {
         /* The "device" TCTI is the most relevant one, let's also load it explicitly on dlopen_tpm2(), even
          * if we don't resolve any symbols here. */
 
-        SD_ELF_NOTE_DLOPEN(
-                        "tpm",
-                        "Support for TPM",
-                        SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
-                        "libtss2-tcti-device.so.0");
+        TPM2_TCTI_DEVICE_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED);
 
         return dlopen_verbose(
                         &libtss2_tcti_device_dl,
index bc26a16947ad10c50be76653b7bd6145ceb157f6..4d62702ce1ff454562de675c9ed112e01cbc5bda 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dlopen.h"
+
 #include "bitfield.h"
 #include "iovec-util.h"
 #include "shared-forward.h"
@@ -43,6 +45,28 @@ static inline bool TPM2_PCR_MASK_VALID(uint32_t pcr_mask) {
 int dlopen_tpm2(int log_level);
 
 #if HAVE_TPM2
+#define TPM2_ESYS_NOTE(priority) \
+        SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-esys.so.0")
+#define TPM2_RC_NOTE(priority) \
+        SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-rc.so.0")
+#define TPM2_MU_NOTE(priority) \
+        SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-mu.so.0")
+#define TPM2_TCTI_DEVICE_NOTE(priority) \
+        SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-tcti-device.so.0")
+
+#define TPM2_NOTE(priority)                                             \
+        ({                                                              \
+                TPM2_ESYS_NOTE(priority);                               \
+                TPM2_RC_NOTE(priority);                                 \
+                TPM2_MU_NOTE(priority);                                 \
+                TPM2_TCTI_DEVICE_NOTE(priority);                        \
+        })
+
+#define DLOPEN_TPM2(log_level, priority)                                \
+        ({                                                              \
+                TPM2_NOTE(priority);                                    \
+                dlopen_tpm2(log_level);                                 \
+        })
 
 #include <tss2/tss2_esys.h>     /* IWYU pragma: export */
 #include <tss2/tss2_mu.h>       /* IWYU pragma: export */
@@ -413,6 +437,7 @@ static inline int tpm2_pcrlock_search_file(const char *path, FILE **ret_file, ch
         return -ENOENT;
 }
 
+#define DLOPEN_TPM2(log_level, priority) dlopen_tpm2(log_level)
 #endif /* HAVE_TPM2 */
 
 int tpm2_list_devices(bool legend, bool quiet);