Change time_t to 64-bit by default

In order to avoid the year 2038 problem, define time_t to a signed
integer with at least 64-bits.  The type for time_t can be forced to
long with the --enable-newlib-long-time_t configure option or with the
_USE_LONG_TIME_T system configuration define.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
This commit is contained in:
Sebastian Huber 2017-09-07 08:24:22 +02:00
parent ad45b86533
commit 4de8754bac
7 changed files with 60 additions and 3 deletions

View File

@ -343,6 +343,12 @@ 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-newlib-long-time_t'
Define time_t to long. On platforms with a 32-bit long type, this gives
raise to the year 2038 problem. The default type for time_t is a signed
64-bit integer on most systems.
Disabled by default.
`--enable-multilib'
Build many library versions.
Enabled by default.

26
newlib/configure vendored
View File

@ -804,6 +804,7 @@ enable_newlib_unbuf_stream_opt
enable_lite_exit
enable_newlib_nano_formatted_io
enable_newlib_retargetable_locking
enable_newlib_long_time_t
enable_multilib
enable_target_optspace
enable_malloc_debugging
@ -1477,6 +1478,7 @@ 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-newlib-long-time_t define time_t to long
--enable-multilib build many library versions (default)
--enable-target-optspace optimize for space
--enable-malloc-debugging indicate malloc debugging requested
@ -2501,6 +2503,19 @@ else
fi
# Check whether --enable-newlib-long-time_t was given.
if test "${enable_newlib_long_time_t+set}" = set; then :
enableval=$enable_newlib_long_time_t; if test "${newlib_long_time_t+set}" != set; then
case "${enableval}" in
yes) newlib_long_time_t=yes ;;
no) newlib_long_time_t=no ;;
*) as_fn_error $? "bad value ${enableval} for newlib-long-time_t option" "$LINENO" 5 ;;
esac
fi
else
newlib_nano_malloc=
fi
# Make sure we can run config.sub.
$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@ -11807,7 +11822,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 11825 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -11913,7 +11928,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 11931 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -12496,6 +12511,13 @@ _ACEOF
fi
if test "${newlib_long_time_t}" = "yes"; then
cat >>confdefs.h <<_ACEOF
#define _WANT_USE_LONG_TIME_T 1
_ACEOF
fi
if test "x${iconv_encodings}" != "x" \
|| test "x${iconv_to_encodings}" != "x" \

View File

@ -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-newlib-long-time_t
AC_ARG_ENABLE(newlib-long-time_t,
[ --enable-newlib-long-time_t define time_t to long],
[if test "${newlib_long_time_t+set}" != set; then
case "${enableval}" in
yes) newlib_long_time_t=yes ;;
no) newlib_long_time_t=no ;;
*) AC_MSG_ERROR(bad value ${enableval} for newlib-long-time_t option) ;;
esac
fi], [newlib_nano_malloc=])dnl
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_long_time_t}" = "yes"; then
AC_DEFINE_UNQUOTED(_WANT_USE_LONG_TIME_T)
fi
dnl
dnl Parse --enable-newlib-iconv-encodings option argument
dnl

View File

@ -186,7 +186,11 @@ typedef void *_iconv_t;
typedef _CLOCK_T_ __clock_t;
#define _TIME_T_ long /* time() */
#if defined(_USE_LONG_TIME_T) || __LONG_MAX__ > 0x7fffffffL
#define _TIME_T_ long
#else
#define _TIME_T_ __int_least64_t
#endif
typedef _TIME_T_ __time_t;
#define _CLOCKID_T_ unsigned long

View File

@ -283,6 +283,12 @@
#endif
#endif
#ifdef _WANT_USE_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. */

View File

@ -90,6 +90,9 @@
/* Define if using retargetable functions for default lock routines. */
#undef _RETARGETABLE_LOCKING
/* Define to use type long for time_t. */
#undef _WANT_USE_LONG_TIME_T
/*
* Iconv encodings enabled ("to" direction)
*/

View File

@ -79,6 +79,7 @@ extern inline struct _reent *__getreent (void)
#define _STDIO_BSD_SEMANTICS 1
#define __TM_GMTOFF tm_gmtoff
#define __TM_ZONE tm_zone
#define _USE_LONG_TIME_T 1
#if defined(__INSIDE_CYGWIN__) || defined(_COMPILING_NEWLIB)
#define __EXPORT __declspec(dllexport)