This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR ada/54040: [x32] Incorrect timeval and timespec
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Arnaud Charlet <charlet at adacore dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Eric Botcazou <ebotcazou at adacore dot com>
- Date: Mon, 18 Nov 2013 06:10:20 -0800
- Subject: Re: [PATCH] PR ada/54040: [x32] Incorrect timeval and timespec
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOq=0jJRC9Ps6aHjKihfXd3XKHmGX7TY0HVTpESd7m0H6Q at mail dot gmail dot com> <20131115111843 dot GA31367 at adacore dot com> <CAMe9rOrZpt5LCP_1dDiOYDi2phbfEQMBYtKaUZhzireTt9vGHg at mail dot gmail dot com> <20131115113815 dot GB7411 at adacore dot com> <CAMe9rOpAs6Gu07nhf-tM1ir97jF-LztL8JY86DuVQ8hb9q80ag at mail dot gmail dot com> <20131115115615 dot GD27059 at adacore dot com> <CAMe9rOpTqtdy_e-Yz6gUAGFWpZNr582-R16WOPEdbikCPg2VjA at mail dot gmail dot com> <20131118085832 dot GA13792 at adacore dot com> <20131118090233 dot GB6341 at adacore dot com> <CAMe9rOryT=7QZjmg__OE95cf-yCay+mGozB89hZ6+gJmWFCAwQ at mail dot gmail dot com> <20131118135712 dot GB1024 at adacore dot com>
On Mon, Nov 18, 2013 at 5:57 AM, Arnaud Charlet <charlet@adacore.com> wrote:
>> >> struct timespec {
>> >> __kernel_time_t tv_sec; /* seconds */
>> >> long tv_nsec; /* nanoseconds */
>> >> };
>>
>> This is wrong for x32 where tv_nsec is long long, not
>> long. There are a couple places where long should be
>> long long for x32.
>
> Well yes, but the type is *not* time_t, it's conceptually a different type.
>
>> Glibc gets them right properly:
>
> But that's for timeval, not timespec.
Glibc has
struct timespec
{
__time_t tv_sec; /* Seconds. */
__syscall_slong_t tv_nsec; /* Nanoseconds. */
};
__syscall_slong_t is long long for x32.
>> All for Linux architectures, __suseconds_t and
>> __suseconds_t are the same as time_t, including
>> x32. If not, we can't use array for timeval.
>
> Well this PR is about x32 being different from all other linux ports. There's
> no guarantee that we won't have exactly the same issue on future ports where
> __suseconds_t is *not* the same as time_t.
Ada was using long for time_t and
type timeval is array (1 .. 2) of C.long
It assumes that the type of tv_nsec is the same as tv_sec.
> Also there's the issue of s-osinte-solaris-posix.ads which is broken with
> your change right now.
>
> The short term solution would be to apply this change:
>
> --- s-osinte-solaris-posix.ads (revision 298928)
> +++ s-osinte-solaris-posix.ads (working copy)
> @@ -513,7 +513,7 @@
>
> type timespec is record
> tv_sec : time_t;
> - tv_nsec : long;
> + tv_nsec : time_t;
> end record;
> pragma Convention (C, timespec);
>
> But I'd rather settle on which type is appropriate for the tv_nsec
> field before making this change.
>
__syscall_slong_t is a Linux specific type. We
can add tv_nsec_t, which should be the same
as time_t for all the current targets.
--
H.J.