You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.7 KiB

  1. From b83524b19ca6e5e58dded77fad37f17a177766ff Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <cotequeiroz@gmail.com>
  3. Date: Fri, 8 Oct 2021 14:39:52 -0300
  4. Subject: [PATCH 1/2] Avoid problems with 64-bit time_t
  5. The clock_gettime() calls are being handled by calling
  6. syscall(__NR_clock_gettime, ...), which is not portable between systems
  7. using 32-bit and 64-bit time_t. This is being done to avoid having to
  8. link agains librt.
  9. So, use the standard function, and add a test to see if we can compile
  10. a test without the library, including it otherwise.
  11. Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
  12. --- a/Makefile.flags
  13. +++ b/Makefile.flags
  14. @@ -124,6 +124,12 @@ CFLAGS += --sysroot=$(CONFIG_SYSROOT)
  15. export SYSROOT=$(CONFIG_SYSROOT)
  16. endif
  17. +# glibc versions before 2.17 need to link with -rt to use clock_gettime
  18. +RT_NEEDED := $(shell echo -e '#include <time.h>\nint main(void){struct timespec tp; return clock_gettime(CLOCK_MONOTONIC, &tp);}' >rttest.c; $(CC) $(CFLAGS) -o /dev/null rttest.c >/dev/null 2>&1 || echo "y"; rm rttest.c)
  19. +ifeq ($(RT_NEEDED),y)
  20. +LDLIBS += rt
  21. +endif
  22. +
  23. # Android has no separate crypt library
  24. # gcc-4.2.1 fails if we try to feed C source on stdin:
  25. # echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
  26. --- a/coreutils/date.c
  27. +++ b/coreutils/date.c
  28. @@ -37,7 +37,7 @@
  29. //config:config FEATURE_DATE_NANO
  30. //config: bool "Support %[num]N nanosecond format specifier"
  31. //config: default n
  32. -//config: depends on DATE # syscall(__NR_clock_gettime)
  33. +//config: depends on DATE # clock_gettime()
  34. //config: select PLATFORM_LINUX
  35. //config: help
  36. //config: Support %[num]N format specifier. Adds ~250 bytes of code.
  37. @@ -265,9 +265,7 @@ int date_main(int argc UNUSED_PARAM, cha
  38. #endif
  39. } else {
  40. #if ENABLE_FEATURE_DATE_NANO
  41. - /* libc has incredibly messy way of doing this,
  42. - * typically requiring -lrt. We just skip all this mess */
  43. - syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
  44. + clock_gettime(CLOCK_REALTIME, &ts);
  45. #else
  46. time(&ts.tv_sec);
  47. #endif
  48. --- a/libbb/time.c
  49. +++ b/libbb/time.c
  50. @@ -243,7 +243,7 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(
  51. * typically requiring -lrt. We just skip all this mess */
  52. static void get_mono(struct timespec *ts)
  53. {
  54. - if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts))
  55. + if (clock_gettime(CLOCK_MONOTONIC, ts))
  56. bb_error_msg_and_die("clock_gettime(MONOTONIC) failed");
  57. }
  58. unsigned long long FAST_FUNC monotonic_ns(void)
  59. --- a/runit/runsv.c
  60. +++ b/runit/runsv.c
  61. @@ -55,7 +55,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAG
  62. * typically requiring -lrt. We just skip all this mess */
  63. static void gettimeofday_ns(struct timespec *ts)
  64. {
  65. - syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
  66. + clock_gettime(CLOCK_REALTIME, ts);
  67. }
  68. #else
  69. static void gettimeofday_ns(struct timespec *ts)