]> git.ipfire.org Git - thirdparty/systemd.git/commit
libc,shared: detect newer library symbols at runtime 42065/head
authorDaan De Meyer <daan@amutable.com>
Tue, 12 May 2026 14:29:18 +0000 (16:29 +0200)
committerDaan De Meyer <daan@amutable.com>
Wed, 13 May 2026 08:29:50 +0000 (10:29 +0200)
commitf795d5459151ad84acf77557cf47dddddb3b4bce
tree8698f63255bd6a6e7d531508f080e157797bedd2
parent5d60cd8539b8c931ac157cc4c94e71df094610cd
libc,shared: detect newer library symbols at runtime

For libc syscall wrappers (pidfd_open, fsopen, openat2, etc.) we previously
gated the calls behind build-time HAVE_* checks. Replace these with shim
functions in src/libc/ that fall back to the raw syscall at runtime when the
loaded glibc lacks the symbol. The infrastructure lives in src/libc/libc-shim.h:
DEFINE_SYSCALL_SHIM falls back to a direct syscall, DEFINE_LIBC_SHIM returns
ENOSYS (for posix_spawn-family helpers that have no corresponding syscall), and
DEFINE_LIBC_ERRNO_SHIM sets errno=ENOSYS and returns -1 (for read/write-style
helpers). The weak reference to the libc symbol is bound via __asm__(\"name\")
rename so the bare libc identifier never appears as a C token — this avoids
both #undef boilerplate against override-header redirects and the resulting
-Wredundant-decls warning. Drop the corresponding cc.has_function() loop from
meson.build.

For optional libraries (libcryptsetup, libdw, libarchive), drop the per-symbol
HAVE_* checks. Always declare the prototypes, suppressing the redundant-decl
warnings via DISABLE_WARNING_REDUNDANT_DECLS and NOLINT, and resolve the symbols
after the main dlopen via a new DLSYM_OPTIONAL() helper that only assigns on
success. libcryptsetup's crypt_set_keyring_to_link / crypt_token_set_external_path
and libarchive's *_is_set wrappers use fallback functions as their pointer
initializers (returning -ENOSYS and 0 respectively), so call sites can invoke
the symbol unconditionally and just check for -ENOSYS where the \"not supported\"
distinction matters.

The same shim treatment applies to pidfd_spawn / posix_spawnattr_setcgroup_np
(src/libc/spawn.c) and epoll_pwait2 (src/libc/epoll.c), with corresponding
override headers in src/include/override/spawn.h and
src/include/override/sys/epoll.h. posix_spawn_wrapper() in process-util.c and
epoll_wait_usec() in sd-event.c now detect ENOSYS in the return value instead
of checking the function pointer, falling back to plain posix_spawn() and
epoll_wait() respectively. coredump-config and coredump-submit get a
dlopen_dw_has_dwfl_set_sysroot() helper. The kexec arch gate now uses
defined(__NR_kexec_file_load) directly; pidfd.h uses __has_include_next() to
decide whether to pull in glibc's header.

This lets binaries built against newer glibc / libcryptsetup / libdw /
libarchive headers still load and run on older targets where these symbols are
absent.
51 files changed:
meson.build
src/basic/dlfcn-util.h
src/basic/process-util.c
src/coredump/coredump-config.c
src/coredump/coredump-submit.c
src/cryptsetup/cryptsetup.c
src/include/musl/stdio.h
src/include/override/fcntl.h
src/include/override/sched.h
src/include/override/signal.h
src/include/override/spawn.h [new file with mode: 0644]
src/include/override/sys/bpf.h
src/include/override/sys/epoll.h [new file with mode: 0644]
src/include/override/sys/ioprio.h
src/include/override/sys/kcmp.h
src/include/override/sys/kexec.h
src/include/override/sys/keyctl.h
src/include/override/sys/mempolicy.h
src/include/override/sys/mount.h
src/include/override/sys/pidfd.h
src/include/override/sys/quota.h
src/include/override/sys/stat.h
src/include/override/sys/xattr.h
src/include/override/unistd.h
src/libc/bpf.c
src/libc/epoll.c [new file with mode: 0644]
src/libc/fcntl.c
src/libc/ioprio.c
src/libc/kcmp.c
src/libc/kexec.c
src/libc/keyctl.c
src/libc/libc-shim.h [new file with mode: 0644]
src/libc/mempolicy.c
src/libc/meson.build
src/libc/mount.c
src/libc/musl/stdio.c
src/libc/pidfd.c
src/libc/quota.c
src/libc/sched.c
src/libc/signal.c
src/libc/spawn.c [new file with mode: 0644]
src/libc/stat.c
src/libc/unistd.c
src/libc/xattr.c
src/libsystemd/sd-event/sd-event.c
src/shared/cryptsetup-util.c
src/shared/cryptsetup-util.h
src/shared/elf-util.c
src/shared/elf-util.h
src/shared/libarchive-util.c
src/shared/libarchive-util.h