From 1972341ab1369233c55bd10762117b405e1fbfa9 Mon Sep 17 00:00:00 2001 From: Faraz Shahbazker Date: Thu, 8 Aug 2024 15:22:40 +0800 Subject: [PATCH] [Y2K38] Support 64-bit time_t as a multilib in headers and libraries The header definition of time_t changes depending on whether __nanomips_64bit_time_t__ is defined. The compiler is expected to define this macro when compiling for 64-bit time_t. Change-Id: I8358cd9666071fac46b6e396b14ec9bd7d3d9eb7 --- libgloss/mips/uhi/uhi_fstat.c | 17 +++++++++++++++-- libgloss/mips/uhi/yamon_fstat.c | 19 ++++++++++++++++--- newlib/libc/include/sys/config.h | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libgloss/mips/uhi/uhi_fstat.c b/libgloss/mips/uhi/uhi_fstat.c index d097af78c2..56dbb3da0b 100644 --- a/libgloss/mips/uhi/uhi_fstat.c +++ b/libgloss/mips/uhi/uhi_fstat.c @@ -97,7 +97,6 @@ fstat (int file, struct stat *sbuf) __check (__LINE__, offsetof (struct stat, st_blocks) == 80); __check (__LINE__, offsetof (struct stat, st_spare4) == 88); #else - __check (__LINE__, sizeof (struct stat) == 60); __check (__LINE__, offsetof (struct stat, st_dev) == 0); __check (__LINE__, offsetof (struct stat, st_ino) == 2); __check (__LINE__, offsetof (struct stat, st_mode) == 4); @@ -105,7 +104,8 @@ fstat (int file, struct stat *sbuf) __check (__LINE__, offsetof (struct stat, st_uid) == 10); __check (__LINE__, offsetof (struct stat, st_gid) == 12); __check (__LINE__, offsetof (struct stat, st_rdev) == 14); - __check (__LINE__, offsetof (struct stat, st_size) == 16); +#ifdef _USE_LONG_TIME_T + __check (__LINE__, sizeof (struct stat) == 60); __check (__LINE__, offsetof (struct stat, st_atim) == 20); // __check (__LINE__, offsetof (struct stat, st_spare1) == 24); __check (__LINE__, offsetof (struct stat, st_mtim) == 28); @@ -115,6 +115,19 @@ fstat (int file, struct stat *sbuf) __check (__LINE__, offsetof (struct stat, st_blksize) == 44); __check (__LINE__, offsetof (struct stat, st_blocks) == 48); __check (__LINE__, offsetof (struct stat, st_spare4) == 52); +#else // Using 64-bit time_t + __check (__LINE__, sizeof (struct stat) == 88); + __check (__LINE__, offsetof (struct stat, st_size) == 16); + __check (__LINE__, offsetof (struct stat, st_atim) == 24); + // __check (__LINE__, offsetof (struct stat, st_spare1) == 32); + __check (__LINE__, offsetof (struct stat, st_mtim) == 40); + //__check (__LINE__, offsetof (struct stat, st_spare2) == 48); + __check (__LINE__, offsetof (struct stat, st_ctim) == 56); + //__check (__LINE__, offsetof (struct stat, st_spare3) == 64); + __check (__LINE__, offsetof (struct stat, st_blksize) == 72); + __check (__LINE__, offsetof (struct stat, st_blocks) == 76); + __check (__LINE__, offsetof (struct stat, st_spare4) == 80); +#endif #endif __asm__ __volatile__ (" # %0,%1 = fstat(%2, %3) op=%4\n" diff --git a/libgloss/mips/uhi/yamon_fstat.c b/libgloss/mips/uhi/yamon_fstat.c index e107248652..742f080919 100644 --- a/libgloss/mips/uhi/yamon_fstat.c +++ b/libgloss/mips/uhi/yamon_fstat.c @@ -98,7 +98,6 @@ fstat (int file, struct stat *sbuf) __check (__LINE__, offsetof (struct stat, st_blocks) == 80); __check (__LINE__, offsetof (struct stat, st_spare4) == 88); #else - __check (__LINE__, sizeof (struct stat) == 60); __check (__LINE__, offsetof (struct stat, st_dev) == 0); __check (__LINE__, offsetof (struct stat, st_ino) == 2); __check (__LINE__, offsetof (struct stat, st_mode) == 4); @@ -106,9 +105,10 @@ fstat (int file, struct stat *sbuf) __check (__LINE__, offsetof (struct stat, st_uid) == 10); __check (__LINE__, offsetof (struct stat, st_gid) == 12); __check (__LINE__, offsetof (struct stat, st_rdev) == 14); - __check (__LINE__, offsetof (struct stat, st_size) == 16); +#ifdef _USE_LONG_TIME_T + __check (__LINE__, sizeof (struct stat) == 60); __check (__LINE__, offsetof (struct stat, st_atim) == 20); - //__check (__LINE__, offsetof (struct stat, st_spare1) == 24); + // __check (__LINE__, offsetof (struct stat, st_spare1) == 24); __check (__LINE__, offsetof (struct stat, st_mtim) == 28); //__check (__LINE__, offsetof (struct stat, st_spare2) == 32); __check (__LINE__, offsetof (struct stat, st_ctim) == 36); @@ -116,6 +116,19 @@ fstat (int file, struct stat *sbuf) __check (__LINE__, offsetof (struct stat, st_blksize) == 44); __check (__LINE__, offsetof (struct stat, st_blocks) == 48); __check (__LINE__, offsetof (struct stat, st_spare4) == 52); +#else // Using 64-bit time_t + __check (__LINE__, sizeof (struct stat) == 88); + __check (__LINE__, offsetof (struct stat, st_size) == 16); + __check (__LINE__, offsetof (struct stat, st_atim) == 24); + // __check (__LINE__, offsetof (struct stat, st_spare1) == 32); + __check (__LINE__, offsetof (struct stat, st_mtim) == 40); + //__check (__LINE__, offsetof (struct stat, st_spare2) == 48); + __check (__LINE__, offsetof (struct stat, st_ctim) == 56); + //__check (__LINE__, offsetof (struct stat, st_spare3) == 64); + __check (__LINE__, offsetof (struct stat, st_blksize) == 72); + __check (__LINE__, offsetof (struct stat, st_blocks) == 76); + __check (__LINE__, offsetof (struct stat, st_spare4) == 80); +#endif #endif if (file == 0 || file == 1 || file == 2) diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h index c4355f6c13..501a5c93a8 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -290,6 +290,9 @@ #endif #endif +#if defined(__nanomips_64bit_time_t__) +#undef _WANT_USE_LONG_TIME_T +#endif #ifdef _WANT_USE_LONG_TIME_T #ifndef _USE_LONG_TIME_T #define _USE_LONG_TIME_T