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);