[RFC PATCH 1/4] nptl: use futex_time64 for lll_futex_syscall() if possible

Arnd Bergmann arnd@arndb.de
Wed Nov 11 14:21:24 GMT 2026


On Wed, Nov 11, 2026, at 14:54, Adhemerval Zanella Netto wrote:
> On 11/11/26 09:56, Arnd Bergmann wrote:
>> On Wed, Nov 11, 2026, at 13:08, Adhemerval Zanella Netto wrote:

>> // in a new architecture-independent header included from there
>> #if __WORDSIZE==64 || (defined(__x86_64__) && defined(__ILP32__))
>> # define __NR_futex __NR_futex_time64
>> # define __NR_gettimeofday __NR_gettimeofday_time64
>> ...
>> #elif !defined(__USE_TIME_BITS64)
>> # define __NR_futex __NR_futex_time32
>> # define __NR_gettimeofday __NR_gettimeofday_time32
>> ...
>> #else
>> // leave the old macros undefined when building with __USE_TIME_BITS64
>> #endif
>> 
>> This would forcibly break any source code that attempts to
>> call the time32 syscalls by their traditional name in a source
>> file built with -D_TIME_BITS=64, which would otherwise be a bug
>> that may go unnoticed for a long time.
>
> The _TIME_BITS is only meant to be used by programs built against glibc, we
> only use it on tests (and configuring glibc with this should trigger an
> error). And I am not sure if it would simplify things, internal calls
> usually only uses 64 bit time_t variants now (either through wrappers like
> lowlevellock.h or by routing explicitly to internal symbols). The 32 bit
> time_t variants are only provided for ABI compatibility.
>
> Or do you mean by external users, through syscall()? In this case I am
> not sure if routines the SYS_ macro depending of _TIME_BITS value is a 
> good idea.

I specifically care about external users that call syscall(__NR_...)
and end up with the wrong ABI when _TIME_BITS=64 is set at build time
(manually or as the distro default setting). In particular I think
more than half the users of __NR_futex were at some point converted
incorrectly, e.g. the first ones I find in debian codesearch:

https://sources.debian.org/src/mesa/26.2.6-1/src/util/futex.c?hl=38#L37
https://sources.debian.org/src/firefox-esr/153.6.0esr-1/third_party/abseil-cpp/absl/synchronization/internal/futex.h#L81
https://sources.debian.org/src/jackd2/1.9.22~dfsg-6/linux/JackLinuxFutex.cpp?hl=34#L110

These would be examples where a 'struct timespec' is passed
into syscall(__NR_futex, ...) regardless of _TIME_BITS.
On rv32 this works because __NR_futex is not defined, on
most little-endian 32-bit targets this kind-of works as long
as the timeout is between 1 and INT_MAX seconds because you
get the correct value in the first four bytes of the structure.
For FUTEX_CLOCK_REALTIME timeouts past 2038, for big-endian
architectures, and for CONFIG_COMPAT_32BIT_TIME=n this is
of course completely broken.

The best fix here would be to use the libc wrapper for futex
if available, so I probably wouldn't change the status quo
before a glibc release that has this.

      Arnd


More information about the Libc-alpha mailing list