From b09441b1c5a9f3d705e939f9b5f4a2bcbcaec4c3 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 18 Nov 2022 17:13:22 +0100 Subject: [PATCH] virmockstathelpers: Load aliases for 64-bit time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 32-bit arches, it's possible not only to request -D_FILE_OFFSET_BITS=64 (which is always done with meson) but also -D_TIME_BITS=64. With glibc, both of these affect what variant of stat() or lstat() is called. With 64 bit time it's: __stat64_time64() or __lstat64_time64(), respectively. Fortunately, no other variant (__xstat(), __xstat64()) has _time64 alternative and thus does not need similar treatment. Similarly, musl is not affected by this. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/404 Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- tests/virmockstathelpers.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c index 39e270eaac..5b1f3b08a7 100644 --- a/tests/virmockstathelpers.c +++ b/tests/virmockstathelpers.c @@ -54,6 +54,10 @@ * Unfortunately, because we are trying to mock replace the C library, * we need to know about this internal impl detail. * + * Furthermore, support for 64-bit time can be enabled, which on 32-bit + * systems with glibc overwrites stat64() to __stat64_time64() and lstat64() + * to __lstat64_time64(). + * * On macOS stat() and lstat() are resolved to _stat$INODE64 and * _lstat$INODE64, respectively. stat(2) man page also declares that * stat64(), lstat64() and fstat64() are deprecated, and when @@ -168,7 +172,11 @@ static void virMockStatInit(void) fdebug("real stat %p\n", real_stat); #endif #ifdef MOCK_STAT64 +# if defined(__GLIBC__) && defined(_TIME_BITS) && _TIME_BITS == 64 + VIR_MOCK_REAL_INIT_ALIASED(stat64, "__stat64_time64"); +# else VIR_MOCK_REAL_INIT(stat64); +# endif fdebug("real stat64 %p\n", real_stat64); #endif #ifdef MOCK___XSTAT @@ -188,7 +196,11 @@ static void virMockStatInit(void) fdebug("real lstat %p\n", real_lstat); #endif #ifdef MOCK_LSTAT64 +# if defined(__GLIBC__) && defined(_TIME_BITS) && _TIME_BITS == 64 + VIR_MOCK_REAL_INIT_ALIASED(lstat64, "__lstat64_time64"); +# else VIR_MOCK_REAL_INIT(lstat64); +# endif fdebug("real lstat64 %p\n", real_lstat64); #endif #ifdef MOCK___LXSTAT