#include <zstd_errors.h>
#endif
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "bitfield.h"
#include "compress.h"
int dlopen_lzma(void) {
#if HAVE_XZ
- ELF_NOTE_DLOPEN("lzma",
+ SD_ELF_NOTE_DLOPEN(
+ "lzma",
"Support lzma compression in journal and coredump files",
COMPRESSION_PRIORITY_XZ,
"liblzma.so.5");
int dlopen_lz4(void) {
#if HAVE_LZ4
- ELF_NOTE_DLOPEN("lz4",
+ SD_ELF_NOTE_DLOPEN(
+ "lz4",
"Support lz4 compression in journal and coredump files",
COMPRESSION_PRIORITY_LZ4,
"liblz4.so.1");
int dlopen_zstd(void) {
#if HAVE_ZSTD
- ELF_NOTE_DLOPEN("zstd",
+ SD_ELF_NOTE_DLOPEN(
+ "zstd",
"Support zstd compression in journal and coredump files",
COMPRESSION_PRIORITY_ZSTD,
"libzstd.so.1");
#define DLSYM_ARG_FORCE(arg) \
&sym_##arg, STRINGIFY(arg)
-#define ELF_NOTE_DLOPEN_VENDOR "FDO"
-#define ELF_NOTE_DLOPEN_TYPE UINT32_C(0x407c0c0a)
-#define ELF_NOTE_DLOPEN_PRIORITY_REQUIRED "required"
-#define ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED "recommended"
-#define ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED "suggested"
-
-/* Add an ".note.dlopen" ELF note to our binary that declares our weak dlopen() dependency. This
- * information can be read from an ELF file via "readelf -p .note.dlopen" or an equivalent command. */
-#define _ELF_NOTE_DLOPEN(json, variable_name) \
- __attribute__((used, section(".note.dlopen"))) _Alignas(sizeof(uint32_t)) static const struct { \
- struct { \
- uint32_t n_namesz, n_descsz, n_type; \
- } nhdr; \
- char name[sizeof(ELF_NOTE_DLOPEN_VENDOR)]; \
- _Alignas(sizeof(uint32_t)) char dlopen_json[sizeof(json)]; \
- } variable_name = { \
- .nhdr = { \
- .n_namesz = sizeof(ELF_NOTE_DLOPEN_VENDOR), \
- .n_descsz = sizeof(json), \
- .n_type = ELF_NOTE_DLOPEN_TYPE, \
- }, \
- .name = ELF_NOTE_DLOPEN_VENDOR, \
- .dlopen_json = json, \
- }
-
-#define _SONAME_ARRAY1(a) "[\""a"\"]"
-#define _SONAME_ARRAY2(a, b) "[\""a"\",\""b"\"]"
-#define _SONAME_ARRAY3(a, b, c) "[\""a"\",\""b"\",\""c"\"]"
-#define _SONAME_ARRAY4(a, b, c, d) "[\""a"\",\""b"\",\""c"\"",\""d"\"]"
-#define _SONAME_ARRAY5(a, b, c, d, e) "[\""a"\",\""b"\",\""c"\"",\""d"\",\""e"\"]"
-#define _SONAME_ARRAY_GET(_1,_2,_3,_4,_5,NAME,...) NAME
-#define _SONAME_ARRAY(...) _SONAME_ARRAY_GET(__VA_ARGS__, _SONAME_ARRAY5, _SONAME_ARRAY4, _SONAME_ARRAY3, _SONAME_ARRAY2, _SONAME_ARRAY1)(__VA_ARGS__)
-
-/* The 'priority' must be one of 'required', 'recommended' or 'suggested' as per specification, use the
- * macro defined above to specify it.
- * Multiple sonames can be passed and they will be automatically constructed into a json array (but note that
- * due to preprocessor language limitations if more than the limit defined above is used, a new
- * _SONAME_ARRAY<X+1> will need to be added). */
-#define ELF_NOTE_DLOPEN(feature, description, priority, ...) \
- _ELF_NOTE_DLOPEN("[{\"feature\":\"" feature "\",\"description\":\"" description "\",\"priority\":\"" priority "\",\"soname\":" _SONAME_ARRAY(__VA_ARGS__) "}]", UNIQ_T(s, UNIQ))
-
/* If called dlopen_many_sym_or_warn() will fail with EPERM. This can be used to block lazy loading of shared
* libs, if we transfer a process into a different namespace. Note that this does not work for all calls of
* dlopen(), just those through our dlopen_safe() wrapper (which we use comprehensively in our
#include <sys/syslog.h>
+#include "sd-dlopen.h"
+
#include "gcrypt-util.h"
#if HAVE_GCRYPT
int dlopen_gcrypt(void) {
#if HAVE_GCRYPT
- ELF_NOTE_DLOPEN("gcrypt",
+ SD_ELF_NOTE_DLOPEN(
+ "gcrypt",
"Support for journald forward-sealing",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libgcrypt.so.20");
return dlopen_many_sym_or_warn(
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "sd-dlopen.h"
+
#include "dlfcn-util.h"
#include "log.h"
#include "string-util.h"
DLSYM_PROTOTYPE(xkb_keymap_unref) = NULL;
static int dlopen_xkbcommon(void) {
- ELF_NOTE_DLOPEN("xkbcommon",
+ SD_ELF_NOTE_DLOPEN(
+ "xkbcommon",
"Support for keyboard locale descriptions",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, "libxkbcommon.so.0");
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, "libxkbcommon.so.0");
return dlopen_many_sym_or_warn(
&xkbcommon_dl, "libxkbcommon.so.0", LOG_DEBUG,
#include <sys/stat.h>
#include <sys/syslog.h>
+#include "sd-dlopen.h"
+
#include "acl-util.h"
#include "alloc-util.h"
#include "errno-util.h"
DLSYM_PROTOTYPE(acl_to_any_text);
int dlopen_libacl(void) {
- ELF_NOTE_DLOPEN("acl",
+ SD_ELF_NOTE_DLOPEN(
+ "acl",
"Support for file Access Control Lists (ACLs)",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libacl.so.1");
return dlopen_many_sym_or_warn(
#include <syslog.h>
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "apparmor-util.h"
#include "fileio.h"
DLSYM_PROTOTYPE(aa_policy_cache_unref) = NULL;
int dlopen_libapparmor(void) {
- ELF_NOTE_DLOPEN("apparmor",
+ SD_ELF_NOTE_DLOPEN(
+ "apparmor",
"Support for AppArmor policies",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libapparmor.so.1");
return dlopen_many_sym_or_warn(
#include <sys/syslog.h>
+#include "sd-dlopen.h"
#include "sd-id128.h"
#include "blkid-util.h"
DLSYM_PROTOTYPE(blkid_safe_string) = NULL;
int dlopen_libblkid(void) {
- ELF_NOTE_DLOPEN("blkid",
+ SD_ELF_NOTE_DLOPEN(
+ "blkid",
"Support for block device identification",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libblkid.so.1");
return dlopen_many_sym_or_warn(
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "sd-dlopen.h"
+
#include "bpf-dlopen.h"
#include "dlfcn-util.h"
#include "errno-util.h"
if (cached != 0)
return cached;
- ELF_NOTE_DLOPEN("bpf",
+ SD_ELF_NOTE_DLOPEN(
+ "bpf",
"Support firewalling and sandboxing with BPF",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libbpf.so.1", "libbpf.so.0");
DISABLE_WARNING_DEPRECATED_DECLARATIONS;
#include <stdlib.h>
+#include "sd-dlopen.h"
#include "sd-json.h"
#include "alloc-util.h"
* 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. */
- ELF_NOTE_DLOPEN("cryptsetup",
+ SD_ELF_NOTE_DLOPEN(
+ "cryptsetup",
"Support for disk encryption, integrity, and authentication",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libcryptsetup.so.12");
r = dlopen_many_sym_or_warn(
#endif
#include <unistd.h>
+#include "sd-dlopen.h"
#include "sd-json.h"
#include "alloc-util.h"
#if HAVE_ELFUTILS
int r;
- ELF_NOTE_DLOPEN("dw",
+ SD_ELF_NOTE_DLOPEN(
+ "dw",
"Support for backtrace and ELF package metadata decoding from core files",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libdw.so.1");
r = dlopen_many_sym_or_warn(
#if HAVE_ELFUTILS
int r;
- ELF_NOTE_DLOPEN("elf",
+ SD_ELF_NOTE_DLOPEN(
+ "elf",
"Support for backtraces and reading ELF package metadata from core files",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libelf.so.1");
r = dlopen_many_sym_or_warn(
/* Package metadata might have different owners, but the
* magic ID is always the same. */
- if (!IN_SET(note_header.n_type, ELF_PACKAGE_METADATA_ID, ELF_NOTE_DLOPEN_TYPE))
+ if (!IN_SET(note_header.n_type, ELF_PACKAGE_METADATA_ID, SD_ELF_NOTE_DLOPEN_TYPE))
continue;
_cleanup_free_ char *payload_0suffixed = NULL;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "sd-dlopen.h"
+
#include "idn-util.h"
#include "log.h" /* IWYU pragma: keep */
DLSYM_PROTOTYPE(idn2_to_unicode_8z8z) = NULL;
int dlopen_idn(void) {
- ELF_NOTE_DLOPEN("idn",
+ SD_ELF_NOTE_DLOPEN(
+ "idn",
"Support for internationalized domain names",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libidn2.so.0");
return dlopen_many_sym_or_warn(
#include <syslog.h>
+#include "sd-dlopen.h"
+
#include "libarchive-util.h"
#include "user-util.h" /* IWYU pragma: keep */
DLSYM_PROTOTYPE(archive_write_set_format_pax) = NULL;
int dlopen_libarchive(void) {
- ELF_NOTE_DLOPEN("archive",
+ SD_ELF_NOTE_DLOPEN(
+ "archive",
"Support for decompressing archive files",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libarchive.so.13");
return dlopen_many_sym_or_warn(
#include <linux/netlink.h>
#include <sys/socket.h>
+#include "sd-dlopen.h"
+
#include "errno-util.h"
#include "fd-util.h"
#include "iovec-util.h"
int dlopen_libaudit(void) {
#if HAVE_AUDIT
- ELF_NOTE_DLOPEN("audit",
+ SD_ELF_NOTE_DLOPEN(
+ "audit",
"Support for Audit logging",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libaudit.so.1");
return dlopen_many_sym_or_warn(
# include <crypt.h>
#endif
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "dlfcn-util.h"
#include "errno-util.h"
/* Several distributions like Debian/Ubuntu and OpenSUSE provide libxcrypt as libcrypt.so.1
* (libcrypt.so.1.1 on some architectures), while others like Fedora/CentOS and Arch provide it as
* libcrypt.so.2. */
- ELF_NOTE_DLOPEN("crypt",
+ SD_ELF_NOTE_DLOPEN(
+ "crypt",
"Support for hashing passwords",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libcrypt.so.2", "libcrypt.so.1", "libcrypt.so.1.1");
_cleanup_(dlclosep) void *dl = NULL;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "sd-dlopen.h"
+
#include "libfido2-util.h"
#include "log.h"
#if HAVE_LIBFIDO2
int r;
- ELF_NOTE_DLOPEN("fido2",
+ SD_ELF_NOTE_DLOPEN(
+ "fido2",
"Support fido2 for encryption and authentication",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libfido2.so.1");
r = dlopen_many_sym_or_warn(
#include <stdio.h>
+#include "sd-dlopen.h"
+
#include "fstab-util.h"
#include "libmount-util.h"
#include "log.h"
DLSYM_PROTOTYPE(mnt_unref_monitor) = NULL;
int dlopen_libmount(void) {
- ELF_NOTE_DLOPEN("mount",
+ SD_ELF_NOTE_DLOPEN(
+ "mount",
"Support for mount enumeration",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libmount.so.1");
return dlopen_many_sym_or_warn(
#include <syslog.h>
+#include "sd-dlopen.h"
+
#include "log.h"
#include "module-util.h"
#include "proc-cmdline.h"
DLSYM_PROTOTYPE(kmod_validate_resources) = NULL;
int dlopen_libkmod(void) {
- ELF_NOTE_DLOPEN("kmod",
+ SD_ELF_NOTE_DLOPEN(
+ "kmod",
"Support for loading kernel modules",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libkmod.so.2");
return dlopen_many_sym_or_warn(
#include <syslog.h>
#include "sd-bus.h"
+#include "sd-dlopen.h"
#include "alloc-util.h"
#include "bus-internal.h"
DLSYM_PROTOTYPE(pam_vsyslog) = NULL;
int dlopen_libpam(void) {
- ELF_NOTE_DLOPEN("pam",
+ SD_ELF_NOTE_DLOPEN(
+ "pam",
"Support for LinuxPAM",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libpam.so.0");
return dlopen_many_sym_or_warn(
#include <passwdqc.h>
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "dlfcn-util.h"
#include "errno-util.h"
int dlopen_passwdqc(void) {
#if HAVE_PASSWDQC
- ELF_NOTE_DLOPEN("passwdqc",
+ SD_ELF_NOTE_DLOPEN(
+ "passwdqc",
"Support for password quality checks",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libpasswdqc.so.1");
return dlopen_many_sym_or_warn(
#include <stdio.h>
#include <unistd.h>
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "dlfcn-util.h"
#include "errno-util.h"
int dlopen_pwquality(void) {
#if HAVE_PWQUALITY
- ELF_NOTE_DLOPEN("pwquality",
+ SD_ELF_NOTE_DLOPEN(
+ "pwquality",
"Support for password quality checks",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libpwquality.so.1");
return dlopen_many_sym_or_warn(
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "sd-dlopen.h"
+
#include "dlfcn-util.h"
#include "hash-funcs.h"
#include "log.h"
int dlopen_pcre2(void) {
#if HAVE_PCRE2
- ELF_NOTE_DLOPEN("pcre2",
+ SD_ELF_NOTE_DLOPEN(
+ "pcre2",
"Support for regular expressions",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libpcre2-8.so.0");
/* So here's something weird: PCRE2 actually renames the symbols exported by the library via C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "ask-password-api.h"
#include "dlfcn-util.h"
int dlopen_p11kit(void) {
#if HAVE_P11KIT
- ELF_NOTE_DLOPEN("p11-kit",
+ SD_ELF_NOTE_DLOPEN(
+ "p11-kit",
"Support for PKCS11 hardware tokens",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libp11-kit.so.0");
return dlopen_many_sym_or_warn(
#endif
#include <stdio.h>
+#include "sd-dlopen.h"
+
#include "ansi-color.h"
#include "dlfcn-util.h"
#include "locale-util.h"
#if HAVE_QRENCODE
int r;
- ELF_NOTE_DLOPEN("qrencode",
+ SD_ELF_NOTE_DLOPEN(
+ "qrencode",
"Support for generating QR codes",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libqrencode.so.4", "libqrencode.so.3");
FOREACH_STRING(s, "libqrencode.so.4", "libqrencode.so.3") {
#include <asm/sgidefs.h>
#endif
+#include "sd-dlopen.h"
+
#include "af-list.h"
#include "alloc-util.h"
#include "env-util.h"
DLSYM_PROTOTYPE(seccomp_syscall_resolve_num_arch) = NULL;
int dlopen_libseccomp(void) {
- ELF_NOTE_DLOPEN("seccomp",
+ SD_ELF_NOTE_DLOPEN(
+ "seccomp",
"Support for Seccomp Sandboxes",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libseccomp.so.2");
return dlopen_many_sym_or_warn(
#include <selinux/selinux.h>
#endif
+#include "sd-dlopen.h"
+
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
DLSYM_PROTOTYPE(string_to_security_class) = NULL;
int dlopen_libselinux(void) {
- ELF_NOTE_DLOPEN("selinux",
+ SD_ELF_NOTE_DLOPEN(
+ "selinux",
"Support for SELinux",
- ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libselinux.so.1");
return dlopen_many_sym_or_warn(
#include <unistd.h>
#include "sd-device.h"
+#include "sd-dlopen.h"
#include "alloc-util.h"
#include "ansi-color.h"
static int dlopen_tpm2_esys(void) {
int r;
- ELF_NOTE_DLOPEN("tpm",
+ SD_ELF_NOTE_DLOPEN(
+ "tpm",
"Support for TPM",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libtss2-esys.so.0");
r = dlopen_many_sym_or_warn(
}
static int dlopen_tpm2_rc(void) {
- ELF_NOTE_DLOPEN("tpm",
+ SD_ELF_NOTE_DLOPEN(
+ "tpm",
"Support for TPM",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libtss2-rc.so.0");
return dlopen_many_sym_or_warn(
}
static int dlopen_tpm2_mu(void) {
- ELF_NOTE_DLOPEN("tpm",
+ SD_ELF_NOTE_DLOPEN(
+ "tpm",
"Support for TPM",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libtss2-mu.so.0");
return dlopen_many_sym_or_warn(
/* 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. */
- ELF_NOTE_DLOPEN("tpm",
+ SD_ELF_NOTE_DLOPEN(
+ "tpm",
"Support for TPM",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libtss2-tcti-device.so.0");
return dlopen_verbose(