This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Changes the default size of time_t to 64 bit.


From: Philipp Trommler <philipp.trommler@preh.de>

This fixes the year 2038 problem by defining _TIME_T_ to either
__int_least64_t, __int64_t, long (on 64 bit machines) or long long,
depending on the available types.

Additionally, a new configure switch --enable-32bit-time_t has been
added to force _TIME_T_ to long, architecture independent, in order to
be backward compatible and allow users to use the smaller timestamp
when needed.

Signed-off-by: Philipp Trommler <philipp.trommler@preh.de>
---
 newlib/README                    |  7 +++++++
 newlib/configure                 | 27 +++++++++++++++++++++++++--
 newlib/configure.in              | 15 +++++++++++++++
 newlib/libc/include/sys/_types.h | 15 +++++++++++++++
 newlib/libc/include/sys/config.h |  7 +++++++
 newlib/newlib.hin                |  3 +++
 6 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/newlib/README b/newlib/README
index 78f4de8..d1dface 100644
--- a/newlib/README
+++ b/newlib/README
@@ -343,6 +343,13 @@ One feature can be enabled by specifying `--enable-FEATURE=yes' or
      disables the optimization and saves size of text and stack.
      Enabled by default.
 
+`--enable-32bit-time_t'
+     Use a time_t that is defined to long, regardless of the wordsize of
+     the target. This may lead to problems in January 2038 when the 32 bit
+     timestamp overflows but on the other hand may yield better
+     performance than 64 bit timestamps.
+     Disabled by default.
+
 `--enable-multilib'
      Build many library versions.
      Enabled by default.
diff --git a/newlib/configure b/newlib/configure
index b2f0b33..fa49706 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -804,6 +804,7 @@ enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
 enable_newlib_retargetable_locking
+enable_32bit_time_t
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1477,6 +1478,9 @@ Optional Features:
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
   --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
+  --enable-32bit-time_t   enable the 32 bit time_t which is affected by the
+                          year 2038 problem but may result in better
+                          performance
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2501,6 +2505,18 @@ else
 fi
 
 
+# Check whether --enable-32bit-time_t was given.
+if test "${enable_32bit_time_t+set}" = set; then :
+  enableval=$enable_32bit_time_t; case "${enableval}" in
+   yes) newlib_want_long_time_t=yes ;;
+   no)  newlib_want_long_time_t=no  ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib_want_long_time_t option" "$LINENO" 5 ;;
+ esac
+else
+  newlib_want_long_time_t=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11807,7 +11823,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11810 "configure"
+#line 11826 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11913,7 +11929,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11916 "configure"
+#line 11932 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12496,6 +12512,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_want_long_time_t}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _WANT_LONG_TIME_T 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index 5b86ee8..4d5f7d0 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -238,6 +238,17 @@ AC_ARG_ENABLE(newlib-retargetable-locking,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
  esac],[newlib_retargetable_locking=no])
 
+dnl Support --enable-32bit-time_t
+AC_ARG_ENABLE(32bit-time_t,
+[AS_HELP_STRING([--enable-32bit-time_t],
+                [enable the 32 bit time_t which is affected by the year
+                 2038 problem but may result in better performance])],
+[case "${enableval}" in
+   yes) newlib_want_long_time_t=yes ;;
+   no)  newlib_want_long_time_t=no  ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib_want_long_time_t option) ;;
+ esac],[newlib_want_long_time_t=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -486,6 +497,10 @@ if test "${newlib_retargetable_locking}" = "yes"; then
 AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
 fi
 
+if test "${newlib_want_long_time_t}" = "yes"; then
+AC_DEFINE_UNQUOTED(_WANT_LONG_TIME_T)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index 98b93ce..09be6b0 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -183,7 +183,22 @@ typedef void *_iconv_t;
 #define	_CLOCK_T_	unsigned long	/* clock() */
 typedef	_CLOCK_T_	__clock_t;
 
+#if defined(_USE_LONG_TIME_T)
+/* User decided to use short time_t */
 #define	_TIME_T_	long		/* time() */
+#else
+#if defined(___int_least64_t_defined)
+#define	_TIME_T_	__int_least64_t
+#elif defined(___int64_t_defined)
+#define	_TIME_T_	__int64_t
+#else
+#if __LONG_MAX__ >= 9223372036854775807L
+#define	_TIME_T_	long
+#else
+#define	_TIME_T_	long long
+#endif /* __LONG_MAX__ >= 9223372036854775807L */
+#endif /* ___int_least64_t_defined / ___int64_t_defined / neither */
+#endif /* defined(_USE_LONG_TIME_T) */
 typedef	_TIME_T_	__time_t;
 
 #define	_CLOCKID_T_ 	unsigned long
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 117c49a..f069630 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -283,6 +283,13 @@
 #endif
 #endif
 
+/* If _USE_LONG_TIME_T is set, a long is used for time_t */
+#ifdef _WANT_LONG_TIME_T
+#ifndef _USE_LONG_TIME_T
+#define _USE_LONG_TIME_T
+#endif
+#endif
+
 /* If _MB_EXTENDED_CHARSETS_ALL is set, we want all of the extended
    charsets.  The extended charsets add a few functions and a couple
    of tables of a few K each. */
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index 45c6831..a8b6bf6 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -90,6 +90,9 @@
 /* Define if using retargetable functions for default lock routines.  */
 #undef _RETARGETABLE_LOCKING
 
+/* Define if using the "legacy" 32 bit time_t */
+#undef _WANT_LONG_TIME_T
+
 /*
  * Iconv encodings enabled ("to" direction)
  */
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]