Skip to content

Commit

Permalink
tests: do not unconditionally depend on dlsym
Browse files Browse the repository at this point in the history
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: cbbfdd0 ("test/mock: pass thru unknown ioctls")
Reported-by: Steven Seungcheol Lee <[email protected]>
Signed-off-by: Daniel Wagner <[email protected]>
  • Loading branch information
igaw committed Dec 2, 2024
1 parent dad5a98 commit 3e293a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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__))')
Expand Down
1 change: 1 addition & 0 deletions test/ioctl/meson.build
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/ioctl/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3e293a1

Please sign in to comment.