public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Paul Eggert <eggert@cs.ucla.edu>
Cc: "Rich Felker" <dalias@libc.org>,
	"Stefan Puiu" <stefan.puiu@gmail.com>,
	"Andreas Schwab" <schwab@linux-m68k.org>,
	"Michael Kerrisk" <mtk.manpages@gmail.com>,
	наб <nabijaczleweli@nabijaczleweli.xyz>,
	"Jakub Wilk" <jwilk@jwilk.net>,
	libc-alpha@sourceware.org,
	"Joseph Myers" <joseph@codesourcery.com>,
	"Zack Weinberg" <zack@owlfolio.org>
Subject: Re: [RFC v3 3/3] sys/types.h: Make snseconds_t user visible
Date: Wed, 8 Dec 2021 22:53:51 +0100	[thread overview]
Message-ID: <b1b98690-f9cc-acf7-415f-f8f0aad7c0ba@gmail.com> (raw)
In-Reply-To: <3946d7a9-48cd-32bf-06dc-129181bdd8e7@linaro.org>

Hi Adhemerval, Paul,

On 12/8/21 22:12, Adhemerval Zanella wrote:
> We can even be more clever and use something similar to what musl does:
> 
> diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
> index 489e81136d..b962d3f95f 100644
> --- a/time/bits/types/struct_timespec.h
> +++ b/time/bits/types/struct_timespec.h
> @@ -15,19 +15,9 @@ struct timespec
>   #else
>     __time_t tv_sec;             /* Seconds.  */
>   #endif
> -#if __WORDSIZE == 64 \
> -  || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) \
> -  || (__TIMESIZE == 32 && !defined __USE_TIME_BITS64)
> -  __syscall_slong_t tv_nsec;   /* Nanoseconds.  */
> -#else
> -# if __BYTE_ORDER == __BIG_ENDIAN
> -  int: 32;           /* Padding.  */
> -  long int tv_nsec;  /* Nanoseconds.  */
> -# else
> -  long int tv_nsec;  /* Nanoseconds.  */
> -  int: 32;           /* Padding.  */
> -# endif
> -#endif
> +  int : 8 * (sizeof (time_t) - sizeof (long)) * (__BYTE_ORDER == __BIG_ENDIAN);
> +  long int tv_nsec;
> +  int : 8 * (sizeof (time_t) - sizeof (long)) * (__BYTE_ORDER == __LITTLE_ENDIAN);
>   };
>   
>   #endif
> 
>>
>> and report back on the minimum kernel version for which this works correctly.
> 
> The above does not show any regression on a recent 5.13, but I am not sure which
> is the minimal version it does work correctly on x32.
> 
> I don't mind bump the minimal kernel version for x32, however it would be good
> to check with x86 maintainers.

If that works, this seems to me a clean workaround to the X32 bug (IMO 
both spec and kernel bug, in others' opinions kernel bug, in others' 
opinions spec bug, but we agree there's a bug).  We simply forget the 
bug ever existed, and hope no one triggers it again in a future 
implementation.  In the manual page we can add a small bug note for past 
implementations, noting that it doesn't apply anymore; instead of a 
prominent note that some implementations are currently buggy, which 
would be much worse.

> 
>>
>> (I would still want the type changed in the standards, but only as futureproofing.)
>>

Regarding this, I completely agree with Zack, that this is a bug spec, 
and since the standards simply wrote in stone existing practice, we can 
only conclude that existing practice wasn't ideal.  Having a contract so 
specific about the type of tv_nsec is unnecessary and in general C has 
moved in the other direction: use int or typedefs almost everywhere; 
rare are the interfaces that use long (and even more rarely or never 
short), and usually justified.  This case is just an accident of history.

I also see the value of keeping some accidents just for the sake of not 
accidentally making bigger accidents, and C has traditionally done this, 
so I could live with 'long' for tv_nsec, even if it is wrong.

In this case, in principle, snseconds_t would be backwards compatible, 
and it would allow future implementations (say 100 years from now?) to 
move to int if needed (maybe for ABI stability, maybe for other future 
reasons that we cannot foresee), or would allow to keep it defined as 
long forever if API stability is god.

But if you disagree with that, the above changes seem reasonable and 
enough to me.

Paul:

On 12/8/21 19:12, Paul Eggert wrote:
 >
 > I'm still not seeing the need for a user-visible type "snseconds_t".
 >

I hope Zack and I made our reasons visible to you in our latest (and 
this) emails.

 > In response to the earlier proposal "[RFC v2 1/2] sys/types.h: Define
 > new type: snseconds_t", Joseph suggested omitting snseconds_t[1], I
 > supported this suggestion[2], and I don't recall seeing any statement
 > explaining why this type needs to be user-visible.

Joseph suggested omitting it, and also suggested that if making it 
visible, do it in a separate patch for a separate discussion, and that's 
exactly what I did.

I enjoy these discussions, even when I know beforehand that my proposed 
changes will be rejected, because I (and also the other part) usually 
learn something, and hopefully fix other (related or unrelated) things 
that help all of us.  In this case we learnt some better code from musl, 
and cleaned up some mess of code (or are in the path to do so).

So please don't feel ignored in your rejection; I took it into account :)

 >
 > This is a separate issue of whether we need a __snseconds_t type at all
 > (which is the disagreement that Rich Felker is expressing). Although the
 > type __snseconds_t may well be useful for glibc's own purposes, my
 > experience is that user code doesn't need a snseconds_t type without the
 > leading underscores. Arguably a user-visible snseconds_t type would
 > cause more confusion than it'd cure, and so would be a net negative.

Yes, and that's why in v3 they are in different patches, although since 
they have some relation, they are still in the same patch set.

Thanks,
Alex


-- 
Alejandro Colomar
Linux man-pages maintainer; https://www.kernel.org/doc/man-pages/

  reply	other threads:[~2021-12-08 21:53 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07 11:19 [PATCH] sys/types.h: Define new types: [s]nseconds_t Alejandro Colomar
2021-12-07 12:36 ` Andreas Schwab
2021-12-07 13:17 ` наб
2021-12-07 18:20   ` Alejandro Colomar (man-pages)
2021-12-07 21:48     ` наб
2021-12-07 19:10   ` Joseph Myers
2021-12-07 15:50 ` Zack Weinberg
2021-12-07 18:24   ` Alejandro Colomar (man-pages)
2021-12-07 21:48 ` [RFC v2 1/2] sys/types.h: Define new type: snseconds_t Alejandro Colomar
2021-12-07 23:56   ` Joseph Myers
2021-12-08  0:17     ` Paul Eggert
2021-12-08  0:29   ` Rich Felker
2021-12-08  2:26     ` Zack Weinberg
2021-12-08  3:05       ` Rich Felker
2021-12-08 14:34         ` Zack Weinberg
2021-12-08 17:38           ` Rich Felker
2021-12-08 19:52             ` Zack Weinberg
2021-12-08 18:15           ` Adhemerval Zanella
2021-12-08 21:41           ` Joseph Myers
2021-12-07 22:05 ` [RFC v2 2/2] sys/types.h: struct timespec: Use snseconds_t for tv_nsec Alejandro Colomar
2021-12-08 14:47 ` [RFC v3 1/3] bits/types[izes].h: Define new internal type: __snseconds_t Alejandro Colomar
2021-12-08 14:47 ` [RFC v3 2/3] sys/types.h: struct timespec: Use __snseconds_t for tv_nsec Alejandro Colomar
2021-12-08 14:53   ` Zack Weinberg
2021-12-08 15:17     ` Alejandro Colomar (man-pages)
2021-12-08 15:24     ` Joseph Myers
2021-12-08 15:47       ` Alejandro Colomar (man-pages)
2021-12-08 15:59       ` Zack Weinberg
2021-12-08 17:44         ` Rich Felker
2021-12-08 14:48 ` [RFC v3 3/3] sys/types.h: Make snseconds_t user visible Alejandro Colomar
2021-12-08 14:55   ` Zack Weinberg
2021-12-08 15:15     ` Alejandro Colomar (man-pages)
2021-12-08 18:12   ` Paul Eggert
2021-12-08 18:25     ` Rich Felker
2021-12-08 20:10       ` Zack Weinberg
2021-12-08 20:34         ` Rich Felker
2021-12-08 21:12         ` Adhemerval Zanella
2021-12-08 21:53           ` Alejandro Colomar (man-pages) [this message]
2021-12-09 19:20             ` Adhemerval Zanella
2021-12-09 19:42           ` Paul Eggert
2021-12-09 19:52             ` Adhemerval Zanella
2021-12-09 20:13             ` Joseph Myers
2021-12-09 20:17               ` Rich Felker
2021-12-09 20:23             ` Alejandro Colomar (man-pages)
2021-12-09 20:29               ` Joseph Myers
2021-12-09 20:34                 ` Alejandro Colomar (man-pages)
2021-12-09 20:40                   ` Joseph Myers

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=b1b98690-f9cc-acf7-415f-f8f0aad7c0ba@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=dalias@libc.org \
    --cc=eggert@cs.ucla.edu \
    --cc=joseph@codesourcery.com \
    --cc=jwilk@jwilk.net \
    --cc=libc-alpha@sourceware.org \
    --cc=mtk.manpages@gmail.com \
    --cc=nabijaczleweli@nabijaczleweli.xyz \
    --cc=schwab@linux-m68k.org \
    --cc=stefan.puiu@gmail.com \
    --cc=zack@owlfolio.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).