From patchwork Fri Oct 16 13:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 40739 X-Patchwork-Delegate: l.majewski@majess.pl Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D02553857817; Fri, 16 Oct 2020 13:33:17 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by sourceware.org (Postfix) with ESMTPS id DCEC13857C61 for ; Fri, 16 Oct 2020 13:33:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DCEC13857C61 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=lukma@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4CCRtH0Qc4z1qsjg; Fri, 16 Oct 2020 15:33:11 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4CCRtG63bdz1qv5J; Fri, 16 Oct 2020 15:33:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id SRZJobqDRJXb; Fri, 16 Oct 2020 15:33:07 +0200 (CEST) X-Auth-Info: 9K0i+puZ4eoRMj/Nm/zHbRuYWOh+SI+vVYHfp+Jb66U= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 16 Oct 2020 15:33:07 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Subject: [PATCH v2] y2038: linux: Provide __time64 implementation Date: Fri, 16 Oct 2020 15:32:18 +0200 Message-Id: <20201016133218.20864-1-lukma@denx.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-16.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , Cc: Florian Weimer , GNU C Library , Andreas Schwab , Stepan Golosunov , Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" In the glibc the time function can use vDSO (on power and x86 the USE_IFUNC_TIME is defined), time syscall or 'default' time() from ./time/time.c (as a fallback). In this patch the last function (time) has been refactored and moved to ./sysdeps/unix/sysv/linux/time.c to be Linux specific. The new __time64 explicit 64 bit function for providing 64 bit value of seconds after epoch (by internally calling __clock_gettime64) has been introduced. Moreover, a 32 bit version - __time has been refactored to internally use __time64. The __time is now supposed to be used on systems still supporting 32 bit time (__TIMESIZE != 64) - hence the necessary check for time_t potential overflow. The iFUNC vDSO direct call optimization has been removed from both i686 and powerpc32 (USE_IFUNC_TIME is not defined for those architectures anymore). The Linux kernel does not provide a y2038 safe implementation of time neither it plans to provide it in the future, __clock_gettime64 should be used instead. Keeping support for this optimization would require to handle another build permutation (!__ASSUME_TIME64_SYSCALLS && USE_IFUNC_TIME which adds more complexity and has limited use (since the idea is to eventually have a y2038 safe glibc build). Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test proper usage of both __time64 and __time. Reviewed-by: Adhemerval Zanella --- Changes for v2: - Add guards #ifdef __x86_64__ and #ifdef __powerpc64__ to avoid using time vDSO on 32 bit powerpc and x86 - Remove comment about time syscall conversion to 64 bit - Avoid implicit checks on timer (shall be timer != NULL) - Add comment about disabling vDSO optimization on powerpc32 and x86 --- include/time.h | 7 +++++ sysdeps/unix/sysv/linux/powerpc/time.c | 4 ++- sysdeps/unix/sysv/linux/time.c | 37 +++++++++++++++++++++++++- sysdeps/unix/sysv/linux/x86/time.c | 4 ++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/time.h b/include/time.h index edf6cdf829..caf2af5e74 100644 --- a/include/time.h +++ b/include/time.h @@ -317,6 +317,13 @@ extern int __timespec_get64 (struct __timespec64 *ts, int base); libc_hidden_proto (__timespec_get64) #endif +#if __TIMESIZE == 64 +# define __time64 __time +#else +extern __time64_t __time64 (__time64_t *timer); +libc_hidden_proto (__time64) +#endif + /* Use in the clock_* functions. Size of the field representing the actual clock ID. */ #define CLOCK_IDFIELD_SIZE 3 diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c index d10f449c5c..4fd5e138a3 100644 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ b/sysdeps/unix/sysv/linux/powerpc/time.c @@ -16,5 +16,7 @@ License along with the GNU C Library; if not, see . */ -#define USE_IFUNC_TIME +#ifdef __powerpc64__ +# define USE_IFUNC_TIME +#endif #include diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c index 9d8e573c0a..80641d9ca4 100644 --- a/sysdeps/unix/sysv/linux/time.c +++ b/sysdeps/unix/sysv/linux/time.c @@ -47,5 +47,40 @@ time (time_t *t) } # endif /* !SHARED */ #else /* USE_IFUNC_TIME */ -# include