https://github.com/ptesarik/libkdumpfile/commit/16c73b83a78c1bfb55f3e9823b09fce549c8ec11 From 16c73b83a78c1bfb55f3e9823b09fce549c8ec11 Mon Sep 17 00:00:00 2001 From: Petr Tesarik Date: Thu, 23 May 2024 13:01:17 +0200 Subject: [PATCH] Fix file cache test for 32-bit architectures If 64-bit file offsets are selected with _FILE_OFFSET_BITS on a 32-bit architecture, the default mmap() call takes a 64-bit off_t, but dlsym() returns a pointer to a function that takes a 32-bit off_t. To fix it: - always call original mmap64() if it is available, - use XSTRINGIFY(mmap) instead of "mmap". The latter is needed, because some systems define mmap as a macro which expands to another identifier. Fixes: #80 Signed-off-by: Petr Tesarik --- configure.ac | 2 ++ src/kdumpfile/test-fcache.c | 13 ++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 04d1c6fa..93ebb39d 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,8 @@ AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(off_t) AC_SUBST(SIZEOF_OFF_T, $ac_cv_sizeof_off_t) +AC_CHECK_FUNCS(mmap64) + dnl This makes sure pkg.m4 is available. m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config]) diff --git a/src/kdumpfile/test-fcache.c b/src/kdumpfile/test-fcache.c index 1ed57447..604ed540 100644 --- a/src/kdumpfile/test-fcache.c +++ b/src/kdumpfile/test-fcache.c @@ -64,9 +64,20 @@ static char *mmapbuf; static int failmmap; +#ifdef HAVE_MMAP64 + +#define STR_MMAP XSTRINGIFY(mmap64) +static void* (*orig_mmap)(void *addr, size_t length, int prot, int flags, + int fd, off64_t offset); + +#else + +#define STR_MMAP XSTRINGIFY(mmap) static void* (*orig_mmap)(void *addr, size_t length, int prot, int flags, int fd, off_t offset); +#endif + void * mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { @@ -445,7 +456,7 @@ main(int argc, char **argv) return TEST_ERR; } - orig_mmap = dlsym(RTLD_NEXT, "mmap"); + orig_mmap = dlsym(RTLD_NEXT, STR_MMAP); if (!orig_mmap) { fprintf(stderr, "Cannot get original mmap() address: %s\n", dlerror());