From: Bastian Germann <bage@debian.org>
To: linux-mtd@lists.infradead.org
Cc: Bastian Germann <bage@debian.org>
Subject: [PATCH] unittests: fix syscall mocks on 32-bit with time64 glibc
Date: Tue, 28 Apr 2026 00:37:08 +0200 [thread overview]
Message-ID: <20260427223711.401029-1-bage@debian.org> (raw)
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/
reply other threads:[~2026-04-27 22:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260427223711.401029-1-bage@debian.org \
--to=bage@debian.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox