0003-date-Use-64-prefix-syscall-if-we-have-to.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 29ba834ed7d968de0460f7fd87156d43d8120d8f Mon Sep 17 00:00:00 2001
  2. From: Alistair Francis <alistair.francis@wdc.com>
  3. Date: Wed, 18 Sep 2019 09:28:49 -0700
  4. Subject: [PATCH] date: Use 64 prefix syscall if we have to
  5. Some 32-bit architectures no longer have the 32-bit time_t syscalls.
  6. Instead they have suffixed syscalls that returns a 64-bit time_t. If
  7. the architecture doesn't have the non-suffixed syscall and is using a
  8. 64-bit time_t let's use the suffixed syscall instead.
  9. This fixes build issues when building for RISC-V 32-bit with 5.1+ kernel
  10. headers.
  11. If an architecture only supports the suffixed syscalls, but is still
  12. using a 32-bit time_t fall back to the libc call.
  13. Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  14. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
  15. (cherry picked from commit b7b7452f292f03eefafa6fd1da9bcfc933dee15a)
  16. Signed-off-by: Carlos Santos <unixmania@gmail.com>
  17. ---
  18. coreutils/date.c | 11 +++++++++--
  19. 1 file changed, 9 insertions(+), 2 deletions(-)
  20. diff --git a/coreutils/date.c b/coreutils/date.c
  21. index 3414d38ae..1e0a675ca 100644
  22. --- a/coreutils/date.c
  23. +++ b/coreutils/date.c
  24. @@ -36,7 +36,7 @@
  25. //config:# defaults to "no": stat's nanosecond field is a bit non-portable
  26. //config:config FEATURE_DATE_NANO
  27. //config: bool "Support %[num]N nanosecond format specifier"
  28. -//config: default n # syscall(__NR_clock_gettime)
  29. +//config: default n # syscall(__NR_clock_gettime) or syscall(__NR_clock_gettime64)
  30. //config: depends on DATE
  31. //config: select PLATFORM_LINUX
  32. //config: help
  33. @@ -271,10 +271,17 @@ int date_main(int argc UNUSED_PARAM, char **argv)
  34. */
  35. #endif
  36. } else {
  37. -#if ENABLE_FEATURE_DATE_NANO
  38. +#if ENABLE_FEATURE_DATE_NANO && defined(__NR_clock_gettime)
  39. /* libc has incredibly messy way of doing this,
  40. * typically requiring -lrt. We just skip all this mess */
  41. syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
  42. +#elif ENABLE_FEATURE_DATE_NANO && __TIMESIZE == 64
  43. + /* Let's only support the 64 suffix syscalls for 64-bit time_t.
  44. + * This simplifies the code for us as we don't need to convert
  45. + * between 64-bit and 32-bit. We also don't have a way to
  46. + * report overflow errors here.
  47. + */
  48. + syscall(__NR_clock_gettime64, CLOCK_REALTIME, &ts);
  49. #else
  50. time(&ts.tv_sec);
  51. #endif
  52. --
  53. 2.18.2