From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 6C2791F8C6 for ; Wed, 11 Aug 2021 20:31:15 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 452663843890 for ; Wed, 11 Aug 2021 20:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 452663843890 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628713874; bh=cmfPcLbJsX5Rcb/lozB7aYob+TzKs+Zszmx/nzBu1lc=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ZeUcsuY+KNKU+KZypS+hRS5eDsYYRXLjii7KVG85rv6nvx+beS/QUs+3Dsv0bdz1s D26Hp/aL5/BN89m8Rb4hOcPJJH2ATRUM+ooP3HE9pNxfecXZ3eqSQu+i6wFOeagRzk EWcxv3mjNzyXyp/7afdZOnI1iHd2tC8wKDLZwd8s= Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 0DB58386187E for ; Wed, 11 Aug 2021 20:30:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0DB58386187E Received: by mail-pl1-x629.google.com with SMTP id a5so4260741plh.5 for ; Wed, 11 Aug 2021 13:30:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cmfPcLbJsX5Rcb/lozB7aYob+TzKs+Zszmx/nzBu1lc=; b=slDoK4BAmV30LWLaAmbK5DzuH/O19+g0jh4BWHMj+D5PBk5kgbHLd83pmbGnI0wYaR bfav7xMZOBv6ox4TirRckLFQ9zp303vYogVuVXdU+Pa/fbc2VzW4EIbguNhMJDNNxKvE 9MNmL7PZ0998FLByU9Aa19yJhDVWl+gq20+pTOxYvoaodtnxf39g7w5V7CvIzbGnvqWb kTiqh+H1Imd2f7PShhoMHsHdU/U3TD3Q9D/G7PUIkFSatZ16hAnEEQ6pQGoozDHaDOux MwQ2iIU1e4vuuUO84uEtsj3EifqbqxzIdq7Mipi5U3rv5qNIaMfQTnpLlUG55FOJ2kbo l70g== X-Gm-Message-State: AOAM5313LsxEIIhjbSCqFbl8vyrHLDwqm93mFM8vcS5bEa+XNT/aGcNO 9brcwZn6LFDi/919lDez3lYTjw== X-Google-Smtp-Source: ABdhPJwV3EyKZGx5NDTtUvbtnpIjcqcFDixotYLYgJucDjSR/SvUBert3XoEM+z8+aGBqieYwPAKgw== X-Received: by 2002:a63:d104:: with SMTP id k4mr515909pgg.196.1628713843087; Wed, 11 Aug 2021 13:30:43 -0700 (PDT) Received: from ?IPv6:2804:431:c7cb:9dce:70f4:4f7a:652c:7fb? ([2804:431:c7cb:9dce:70f4:4f7a:652c:7fb]) by smtp.gmail.com with ESMTPSA id q11sm417288pfk.32.2021.08.11.13.30.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Aug 2021 13:30:42 -0700 (PDT) Subject: Re: [PATCH v2] time: Fix overflow itimer tests on 32-bit systems To: Stafford Horne , GLIBC patches References: <20210806094217.3227877-1-shorne@gmail.com> Message-ID: <0f577bc8-bef8-6c06-aaa9-57bf16d8443b@linaro.org> Date: Wed, 11 Aug 2021 17:30:40 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210806094217.3227877-1-shorne@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Cc: Openrisc Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On 06/08/2021 06:42, Stafford Horne wrote: > On the port of OpenRISC I am working on and it appears the rv32 port > we have sets __TIMESIZE == 64 && __WORDSIZE == 32. This causes the > size of time_t to be 8 bytes, but the tv_sec in the kernel is still 32-bit > causing truncation. > > The truncations are unavoidable on these systems so skip the > testing/failures by guarding with __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64. > > Also, futher in the tests and in other parts of code checking for time_t > overflow does not work on 32-bit systems when time_t is 64-bit. As > suggested by Adhemerval, update the in_time_t_range function to assume > 32-bits by using int32_t. > > This also brings in the header for stdint.h so we can update other > usages of __int32_t to int32_t as suggested by Adhemerval. > --- > > Hello, > > Sorry for the delay to get this out I have been busy on the hardware side of > openrisc the last month so I haven't been able to spend time on getting this > out. > > The patch ends up doing a test fix and some lib code fixes, I can split it to > separate small patches. But since as a whole it's small I feel leaving it > together is best. LGTM, thanks. Reviewed-by: Adhemerval Zanella > > -Stafford > > include/time.h | 10 ++++++---- > time/tst-itimer.c | 4 ++-- > 2 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/include/time.h b/include/time.h > index 4372bfbd96..ba3c5116cf 100644 > --- a/include/time.h > +++ b/include/time.h > @@ -11,6 +11,7 @@ > # include > # include > # include > +# include > > extern __typeof (strftime_l) __strftime_l; > libc_hidden_proto (__strftime_l) > @@ -334,11 +335,12 @@ libc_hidden_proto (__time64) > actual clock ID. */ > #define CLOCK_IDFIELD_SIZE 3 > > -/* Check whether T fits in time_t. */ > +/* Check whether T fits in int32_t, assume all usages are for > + sizeof(time_t) == 32. */ > static inline bool > in_time_t_range (__time64_t t) > { > - time_t s = t; > + int32_t s = t; > return s == t; > } > > @@ -445,8 +447,8 @@ timespec64_to_timeval64 (const struct __timespec64 ts64) > and suseconds_t. */ > struct __timeval32 > { > - __int32_t tv_sec; /* Seconds. */ > - __int32_t tv_usec; /* Microseconds. */ > + int32_t tv_sec; /* Seconds. */ > + int32_t tv_usec; /* Microseconds. */ > }; > > /* Conversion functions for converting to/from __timeval32 */ > diff --git a/time/tst-itimer.c b/time/tst-itimer.c > index 929c2b74c7..bd7d7afe83 100644 > --- a/time/tst-itimer.c > +++ b/time/tst-itimer.c > @@ -100,7 +100,7 @@ do_test (void) > > /* Linux does not provide 64 bit time_t support for getitimer and > setitimer on architectures with 32 bit time_t support. */ > - if (sizeof (__time_t) == 8) > + if (__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64) > { > TEST_COMPARE (setitimer (timers[i], &it, NULL), 0); > TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, > @@ -131,7 +131,7 @@ do_test (void) > it.it_interval.tv_usec = 20; > it.it_value.tv_sec = 30; > it.it_value.tv_usec = 40; > - if (sizeof (__time_t) == 8) > + if (__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64) > { > TEST_COMPARE (setitimer (timers[i], &it, NULL), 0); > >