* [PATCH] unittests: fix syscall mocks on 32-bit with time64 glibc
@ 2026-04-27 22:37 Bastian Germann
0 siblings, 0 replies; only message in thread
From: Bastian Germann @ 2026-04-27 22:37 UTC (permalink / raw)
To: linux-mtd; +Cc: Bastian Germann
On 32-bit systems (e.g. armhf), building with -D_FORTIFY_SOURCE=2,
-D_FILE_OFFSET_BITS=64, and -D_TIME_BITS=64 CFLAGS fails many tests.
These flags activate glibc symbol redirects that bypass the --wrap
linker interpositions used by the cmocka mocks:
- _FORTIFY_SOURCE=2 + _FILE_OFFSET_BITS=64: open(path, flags) -> open64()
- _FILE_OFFSET_BITS=64: lseek() -> lseek64()
- _TIME_BITS=64 (glibc >= 2.34): ioctl() -> __ioctl_time64()
Add --wrap entries for each redirected symbol and provide thin forwarders
that delegate to the primary __wrap_open / __wrap_lseek / __wrap_ioctl
functions via plain function calls. This ensures that __func__ inside
those functions resolves correctly for cmocka's expectation lookup.
Signed-off-by: Bastian Germann <bage@debian.org>
---
tests/unittests/Makemodule.am | 4 ++--
tests/unittests/test_lib.h | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/tests/unittests/Makemodule.am b/tests/unittests/Makemodule.am
index 277cac2..7b2ba4d 100644
--- a/tests/unittests/Makemodule.am
+++ b/tests/unittests/Makemodule.am
@@ -1,13 +1,13 @@
ubilib_test_SOURCES = tests/unittests/libubi_test.c lib/libubi.c
ubilib_test_SOURCES += tests/unittests/test_lib.h
ubilib_test_LDADD = $(CMOCKA_LIBS)
-ubilib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=read -Wl,--wrap=lseek
+ubilib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=open64 -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=__ioctl_time64 -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=lseek64
ubilib_test_CPPFLAGS = -O0 --std=gnu99 $(CMOCKA_CFLAGS) -I$(top_srcdir)/include -DSYSFS_ROOT='"$(top_srcdir)/tests/unittests/sysfs_mock"'
mtdlib_test_SOURCES = tests/unittests/libmtd_test.c lib/libmtd.c lib/libmtd_legacy.c
mtdlib_test_SOURCES += tests/unittests/test_lib.h
mtdlib_test_LDADD = $(CMOCKA_LIBS)
-mtdlib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=write
+mtdlib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=open64 -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=__ioctl_time64 -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=lseek64 -Wl,--wrap=write
mtdlib_test_CPPFLAGS = -O0 -D_GNU_SOURCE --std=gnu99 $(CMOCKA_CFLAGS) -I$(top_srcdir)/lib/ -I$(top_srcdir)/include -DSYSFS_ROOT='"$(top_srcdir)/tests/unittests/sysfs_mock"'
TEST_BINS = \
diff --git a/tests/unittests/test_lib.h b/tests/unittests/test_lib.h
index cd94d9f..7a5b98b 100644
--- a/tests/unittests/test_lib.h
+++ b/tests/unittests/test_lib.h
@@ -89,6 +89,25 @@ off_t __wrap_lseek(int fd, off_t seek, int whence)
return mock_type(off_t);
}
+int __wrap_open64(const char *path, int flags)
+{
+ return __wrap_open(path, flags);
+}
+
+off_t __wrap_lseek64(int fd, off_t offset, int whence)
+{
+ return __wrap_lseek(fd, offset, whence);
+}
+
+int __wrap___ioctl_time64(int fd, unsigned long req, ...)
+{
+ va_list ap;
+ va_start(ap, req);
+ void *arg = va_arg(ap, void *);
+ va_end(ap);
+ return __wrap_ioctl(fd, req, arg);
+}
+
#define expect_open(X,Y,Z) do { \
expect_string(__wrap_open, path, X);\
will_return(__wrap_open, Y);\
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-27 22:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 22:37 [PATCH] unittests: fix syscall mocks on 32-bit with time64 glibc Bastian Germann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.