From 939e6c9dd365c901351d9b1d68cd1b792e3e6468 Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Mon, 14 Sep 2020 12:32:39 -0400 Subject: [PATCH] [mono] Add proper check for clock_gettime Fixes mono/mono wasm build --- src/mono/configure.ac | 23 ++++++++++++++++++++++- src/mono/mono/utils/mono-time.c | 6 +++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/mono/configure.ac b/src/mono/configure.ac index 24cfa42f05d80..945618a20977e 100644 --- a/src/mono/configure.ac +++ b/src/mono/configure.ac @@ -2254,7 +2254,28 @@ if test x$host_win32 = xno; then [#include ]) dnl hires monotonic clock support - AC_SEARCH_LIBS(clock_gettime, rt) + + # Check for clock_gettime + if test x$target_osx = xyes; then + # On OSX, clock_gettime is only really available on 10.12 or later + # However, it exists as a weak symbol on earlier versions, so hard-code a version check + AC_MONO_APPLE_AVAILABLE(clock_gettime_available, [whether clock_gettime is available on OSX], + [(MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)]) + if test x$clock_gettime_available = xyes; then + AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [clock_gettime]) + fi + else + AC_CHECK_FUNC(clock_gettime, [ + AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [clock_gettime]) + ], [ + # Old glibc (< 2.17) has clock_gettime in librt, so check there too + AC_CHECK_LIB(rt, clock_gettime, [ + AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [clock_gettime]) + LIBS="$LIBS -lrt" + ]) + ]) + fi + AC_CHECK_FUNCS(clock_nanosleep) dnl dynamic loader support diff --git a/src/mono/mono/utils/mono-time.c b/src/mono/mono/utils/mono-time.c index 05dd2b9a6fd0e..beec0266134de 100644 --- a/src/mono/mono/utils/mono-time.c +++ b/src/mono/mono/utils/mono-time.c @@ -298,13 +298,17 @@ mono_clock_cleanup (mono_clock_id_t clk_id) guint64 mono_clock_get_time_ns (mono_clock_id_t clk_id) -{ +{ +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; if (clock_gettime (clk_id, &ts) == -1) g_error ("%s: clock_gettime () returned -1, errno = %d", __func__, errno); return ((guint64) ts.tv_sec * 1000000000) + (guint64) ts.tv_nsec; +#else + return 0; +#endif } #else