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.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "coredump-config.h"
|
||||
#include "elf-util.h"
|
||||
#include "format-util.h"
|
||||
#include "journal-def.h"
|
||||
#include "log.h"
|
||||
@@ -45,12 +46,10 @@ int coredump_parse_config(CoredumpConfig *config) {
|
||||
config->journal_size_max = JOURNAL_SIZE_MAX;
|
||||
}
|
||||
|
||||
#if !HAVE_DWFL_SET_SYSROOT
|
||||
if (config->enter_namespace) {
|
||||
if (config->enter_namespace && !dlopen_dw_has_dwfl_set_sysroot()) {
|
||||
log_warning("EnterNamespace= is enabled but libdw does not support dwfl_set_sysroot(), disabling.");
|
||||
config->enter_namespace = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
log_debug("Selected storage '%s'.", coredump_storage_to_string(config->storage));
|
||||
log_debug("Selected compression %s.", yes_no(config->compress));
|
||||
|
||||
@@ -468,7 +468,9 @@ static int maybe_remove_external_coredump(
|
||||
}
|
||||
|
||||
static int acquire_pid_mount_tree_fd(const CoredumpConfig *config, CoredumpContext *context) {
|
||||
#if HAVE_DWFL_SET_SYSROOT
|
||||
if (!dlopen_dw_has_dwfl_set_sysroot())
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "dwfl_set_sysroot() is not supported.");
|
||||
|
||||
_cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, fd = -EBADF;
|
||||
_cleanup_close_pair_ int pair[2] = EBADF_PAIR;
|
||||
int r;
|
||||
@@ -533,10 +535,6 @@ static int acquire_pid_mount_tree_fd(const CoredumpConfig *config, CoredumpConte
|
||||
|
||||
context->mount_tree_fd = TAKE_FD(fd);
|
||||
return 0;
|
||||
#else
|
||||
/* Don't bother preparing environment if we can't pass it to libdwfl. */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "dwfl_set_sysroot() is not supported.");
|
||||
#endif
|
||||
}
|
||||
|
||||
static int attach_mount_tree(const CoredumpConfig *config, CoredumpContext *context) {
|
||||
|
||||
Reference in New Issue
Block a user