From 3e293a170b7e496bc08baa7fa5ec6391614e13ad Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 2 Dec 2024 10:53:01 +0100 Subject: [PATCH] tests: do not unconditionally depend on dlsym Older versions of glibc do not have dl as builtin in. Thus include libdl when it's available. While at it also make the mock library to depend hard on the presents of dlsym. It's only necessary for s390. Fixes: cbbfdd0ddfa2 ("test/mock: pass thru unknown ioctls") Reported-by: Steven Seungcheol Lee Signed-off-by: Daniel Wagner --- meson.build | 6 ++++++ test/ioctl/meson.build | 1 + test/ioctl/mock.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/meson.build b/meson.build index 50f68d10..c39903dc 100644 --- a/meson.build +++ b/meson.build @@ -246,6 +246,12 @@ conf.set( ), description: 'Is ioctl the glibc interface (rather than POSIX)' ) +dl_dep = dependency('dl', required: false) +conf.set( + 'HAVE_LIBC_DLSYM', + cc.has_function('dlsym', dependencies: dl_dep), + description: 'Is dlsym function present', +) if cc.has_function_attribute('fallthrough') conf.set('fallthrough', '__attribute__((__fallthrough__))') diff --git a/test/ioctl/meson.build b/test/ioctl/meson.build index bbee047d..fe666fa1 100644 --- a/test/ioctl/meson.build +++ b/test/ioctl/meson.build @@ -1,6 +1,7 @@ mock_ioctl = library( 'mock-ioctl', ['mock.c', 'util.c'], + dependencies: [dl_dep] ) # Add mock-ioctl to the LD_PRELOAD path so it overrides libc. diff --git a/test/ioctl/mock.c b/test/ioctl/mock.c index 14f6e71b..c34c4ce7 100644 --- a/test/ioctl/mock.c +++ b/test/ioctl/mock.c @@ -151,9 +151,13 @@ int ioctl(int fd, int request, ...) result64 = true; break; default: +#if HAVE_LIBC_LDSYM real_ioctl = dlsym(RTLD_NEXT, "ioctl"); if (!real_ioctl) fail("Error: dlsym failed to find original ioctl\n"); +#else + fail("Error: unhandled ioctl\n"); +#endif } va_start(args, request);