From patchwork Wed Mar 27 08:52:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1066740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-100905-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="tEhmLn8l"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Thbt6Hpvz9sSh for ; Wed, 27 Mar 2019 19:53:14 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=ujNTosUCCMVAlBRdgge1bB+3NQ2ASau 8hOcAzo0oyggyAqYNifpUMyKkq1WwKuLBfHPLazN5UCzf9FU8mnOsUIOtzhDNfW/ a0rBVCYgiEvix9qMBVV4TRG5ng4YLe5RqzhwufWuXisEr+I2gUO/ra/CityOmUJt SWm5enCN7si0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=kzAea1wf12YkBL5dMzZLqF3OX8w=; b=tEhmL n8lqtForb4AWuqjXXe+fZRJltqhzcbR5euMJvEkFwkk7gdXNOZjNTLsvpLYYl6hp Z1vnOHuT7Gitw59PdcoGc+iCYhTVMxmcJDoVwr/AepUU+oF8g5vjQryAyJ8O7hp1 UpttxAR4j2HetRae3juxtCxhjaHXN6tmfWoKV8= Received: (qmail 16721 invoked by alias); 27 Mar 2019 08:52:41 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 16633 invoked by uid 89); 27 Mar 2019 08:52:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=Large, 46 X-HELO: mail-out.m-online.net From: Lukasz Majewski To: libc-alpha@sourceware.org, Joseph Myers Cc: Paul Eggert , Zack Weinberg , Lukasz Majewski Subject: [RFC 6/7] y2038: Support for Y2038 safe time on 32 bit systems (generic code) Date: Wed, 27 Mar 2019 09:52:09 +0100 Message-Id: <20190327085210.22019-7-lukma@denx.de> In-Reply-To: <20190327085210.22019-1-lukma@denx.de> References: <20190327085210.22019-1-lukma@denx.de> * include/features.h: Add logic to set __USE_TIME_BITS64 according to passed (when building userspace Y2038 safe program on 32 bit system) _TIME_BITS and _FILE_OFFSET_BITS * manual/creature.texi: Add description of _TIME_BITS * time/bits/types/struct_timespec.h: Add "aliasing" (in preprocessor level) for struct timespec to struct __timespec64 (in userspace) when running on 32 bit system with Y2038 support * time/bits/types/time_t.h: Use __time64_t as time_t when __USE_TIME_BITS64 is defined --- include/features.h | 19 +++++++++++++++++++ manual/creature.texi | 28 ++++++++++++++++++++++++++++ time/bits/types/struct_timespec.h | 8 ++++++++ time/bits/types/time_t.h | 4 ++++ 4 files changed, 59 insertions(+) diff --git a/include/features.h b/include/features.h index e016b3e5c7..bf1d3ccb4f 100644 --- a/include/features.h +++ b/include/features.h @@ -365,6 +365,25 @@ # define __USE_FILE_OFFSET64 1 #endif +/* we need to know the word size in order to check the time size */ +#include + +#if defined _TIME_BITS +# if _TIME_BITS == 64 +# if ! defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS != 64 +# error _TIME_BIT==64 is allowed only when _FILE_OFFSET_BITS==64 +# elif __WORDSIZE == 32 +# define __USE_TIME_BITS64 1 +# endif +# elif __TIME_BITS == 32 +# if __WORDSIZE > 32 +# error __TIME_BITS=32 is not compatible with __WORDSIZE > 32 +# endif +# else +# error Invalid _TIME_BITS value (can only be 32 or 64) +# endif +#endif + #if defined _DEFAULT_SOURCE # define __USE_MISC 1 #endif diff --git a/manual/creature.texi b/manual/creature.texi index 8876b2ab77..10b7111043 100644 --- a/manual/creature.texi +++ b/manual/creature.texi @@ -165,6 +165,34 @@ This macro was introduced as part of the Large File Support extension (LFS). @end defvr +@defvr Macro _TIME_BITS +This macro determines the bit size of @code{time_t} (and therefore the +bit size of all @code{time_t} derived types and the prototypes of all +related functions). If @code{_TIME_BITS} is undefined, the bit size of +time_t equals the bit size of the architecture. + +If @code{_TIME_BITS} is undefined, or if @code{_TIME_BITS} is defined +to the value @code{32} and @code{__WORDSIZE} is defined to the value +@code{32}, or or if @code{_TIME_BITS} is defined to the value @code{64} +and @code{__WORDSIZE} is defined to the value @code{64}, nothing changes. + +If @code{_TIME_BITS} is defined to the value @code{64} and if +@code{__WORDSIZE} is defined to the value @code{32}, then the @w{64 bit} +time API and implementation are used even though the architecture word +size is @code{32}. Also, if the kernel provides @w{64 bit} time support, +it is used; otherwise, the @w{32 bit} kernel time support is used (with +no provision to address kernel Y2038 shortcomings). + +If @code{_TIME_BITS} is defined to the value @code{32} and if +@code{__WORDSIZE} is defined to the value @code{64}, then a compile-time +error is emitted. + +If @code{_TIME_BITS} is defined to a value different from both @code{32} +and @code{64}, then a compile-time error is emitted. + +This macro was introduced as part of the Y2038 support. +@end defvr + @defvr Macro _ISOC99_SOURCE @standards{GNU, (none)} If this macro is defined, features from ISO C99 are included. Since diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h index 5b77c52b4f..fc5a7ec25b 100644 --- a/time/bits/types/struct_timespec.h +++ b/time/bits/types/struct_timespec.h @@ -4,6 +4,9 @@ #include +/* Use the original definition for 64-bit arches + or when 64-bit-time by default has *not* been requested */ +#if __WORDSIZE > 32 || ! defined(__USE_TIME_BITS64) /* POSIX.1b structure for a time value. This is like a `struct timeval' but has nanoseconds instead of microseconds. */ struct timespec @@ -11,5 +14,10 @@ struct timespec __time_t tv_sec; /* Seconds. */ __syscall_slong_t tv_nsec; /* Nanoseconds. */ }; +#else +# include +/* Use the 64-bit-time timespec by default */ +#define timespec __timespec64 +# endif #endif diff --git a/time/bits/types/time_t.h b/time/bits/types/time_t.h index ab8287c6fe..84d67f6ac3 100644 --- a/time/bits/types/time_t.h +++ b/time/bits/types/time_t.h @@ -4,6 +4,10 @@ #include /* Returned by `time'. */ +#ifdef __USE_TIME_BITS64 +typedef __time64_t time_t; +#else typedef __time_t time_t; +#endif #endif