Comment 1 for bug 2055837

Revision history for this message
In , Simon Chopin (schopin) wrote :

POSIX documents struct timeval as follows:

struct timeval {
    time_t tv_sec; /* seconds */
    suseconds_t tv_usec; /* microseconds */
};
Since bdc4782744df73a8c0559985c54b5b6b9c7a4a74 ("y2038: Add __USE_TIME_BITS64 support for struct timeval") tv_usec can have __suseconds64_t when using 64-bit time, however suseconds_t is unconditionally typedefed to __suseconds_t.

That leads to the following:

ubuntu@mantic-armhf:~$ cat test.c
#include <sys/time.h>
#include <stdio.h>
#include <assert.h>

int main(void)
{
        struct timeval tv;
        printf("tv_usec: %d, suseconds_t: %d\n", sizeof(tv.tv_usec), sizeof(suseconds_t));
        assert(sizeof(tv.tv_usec) == sizeof(suseconds_t));
        return 0;
}
ubuntu@mantic-armhf:~$ gcc test.c && ./a.out
tv_usec: 4, suseconds_t: 4
ubuntu@mantic-armhf:~$ gcc -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 test.c && ./a.out
tv_usec: 8, suseconds_t: 4
a.out: test.c:9: main: Assertion `sizeof(tv.tv_usec) == sizeof(suseconds_t)' failed.
Aborted (core dumped)

We noticed this when running the conformance tests on Ubuntu Noble, where we've set _TIME_BITS=64 in the default GCC flags as part of the ongoing t64 transition.