Skip to contentSkip to conversation

selftests/futex: fix futex_wait() for 32bit ARM

PATCH In review Dan Carpenter 2 participants 2 messages Aug 26, 2025 – Aug 27, 2025 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 selftests/futex: fix futex_wait() for 32bit ARM

On 32bit ARM systems gcc-12 will use 32bit timestamps while gcc-13 and later will use 64bit timestamps. The problem is that SYS_futex will continue pointing at the 32bit system call. This makes the futex_wait test fail like this:

waiter failed errno 110
not ok 1 futex_wake private returned: 0 Success waiter failed errno 110
not ok 2 futex_wake shared (page anon) returned: 0 Success waiter failed errno 110
not ok 3 futex_wake shared (file backed) returned: 0 Success

Instead of compiling differently depending on the gcc version, use the -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 options to ensure that we are building with 64bit timestamps. Then use ifdefs to make SYS_futex point to the 64bit system call.

---
 tools/testing/selftests/futex/functional/Makefile |  2 +-
 tools/testing/selftests/futex/include/futextest.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/futex/functional/Makefile +1 -1
index 8cfb87f7f7c5..ddfa61d857b9 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 INCLUDES := -I../include -I../../ $(KHDR_INCLUDES)
-CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread $(INCLUDES) $(KHDR_INCLUDES)
+CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $(INCLUDES) $(KHDR_INCLUDES)
 LDLIBS := -lpthread -lrt -lnuma
 
 LOCAL_HDRS := \
tools/testing/selftests/futex/include/futextest.h +11 -0
index 7a5fd1d5355e..3d48e9789d9f 100644
@@ -58,6 +58,17 @@ typedef volatile u_int32_t futex_t;
 #define SYS_futex SYS_futex_time64
 #endif
 
+/*
+ * On 32bit systems if we use "-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" or if
+ * we are using a newer compiler then the size of the timestamps will be 64bit,
+ * however, the SYS_futex will still point to the 32bit futex system call.
+ */
+#if __SIZEOF_POINTER__ == 4 && defined(SYS_futex_time64) && \
+	defined(_TIME_BITS) && _TIME_BITS == 64
+# undef SYS_futex
+# define SYS_futex SYS_futex_time64
+#endif
+
 /**
  * futex() - SYS_futex syscall wrapper
  * @uaddr:	address of first futex
Signature · 1 line
2.47.2
#2 lore raw
Quoted 12 lines · Dan Carpenter

On 32bit ARM systems gcc-12 will use 32bit timestamps while gcc-13 and later will use 64bit timestamps. The problem is that SYS_futex will continue pointing at the 32bit system call. This makes the futex_wait test fail like this:

waiter failed errno 110
not ok 1 futex_wake private returned: 0 Success waiter failed errno 110
not ok 2 futex_wake shared (page anon) returned: 0 Success waiter failed errno 110
not ok 3 futex_wake shared (file backed) returned: 0 Success

Quoted 7 lines

Instead of compiling differently depending on the gcc version, use the -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 options to ensure that we are building with 64bit timestamps. Then use ifdefs to make SYS_futex point to the 64bit system call.

It appears glibc uses the 64bit syscall by default. So that is fine.

Sebastian