diff --git a/Makeconfig b/Makeconfig
index 0a4811b5e5..e12ee30eca 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1227,6 +1227,20 @@ $(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
 	touch $@
 endif # avoid-generated
 endif # $(build-shared) = yes
+
+-include $(common-objpfx)time64-compat.mk
+postclean-generated += time64-compat.mk
+
+$(common-objpfx)time64-compat.mk: $(sysd-versions-force) \
+				  $(common-objpfx)time64-compat.i
+	sed '/^[        ]*#/d;/^[       ]*$$/d' $< > $@T
+	mv -f $@T $@
+$(common-objpfx)time64-compat.i: $(..)Makeconfig
+	printf "#include <time64-compat.h>\n#ifdef TIME64_NON_DEFAULT\nhave-time64-compat = yes\n#endif" \
+	| $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - > $@T
+	mv -f $@T $@
+
+
 endif # sysd-sorted-done
 
 # The name under which the run-time dynamic linker is installed.
diff --git a/Makerules b/Makerules
index fc5251ffad..f4f641bb26 100644
--- a/Makerules
+++ b/Makerules
@@ -771,7 +771,8 @@ endif
 	     $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
 	     $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
 	     $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
-	     $(addsuffix .d,$(tests) $(tests-internal) $(xtests) $(test-srcs))
+	     $(addsuffix .d,$(tests) $(tests-internal) $(xtests) \
+		$(test-srcs) $(tests-time64) $(xtests-time64))
 ifeq ($(build-programs),yes)
 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
 endif
@@ -1286,6 +1287,21 @@ check: tests
 .PHONY: xcheck
 xcheck: xtests
 
+# Handle tests-time64 and xtests-time64 that should built with LFS
+# and 64-bit time support.
+include $(o-iterator)
+define o-iterator-doit
+$(foreach f,$(tests-time64) $(xtests-time64),\
+	    $(objpfx)$(f)$(o)): CFLAGS += -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64
+endef
+object-suffixes-left := $(all-object-suffixes)
+include $(o-iterator)
+
+ifeq ($(have-time64-compat),yes)
+tests += $(foreach t,$(tests-time64),$(t))
+xtests += $(foreach t,$(xtests-time64),$(t))
+endif
+
 # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
 # that almost all internal declarations from config.h, libc-symbols.h, and
 # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
diff --git a/io/Makefile b/io/Makefile
index 6c637f7c6d..a39f0ecfc1 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -59,7 +59,7 @@ routines :=								\
 	ftw64-time64
 
 others		:= pwd
-test-srcs	:= ftwtest
+test-srcs	:= ftwtest ftwtest-time64
 tests		:= test-utime test-stat test-stat2 test-lfs tst-getcwd \
 		   tst-fcntl bug-ftw1 bug-ftw2 bug-ftw3 bug-ftw4 tst-statvfs \
 		   tst-openat tst-unlinkat tst-fstatat tst-futimesat \
@@ -72,12 +72,18 @@ tests		:= test-utime test-stat test-stat2 test-lfs tst-getcwd \
 		   tst-ftw-lnk tst-file_change_detection tst-lchmod \
 		   tst-ftw-bz26353 tst-utimensat
 
+tests-time64    := tst-fts-time64 \
+		   tst-stat-time64 \
+		   tst-futimesat-time64 \
+		   tst-utimensat-time64
+
 # Likewise for statx, but we do not need static linking here.
 tests-internal += tst-statx
 tests-static += tst-statx
 
 ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)ftwtest.out
+tests-special += $(objpfx)ftwtest.out \
+		 $(objpfx)ftwtest-time64.out
 endif
 
 include ../Rules
@@ -118,8 +124,14 @@ tst-statvfs-ARGS = $(objpfx)tst-statvfs tst-statvfs.c /tmp
 
 tst-open-tmpfile-ARGS = --test-dir=$(objpfx)
 
+CFLAGS-ftwtest-time64.c += -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64
+
 ifeq ($(run-built-tests),yes)
 $(objpfx)ftwtest.out: ftwtest-sh $(objpfx)ftwtest
 	$(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
 	$(evaluate-test)
+
+$(objpfx)ftwtest-time64.out: ftwtest-sh $(objpfx)ftwtest-time64
+	$(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
+	$(evaluate-test)
 endif
diff --git a/io/ftwtest-time64.c b/io/ftwtest-time64.c
new file mode 100644
index 0000000000..67f1c46826
--- /dev/null
+++ b/io/ftwtest-time64.c
@@ -0,0 +1 @@
+#include "ftwtest.c"
diff --git a/io/tst-fts-time64.c b/io/tst-fts-time64.c
new file mode 100644
index 0000000000..a4a41fe1cf
--- /dev/null
+++ b/io/tst-fts-time64.c
@@ -0,0 +1 @@
+#include "tst-fts.c"
diff --git a/io/tst-futimesat-time64.c b/io/tst-futimesat-time64.c
new file mode 100644
index 0000000000..f6c0500eef
--- /dev/null
+++ b/io/tst-futimesat-time64.c
@@ -0,0 +1,4 @@
+#define struct_stat  struct stat
+#define fstat        fstat
+#define fstatat      fstatat
+#include "io/tst-futimesat.c"
diff --git a/io/tst-futimesat.c b/io/tst-futimesat.c
index af58ad06dd..c32ab2b668 100644
--- a/io/tst-futimesat.c
+++ b/io/tst-futimesat.c
@@ -1,4 +1,23 @@
+/* futimesat basic tests.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
 #include <dirent.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -7,19 +26,19 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
+#include <support/test-driver.h>
+#include <support/temp_file.h>
 
-static void prepare (void);
-#define PREPARE(argc, argv) prepare ()
-
-static int do_test (void);
-#define TEST_FUNCTION do_test ()
-
-#include "../test-skeleton.c"
+#ifndef struct_stat
+# define struct_stat struct stat64
+# define fstat       fstat64
+# define fstatat     fstatat64
+#endif
 
 static int dir_fd;
 
 static void
-prepare (void)
+prepare (int argc, char *argv[])
 {
   size_t test_dir_len = strlen (test_dir);
   static const char dir_name[] = "/tst-futimesat.XXXXXX";
@@ -48,7 +67,7 @@ prepare (void)
       exit (1);
     }
 }
-
+#define PREPARE prepare
 
 static int
 do_test (void)
@@ -98,8 +117,8 @@ do_test (void)
   write (fd, "hello", 5);
   puts ("file created");
 
-  struct stat64 st1;
-  if (fstat64 (fd, &st1) != 0)
+  struct_stat st1;
+  if (fstat (fd, &st1) != 0)
     {
       puts ("fstat64 failed");
       return 1;
@@ -118,8 +137,8 @@ do_test (void)
       return 1;
     }
 
-  struct stat64 st2;
-  if (fstatat64 (dir_fd, "some-file", &st2, 0) != 0)
+  struct_stat st2;
+  if (fstatat (dir_fd, "some-file", &st2, 0) != 0)
     {
       puts ("fstatat64 failed");
       return 1;
@@ -146,3 +165,5 @@ do_test (void)
 
   return 0;
 }
+
+#include <support/test-driver.c>
diff --git a/io/tst-stat-time64.c b/io/tst-stat-time64.c
new file mode 100644
index 0000000000..c10fe1284a
--- /dev/null
+++ b/io/tst-stat-time64.c
@@ -0,0 +1,102 @@
+/* Basic test of stat with 64 bit time_t interfaces.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+
+/* The idea of the test is check whether the 64 bit time_t stat implementation
+   returns the expected value for comparable fields, so it does not really
+   matter whether statx uses a fallback implementation or not.  */
+
+static void
+stat_check (int fd, const char *path, struct stat *st)
+{
+  TEST_COMPARE (stat (path, st), 0);
+}
+
+static void
+lstat_check (int fd, const char *path, struct stat *st)
+{
+  TEST_COMPARE (lstat (path, st), 0);
+}
+
+static void
+fstat_check (int fd, const char *path, struct stat *st)
+{
+  TEST_COMPARE (fstat (fd, st), 0);
+}
+
+static void
+fstatat_check (int fd, const char *path, struct stat *st)
+{
+  TEST_COMPARE (fstatat (fd, path, st, 0), 0);
+}
+
+typedef void (*test_t)(int, const char *path, struct stat *);
+
+static int
+do_test (void)
+{
+  char *path;
+  int fd = create_temp_file ("tst-statx-", &path);
+  TEST_VERIFY_EXIT (fd >= 0);
+  support_write_file_string (path, "abc");
+
+  struct statx stx;
+  TEST_COMPARE (statx (fd, path, 0, STATX_BASIC_STATS, &stx), 0);
+
+  for (test_t *test = (test_t[]) { stat_check, lstat_check, fstat_check,
+				   fstatat_check, NULL };
+       *test != NULL; test++)
+  {
+    struct stat st;
+    (*test) (fd, path, &st);
+
+    TEST_COMPARE (stx.stx_dev_major, major (st.st_dev));
+    TEST_COMPARE (stx.stx_dev_minor, minor (st.st_dev));
+    TEST_COMPARE (stx.stx_ino, st.st_ino);
+    TEST_COMPARE (stx.stx_mode, st.st_mode);
+    TEST_COMPARE (stx.stx_nlink, st.st_nlink);
+    TEST_COMPARE (stx.stx_uid, st.st_uid);
+    TEST_COMPARE (stx.stx_gid, st.st_gid);
+    TEST_COMPARE (stx.stx_rdev_major, major (st.st_rdev));
+    TEST_COMPARE (stx.stx_rdev_minor, minor (st.st_rdev));
+    TEST_COMPARE (stx.stx_blksize, st.st_blksize);
+    TEST_COMPARE (stx.stx_blocks, st.st_blocks);
+
+    TEST_COMPARE (stx.stx_ctime.tv_sec, st.st_ctim.tv_sec);
+    TEST_COMPARE (stx.stx_ctime.tv_nsec, st.st_ctim.tv_nsec);
+    TEST_COMPARE (stx.stx_mtime.tv_sec, st.st_mtim.tv_sec);
+    TEST_COMPARE (stx.stx_mtime.tv_nsec, st.st_mtim.tv_nsec);
+  }
+
+  xclose (fd);
+  free (path);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/io/tst-utimensat-time64.c b/io/tst-utimensat-time64.c
new file mode 100644
index 0000000000..7ac7d8df1d
--- /dev/null
+++ b/io/tst-utimensat-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-utimensat.c"
diff --git a/misc/Makefile b/misc/Makefile
index cfc15355d6..a8363d4b76 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -90,6 +90,8 @@ tests := tst-dirname tst-tsearch tst-fdset tst-mntent tst-hsearch \
 	 tst-ldbl-warn tst-ldbl-error tst-dbl-efgcvt tst-ldbl-efgcvt \
 	 tst-mntent-autofs tst-syscalls tst-mntent-escape
 
+tests-time64 := tst-pselect-time64
+
 # Tests which need libdl.
 ifeq (yes,$(build-shared))
 tests += tst-gethostid
diff --git a/misc/tst-pselect-time64.c b/misc/tst-pselect-time64.c
new file mode 100644
index 0000000000..15a1e49292
--- /dev/null
+++ b/misc/tst-pselect-time64.c
@@ -0,0 +1 @@
+#include "tst-pselect.c"
diff --git a/nptl/Makefile b/nptl/Makefile
index 33766eaf7a..d1c786e88b 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -380,6 +380,9 @@ xtests = tst-setuid1 tst-setuid1-static tst-setuid2 \
 	tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups \
 	tst-mutexpp5 tst-mutexpp9
 
+tests-time64 := \
+  tst-cancel4_2-time64
+
 # This test can run into task limits because of a linux kernel bug
 # and then cause the make process to fail too, see bug 24537.
 xtests += tst-eintr1
diff --git a/nptl/tst-cancel4_2-time64.c b/nptl/tst-cancel4_2-time64.c
new file mode 100644
index 0000000000..4ac086a312
--- /dev/null
+++ b/nptl/tst-cancel4_2-time64.c
@@ -0,0 +1 @@
+#include "tst-cancel4_2.c"
diff --git a/posix/Makefile b/posix/Makefile
index aba66efde8..e246ff1d14 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -109,7 +109,9 @@ tests-internal	:= bug-regex5 bug-regex20 bug-regex33 \
 		   tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 \
 		   tst-glob_lstat_compat tst-spawn4-compat
 tests-container := bug-ga2
+tests-time64	:= tst-wait4-time64 tst-wait3-time64 tst-gnuglob64-time64
 xtests		:= tst-getaddrinfo4 tst-getaddrinfo5 tst-sched_rr_get_interval
+xtests-time64	:= tst-sched_rr_get_interval-time64
 ifeq (yes,$(build-shared))
 test-srcs	:= globtest
 tests           += wordexp-test tst-exec tst-spawn tst-spawn2 tst-spawn3
diff --git a/posix/tst-gnuglob64-time64.c b/posix/tst-gnuglob64-time64.c
new file mode 100644
index 0000000000..00922bcdc6
--- /dev/null
+++ b/posix/tst-gnuglob64-time64.c
@@ -0,0 +1,7 @@
+#define GLOB_FUNC glob
+#define GLOB_TYPE glob_t
+#define GLOBFREE_FUNC globfree
+#define DIRENT_STRUCT dirent
+#define STAT_STRUCT stat
+
+#include "tst-gnuglob-skeleton.c"
diff --git a/posix/tst-sched_rr_get_interval-time64.c b/posix/tst-sched_rr_get_interval-time64.c
new file mode 100644
index 0000000000..f4e66d2939
--- /dev/null
+++ b/posix/tst-sched_rr_get_interval-time64.c
@@ -0,0 +1 @@
+#include "tst-sched_rr_get_interval.c"
diff --git a/posix/tst-wait3-time64.c b/posix/tst-wait3-time64.c
new file mode 100644
index 0000000000..2837bc7a9e
--- /dev/null
+++ b/posix/tst-wait3-time64.c
@@ -0,0 +1 @@
+#include "tst-wait3.c"
diff --git a/posix/tst-wait4-time64.c b/posix/tst-wait4-time64.c
new file mode 100644
index 0000000000..12543b270f
--- /dev/null
+++ b/posix/tst-wait4-time64.c
@@ -0,0 +1 @@
+#include "tst-wait4.c"
diff --git a/rt/Makefile b/rt/Makefile
index 7b374f2073..3ce98297f9 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -49,6 +49,15 @@ tests := tst-shm tst-timer tst-timer2 \
 	 tst-shm-cancel
 tests-internal := tst-timer-sigmask
 
+tests-time64 := \
+  tst-aio6-time64 \
+  tst-cpuclock2-time64 \
+  tst-mqueue1-time64 \
+  tst-mqueue2-time64 \
+  tst-mqueue4-time64 \
+  tst-mqueue8-time64 \
+  tst-timer4-time64
+
 extra-libs := librt
 extra-libs-others := $(extra-libs)
 
diff --git a/rt/tst-aio6-time64.c b/rt/tst-aio6-time64.c
new file mode 100644
index 0000000000..a386a577ec
--- /dev/null
+++ b/rt/tst-aio6-time64.c
@@ -0,0 +1 @@
+#include "tst-aio6.c"
diff --git a/rt/tst-cpuclock2-time64.c b/rt/tst-cpuclock2-time64.c
new file mode 100644
index 0000000000..05775522bb
--- /dev/null
+++ b/rt/tst-cpuclock2-time64.c
@@ -0,0 +1 @@
+#include "tst-cpuclock2.c"
diff --git a/rt/tst-cpuclock2.c b/rt/tst-cpuclock2.c
index c1c7ed2ad8..eebc3609d0 100644
--- a/rt/tst-cpuclock2.c
+++ b/rt/tst-cpuclock2.c
@@ -21,7 +21,11 @@
 
 #if (_POSIX_THREADS - 0) <= 0
 
-# define TEST_FUNCTION 0
+static int
+do_test ()
+{
+  return 0;
+}
 
 #else
 
@@ -330,7 +334,6 @@ do_test (void)
 
   return result;
 }
-# define TEST_FUNCTION do_test ()
 #endif
 
-#include "../test-skeleton.c"
+#include <support/test-driver.c>
diff --git a/rt/tst-mqueue1-time64.c b/rt/tst-mqueue1-time64.c
new file mode 100644
index 0000000000..9c600a9a97
--- /dev/null
+++ b/rt/tst-mqueue1-time64.c
@@ -0,0 +1 @@
+#include "tst-mqueue1.c"
diff --git a/rt/tst-mqueue2-time64.c b/rt/tst-mqueue2-time64.c
new file mode 100644
index 0000000000..9d49f0b196
--- /dev/null
+++ b/rt/tst-mqueue2-time64.c
@@ -0,0 +1 @@
+#include "tst-mqueue2.c"
diff --git a/rt/tst-mqueue4-time64.c b/rt/tst-mqueue4-time64.c
new file mode 100644
index 0000000000..c23a228dc4
--- /dev/null
+++ b/rt/tst-mqueue4-time64.c
@@ -0,0 +1 @@
+#include "tst-mqueue4.c"
diff --git a/rt/tst-mqueue8-time64.c b/rt/tst-mqueue8-time64.c
new file mode 100644
index 0000000000..972637f7f5
--- /dev/null
+++ b/rt/tst-mqueue8-time64.c
@@ -0,0 +1 @@
+#include "tst-mqueue8.c"
diff --git a/rt/tst-timer4-time64.c b/rt/tst-timer4-time64.c
new file mode 100644
index 0000000000..e47a593f10
--- /dev/null
+++ b/rt/tst-timer4-time64.c
@@ -0,0 +1 @@
+#include "tst-timer4.c"
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index 53b65ef349..31df6f97e5 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -109,6 +109,16 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
 	 tst-unwind-thread \
 	 tst-pt-vfork1 tst-pt-vfork2 tst-vfork1x tst-vfork2x \
 
+tests-time64 := \
+  tst-abstime-time64 \
+  tst-cnd-timedwait-time64 \
+  tst-cond11-time64 \
+  tst-join14-time64 \
+  tst-mtx-timedlock-time64 \
+  tst-rwlock14-time64 \
+  tst-sem5-time64 \
+  tst-thrd-sleep-time64 \
+
 
 # Files which must not be linked with libpthread.
 tests-nolibpthread = tst-unload
diff --git a/sysdeps/pthread/tst-abstime-time64.c b/sysdeps/pthread/tst-abstime-time64.c
new file mode 100644
index 0000000000..2fc77cb365
--- /dev/null
+++ b/sysdeps/pthread/tst-abstime-time64.c
@@ -0,0 +1 @@
+#include "tst-abstime.c"
diff --git a/sysdeps/pthread/tst-cnd-timedwait-time64.c b/sysdeps/pthread/tst-cnd-timedwait-time64.c
new file mode 100644
index 0000000000..9b2abfd277
--- /dev/null
+++ b/sysdeps/pthread/tst-cnd-timedwait-time64.c
@@ -0,0 +1 @@
+#include "tst-cnd-timedwait.c"
diff --git a/sysdeps/pthread/tst-cond11-time64.c b/sysdeps/pthread/tst-cond11-time64.c
new file mode 100644
index 0000000000..9bccb8ec8b
--- /dev/null
+++ b/sysdeps/pthread/tst-cond11-time64.c
@@ -0,0 +1 @@
+#include "tst-cond11.c"
diff --git a/sysdeps/pthread/tst-join14-time64.c b/sysdeps/pthread/tst-join14-time64.c
new file mode 100644
index 0000000000..bed784ee24
--- /dev/null
+++ b/sysdeps/pthread/tst-join14-time64.c
@@ -0,0 +1 @@
+#include "tst-join14.c"
diff --git a/sysdeps/pthread/tst-mtx-timedlock-time64.c b/sysdeps/pthread/tst-mtx-timedlock-time64.c
new file mode 100644
index 0000000000..b3393c99ef
--- /dev/null
+++ b/sysdeps/pthread/tst-mtx-timedlock-time64.c
@@ -0,0 +1 @@
+#include "tst-mtx-timedlock.c"
diff --git a/sysdeps/pthread/tst-rwlock14-time64.c b/sysdeps/pthread/tst-rwlock14-time64.c
new file mode 100644
index 0000000000..ae9b1912cf
--- /dev/null
+++ b/sysdeps/pthread/tst-rwlock14-time64.c
@@ -0,0 +1 @@
+#include "tst-rwlock14.c"
diff --git a/sysdeps/pthread/tst-sem5-time64.c b/sysdeps/pthread/tst-sem5-time64.c
new file mode 100644
index 0000000000..89c2a14f94
--- /dev/null
+++ b/sysdeps/pthread/tst-sem5-time64.c
@@ -0,0 +1 @@
+#include "tst-sem5.c"
diff --git a/sysdeps/pthread/tst-thrd-sleep-time64.c b/sysdeps/pthread/tst-thrd-sleep-time64.c
new file mode 100644
index 0000000000..02837bd19f
--- /dev/null
+++ b/sysdeps/pthread/tst-thrd-sleep-time64.c
@@ -0,0 +1 @@
+#include "tst-thrd-sleep.c"
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index fc2a17307c..94ee85d124 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -115,6 +115,14 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
 	 tst-futimes tst-lutimes
 
 tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc
+tests-time64 += \
+  tst-futimes-time64\
+  tst-futimens-time64 \
+  tst-lutimes-time64 \
+  tst-ppoll-time64 \
+  tst-utime-time64 \
+  tst-utimes-time64 \
+  tst-timerfd-time64
 
 CFLAGS-tst-sigcontext-get_pc.c = -fasynchronous-unwind-tables
 
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index b53391f613..982b94e625 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -237,7 +237,9 @@ libc {
     __timegm64;
     __timespec_get64;
     __utimensat64;
-     __utimes64;
+    __utimes64;
+    __localtime64;
+    __localtime64_r;
     # misc
     __ntp_gettime64;
     __ntp_gettimex64;
diff --git a/sysdeps/unix/sysv/linux/tst-futimens-time64.c b/sysdeps/unix/sysv/linux/tst-futimens-time64.c
new file mode 100644
index 0000000000..88fcb38489
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-futimens-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-futimens.c"
diff --git a/sysdeps/unix/sysv/linux/tst-futimens.c b/sysdeps/unix/sysv/linux/tst-futimens.c
index 8f48cfee63..b5b240abf1 100644
--- a/sysdeps/unix/sysv/linux/tst-futimens.c
+++ b/sysdeps/unix/sysv/linux/tst-futimens.c
@@ -24,10 +24,14 @@
 #include <support/xunistd.h>
 #include <support/temp_file.h>
 
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
 static int temp_fd = -1;
 
 /* struct timespec array with Y2038 threshold minus 2 and 1 seconds.  */
-const struct timespec t1[2] = { { 0x7FFFFFFE, 0 },  { 0x7FFFFFFF, 0 } };
+const static struct timespec t1[2] = { { 0x7FFFFFFE, 0 },  { 0x7FFFFFFF, 0 } };
 
 /* struct timespec array with Y2038 threshold plus 1 and 2 seconds.  */
 const struct timespec t2[2] = { { 0x80000001ULL, 0 },  { 0x80000002ULL, 0 } };
@@ -46,7 +50,7 @@ do_prepare (int argc, char *argv[])
 static int
 test_futimens_helper (const struct timespec *ts)
 {
-  struct stat64 st;
+  struct_stat st;
   int result;
   time_t t;
 
diff --git a/sysdeps/unix/sysv/linux/tst-futimes-time64.c b/sysdeps/unix/sysv/linux/tst-futimes-time64.c
new file mode 100644
index 0000000000..d489c265d1
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-futimes-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-futimes.c"
diff --git a/sysdeps/unix/sysv/linux/tst-lutimes-time64.c b/sysdeps/unix/sysv/linux/tst-lutimes-time64.c
new file mode 100644
index 0000000000..06caec0a91
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-lutimes-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-lutimes.c"
diff --git a/sysdeps/unix/sysv/linux/tst-ppoll-time64.c b/sysdeps/unix/sysv/linux/tst-ppoll-time64.c
new file mode 100644
index 0000000000..96ee2faee3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-ppoll-time64.c
@@ -0,0 +1 @@
+#include "tst-ppoll.c"
diff --git a/sysdeps/unix/sysv/linux/tst-timerfd-time64.c b/sysdeps/unix/sysv/linux/tst-timerfd-time64.c
new file mode 100644
index 0000000000..bb17f48139
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-timerfd-time64.c
@@ -0,0 +1 @@
+#include "tst-timerfd.c"
diff --git a/sysdeps/unix/sysv/linux/tst-utime-time64.c b/sysdeps/unix/sysv/linux/tst-utime-time64.c
new file mode 100644
index 0000000000..eb62f59126
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-utime-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-utime.c"
diff --git a/sysdeps/unix/sysv/linux/tst-utime.c b/sysdeps/unix/sysv/linux/tst-utime.c
index 6735421657..d413f130e8 100644
--- a/sysdeps/unix/sysv/linux/tst-utime.c
+++ b/sysdeps/unix/sysv/linux/tst-utime.c
@@ -26,6 +26,10 @@
 #include <support/xunistd.h>
 #include <support/temp_file.h>
 
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
 static int temp_fd = -1;
 char *testfile;
 
@@ -49,7 +53,7 @@ do_prepare (int argc, char *argv[])
 static int
 test_utime_helper (const struct utimbuf *ut)
 {
-  struct stat64 st;
+  struct_stat st;
   int result;
   time_t t;
 
diff --git a/sysdeps/unix/sysv/linux/tst-utimes-time64.c b/sysdeps/unix/sysv/linux/tst-utimes-time64.c
new file mode 100644
index 0000000000..234ec02541
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-utimes-time64.c
@@ -0,0 +1,2 @@
+#define struct_stat struct stat
+#include "tst-utimes.c"
diff --git a/sysdeps/unix/sysv/linux/tst-utimes.c b/sysdeps/unix/sysv/linux/tst-utimes.c
index 8c7b006a22..c521c89dfa 100644
--- a/sysdeps/unix/sysv/linux/tst-utimes.c
+++ b/sysdeps/unix/sysv/linux/tst-utimes.c
@@ -25,6 +25,10 @@
 #include <support/xunistd.h>
 #include <support/temp_file.h>
 
+#ifndef struct_stat
+# define struct_stat struct stat64
+#endif
+
 static int temp_fd = -1;
 char *testfile;
 
@@ -50,7 +54,7 @@ do_prepare (int argc, char *argv[])
 static int
 test_utime_helper (const struct timeval *tv)
 {
-  struct stat64 st;
+  struct_stat st;
   int result;
   time_t t;
 
diff --git a/sysvipc/Makefile b/sysvipc/Makefile
index a534791928..86911803b5 100644
--- a/sysvipc/Makefile
+++ b/sysvipc/Makefile
@@ -32,6 +32,8 @@ routines := ftok \
 
 tests    := test-sysvmsg test-sysvsem test-sysvshm
 
+tests-time64 := test-sysvmsg-time64 test-sysvsem-time64 test-sysvshm-time64
+
 include ../Rules
 
 CFLAGS-msgrcv.c += -fexceptions -fasynchronous-unwind-tables
diff --git a/sysvipc/test-sysvmsg-time64.c b/sysvipc/test-sysvmsg-time64.c
new file mode 100644
index 0000000000..c23e0c337e
--- /dev/null
+++ b/sysvipc/test-sysvmsg-time64.c
@@ -0,0 +1 @@
+#include "test-sysvmsg.c"
diff --git a/sysvipc/test-sysvsem-time64.c b/sysvipc/test-sysvsem-time64.c
new file mode 100644
index 0000000000..05c95068cd
--- /dev/null
+++ b/sysvipc/test-sysvsem-time64.c
@@ -0,0 +1 @@
+#include "test-sysvsem.c"
diff --git a/sysvipc/test-sysvshm-time64.c b/sysvipc/test-sysvshm-time64.c
new file mode 100644
index 0000000000..8e2963f563
--- /dev/null
+++ b/sysvipc/test-sysvshm-time64.c
@@ -0,0 +1 @@
+#include "test-sysvshm.c"
diff --git a/time/Makefile b/time/Makefile
index f14022b334..fee206d3c7 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -51,6 +51,21 @@ tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
 	   tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-itimer \
 	   tst-gmtime tst-timegm tst-timespec_get
 
+tests-time64 := \
+  tst-adjtime-time64 \
+  tst-clock-time64 \
+  tst-clock2-time64 \
+  tst-clock_nanosleep-time64 \
+  tst-cpuclock1-time64 \
+  tst-ctime-time64 \
+  tst-difftime-time64 \
+  tst-gmtime-time64 \
+  tst-itimer-time64 \
+  tst-mktime4-time64 \
+  tst-timegm-time64 \
+  tst-timespec_get-time64 \
+  tst-y2039-time64
+
 include ../Rules
 
 ifeq ($(run-built-tests),yes)
diff --git a/time/tst-adjtime-time64.c b/time/tst-adjtime-time64.c
new file mode 100644
index 0000000000..097d6efc4b
--- /dev/null
+++ b/time/tst-adjtime-time64.c
@@ -0,0 +1 @@
+#include <tst-adjtime.c>
diff --git a/time/tst-clock-time64.c b/time/tst-clock-time64.c
new file mode 100644
index 0000000000..a1349678c8
--- /dev/null
+++ b/time/tst-clock-time64.c
@@ -0,0 +1 @@
+#include "tst-clock.c"
diff --git a/time/tst-clock2-time64.c b/time/tst-clock2-time64.c
new file mode 100644
index 0000000000..897f47b287
--- /dev/null
+++ b/time/tst-clock2-time64.c
@@ -0,0 +1 @@
+#include "tst-clock2.c"
diff --git a/time/tst-clock_nanosleep-time64.c b/time/tst-clock_nanosleep-time64.c
new file mode 100644
index 0000000000..c8638aa3d2
--- /dev/null
+++ b/time/tst-clock_nanosleep-time64.c
@@ -0,0 +1 @@
+#include "tst-clock_nanosleep.c"
diff --git a/time/tst-cpuclock1-time64.c b/time/tst-cpuclock1-time64.c
new file mode 100644
index 0000000000..5a7ffa27ac
--- /dev/null
+++ b/time/tst-cpuclock1-time64.c
@@ -0,0 +1 @@
+#include "tst-cpuclock1.c"
diff --git a/time/tst-ctime-time64.c b/time/tst-ctime-time64.c
new file mode 100644
index 0000000000..24a5ae98ed
--- /dev/null
+++ b/time/tst-ctime-time64.c
@@ -0,0 +1 @@
+#include "tst-ctime.c"
diff --git a/time/tst-ctime.c b/time/tst-ctime.c
index e89a906bf8..884d69bfa0 100644
--- a/time/tst-ctime.c
+++ b/time/tst-ctime.c
@@ -24,6 +24,7 @@ static int
 do_test (void)
 {
   char *str;
+  char strb[32];
   time_t t;
 
   /* Use glibc time zone extension "TZ=:" to to guarantee that UTC
@@ -36,11 +37,21 @@ do_test (void)
   str = ctime (&t);
   TEST_COMPARE_STRING (str, "Thu Jan  1 00:00:00 1970\n");
 
+  /* Same as before but with ctime_r.  */
+  str = ctime_r (&t, strb);
+  TEST_VERIFY (str == strb);
+  TEST_COMPARE_STRING (str, "Thu Jan  1 00:00:00 1970\n");
+
   /* Check if the max time value for 32 bit time_t can be converted.  */
   t = 0x7fffffff;
   str = ctime (&t);
   TEST_COMPARE_STRING (str, "Tue Jan 19 03:14:07 2038\n");
 
+  /* Same as before but with ctime_r.  */
+  str = ctime_r (&t, strb);
+  TEST_VERIFY (str == strb);
+  TEST_COMPARE_STRING (str, "Tue Jan 19 03:14:07 2038\n");
+
   /* Check if we run on port with 32 bit time_t size */
   time_t tov;
   if (__builtin_add_overflow (t, 1, &tov))
@@ -50,6 +61,11 @@ do_test (void)
   str = ctime (&tov);
   TEST_COMPARE_STRING (str, "Tue Jan 19 03:14:08 2038\n");
 
+  /* Same as before but with ctime_r.  */
+  str = ctime_r (&tov, strb);
+  TEST_VERIFY (str == strb);
+  TEST_COMPARE_STRING (str, "Tue Jan 19 03:14:08 2038\n");
+
   return 0;
 }
 
diff --git a/time/tst-difftime-time64.c b/time/tst-difftime-time64.c
new file mode 100644
index 0000000000..751ce6c483
--- /dev/null
+++ b/time/tst-difftime-time64.c
@@ -0,0 +1 @@
+#include "tst-difftime.c"
diff --git a/time/tst-gmtime-time64.c b/time/tst-gmtime-time64.c
new file mode 100644
index 0000000000..0df11c1913
--- /dev/null
+++ b/time/tst-gmtime-time64.c
@@ -0,0 +1 @@
+#include "tst-gmtime.c"
diff --git a/time/tst-itimer-time64.c b/time/tst-itimer-time64.c
new file mode 100644
index 0000000000..ddd2efa175
--- /dev/null
+++ b/time/tst-itimer-time64.c
@@ -0,0 +1 @@
+#include <time/tst-itimer.c>
diff --git a/time/tst-mktime4-time64.c b/time/tst-mktime4-time64.c
new file mode 100644
index 0000000000..bf5197c6f3
--- /dev/null
+++ b/time/tst-mktime4-time64.c
@@ -0,0 +1 @@
+#include "tst-mktime4.c"
diff --git a/time/tst-timegm-time64.c b/time/tst-timegm-time64.c
new file mode 100644
index 0000000000..8e3084f74e
--- /dev/null
+++ b/time/tst-timegm-time64.c
@@ -0,0 +1 @@
+#include "tst-timegm.c"
diff --git a/time/tst-timespec_get-time64.c b/time/tst-timespec_get-time64.c
new file mode 100644
index 0000000000..48f336385d
--- /dev/null
+++ b/time/tst-timespec_get-time64.c
@@ -0,0 +1 @@
+#include "tst-timespec_get.c"
diff --git a/time/tst-y2039-time64.c b/time/tst-y2039-time64.c
new file mode 100644
index 0000000000..3c8a504186
--- /dev/null
+++ b/time/tst-y2039-time64.c
@@ -0,0 +1 @@
+#include "tst-y2039.c"
diff --git a/time/tst-y2039.c b/time/tst-y2039.c
index ef024c0a77..66a22d4c2c 100644
--- a/time/tst-y2039.c
+++ b/time/tst-y2039.c
@@ -37,6 +37,16 @@ do_test (void)
 			> 0);
       puts (buf);
       TEST_VERIFY (strcmp (buf, "2039-04-30 14:00:00 PDT") == 0);
+
+      /* Same as before but for localtime_r.  */
+      struct tm tmd;
+      tm = localtime_r (&ouch, &tmd);
+      TEST_VERIFY_EXIT (tm == &tmd);
+
+      TEST_VERIFY_EXIT (strftime (buf, sizeof buf, "%Y-%m-%d %H:%M:%S %Z", tm)
+			> 0);
+      puts (buf);
+      TEST_VERIFY (strcmp (buf, "2039-04-30 14:00:00 PDT") == 0);
     }
   else
     FAIL_UNSUPPORTED ("32-bit time_t");
