This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v7 0/3] y2038: Linux: Introduce __clock_settime64 function
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Alistair Francis <alistair23 at gmail dot com>
- Cc: Lukasz Majewski <lukma at denx dot de>, Zack Weinberg <zackw at panix dot com>, Arnd Bergmann <arnd at arndb dot de>, Alistair Francis <alistair dot francis at wdc dot com>, GNU C Library <libc-alpha at sourceware dot org>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, Florian Weimer <fweimer at redhat dot com>, Carlos O'Donell <carlos at redhat dot com>, Stepan Golosunov <stepan at golosunov dot pp dot ru>
- Date: Wed, 18 Sep 2019 17:25:38 +0000
- Subject: Re: [PATCH v7 0/3] y2038: Linux: Introduce __clock_settime64 function
- Ironport-sdr: 05V0VUemM3yZJdKm0UGW1rnbBAQBcdlbciRhfG67wPWbMOsJRJg3pgBY06qHHdFrBBrrrOHcpj IJUo6ujIiyfrQwm3ZyqJkoUk/eaUfkJUF3iOxnLzFirF245p9TvYIO9JCTJudh/CGxzokvR0t9 d/dWl4/1Aq8EXDhk5wPd2Gw9jgxaGxkkXOz+Cx9up5H7loQr1ovSGGIYcqGyknHNSmdaDJsqPE OTA5GTFZnqgH3gPhYr1zgfcLKuvhziygpau9pmUbcNnttqeS7foygtbWLOFkjINyFQlinVKXQi XRs=
- Ironport-sdr: uYKXxm2FlxpFMfYNEj49h3KsTF4v/Sq45IXO9i4oXqMQr8LXWA22IUydgZ33tZzseX8HsVBNej 1ss0mVZU5/J+awBCo3r5uCx7Qf/XCd+mgg5u5vU9ZidjsqTP/sWm1gi6koVJjFwmMHKEeFeVT8 7zO6ERUtd9lIbjF29S4I+Nw9Qt8jLoKNAGG1UqGeXSb/9kVcFeFcYONCw1hzp18cCEeWzY6YBG hT6J8wSREDIsc8ZGVw6Q0urXSuB4BcYGbPc/usFJRVzwwZcmANdFOFuzYtdbHZ45Y/OmIRN0jm Mk8=
- References: <20190906145911.30207-1-lukma@denx.de> <CAKmqyKMdsVZg_ZS7fLTt23dy2vnZc1z85b_+8heiK-8UiqMx+g@mail.gmail.com> <alpine.DEB.2.21.1909062122220.30243@digraph.polyomino.org.uk> <CAKmqyKP=kmeJjcsDepetvsVrph3xJ7G8yQdNFNyX-wL2ZMtqmA@mail.gmail.com> <20190917121151.01629dad@jawa> <alpine.DEB.2.21.1909171332410.17687@digraph.polyomino.org.uk> <20190917175343.01715554@jawa> <alpine.DEB.2.21.1909171640200.25711@digraph.polyomino.org.uk> <CAKmqyKOXtCQ68G0DxEcesbKQCWGaXpvMV2SX-hzDdJJaQ+J_cA@mail.gmail.com>
On Wed, 18 Sep 2019, Alistair Francis wrote:
> +#include <endian.h>
>
> /* POSIX.1b structure for a time value. This is like a `struct timeval' but
> has nanoseconds instead of microseconds. */
> struct timespec
> {
> __time_t tv_sec; /* Seconds. */
> +#if __WORDSIZE == 64 \
> + || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64)
> __syscall_slong_t tv_nsec; /* Nanoseconds. */
> +#else
> +# if BYTE_ORDER == BIG_ENDIAN
> + __int32_t tv_pad; /* Padding */
> + __syscall_slong_t tv_nsec; /* Nanoseconds */
> +# else
> + __int32_t tv_nsec; /* Nanoseconds */
> + __syscall_slong_t tv_pad; /* Padding */
> +# endif
> +#endif
The padding must be an *unnamed bit-field* so that { tv_sec, tv_nsec }
initializers (common in practice even if not officially supported by the
standards) continue to work. Also, I think you should just use "long int"
for tv_nsec in the case where there is padding, as the standard-defined
type (and then the padding can be "int: 32", so avoiding any dependence on
whether compilers support non-int bit-fields). Certainly the choice of
types for tv_nsec and padding should not depend on the endianness (the
patch above is using __int32_t for the first field and __syscall_slong_t
for the second, regardless of which is tv_nsec and which is padding).
There are namespace issues when changing installed headers. You can't use
macros such as BYTE_ORDER or BIG_ENDIAN because they aren't in the
standard-reserved namespaces.
Unfortunately the definitions of __LITTLE_ENDIAN and __BIG_ENDIAN are in
<endian.h> (__BYTE_ORDER is in the architecture-specific <bits/endian.h>),
and while the non-reserved names therein are all conditional on
__USE_MISC, I don't think we really want to start exporting them from
every header that uses struct timespec. My inclination would be to have a
separate bits/ header that only defines the __LITTLE_ENDIAN / __BIG_ENDIAN
/ __PDP_ENDIAN macros (or that defines those and includes the
architecture-specific header for __BYTE_ORDER), so that other headers can
test endianness without bringing in all the other __USE_MISC
endian-related macros from <endian.h>, but Zack might advise on how such
changes would fit into his header cleanups.
--
Joseph S. Myers
joseph@codesourcery.com