From: vladimir.mezentsev@oracle.com
To: binutils@sourceware.org
Subject: [PATCH] gprofng: the gprofng build failed with glibc versions before 2.17
Date: Mon, 14 Mar 2022 15:38:19 -0700 [thread overview]
Message-ID: <20220314223819.3549925-1-vladimir.mezentsev@oracle.com> (raw)
From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
gprofng/ChangeLog
2022-03-14 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
* gprofng/configure.ac: Check for the clock_gettime function.
* gprofng/configure: Rebuild.
* gprofng/common/gp-time.h: Set CLOCK_MONOTONIC_RAW.
* gprofng/common/config.h.in: Add HAVE_CLOCK_GETTIME.
* gprofng/src/gethrtime.c: Add clock_gettime.
---
gprofng/common/config.h.in | 3 ++
gprofng/common/gp-time.h | 4 +++
gprofng/configure | 63 ++++++++++++++++++++++++++++++++++++++
gprofng/configure.ac | 14 +++++++++
gprofng/src/gethrtime.c | 9 ++++++
5 files changed, 93 insertions(+)
diff --git a/gprofng/common/config.h.in b/gprofng/common/config.h.in
index e46e64f39e3..8409ce74a57 100644
--- a/gprofng/common/config.h.in
+++ b/gprofng/common/config.h.in
@@ -6,6 +6,9 @@
/* Enable java profiling */
#undef GPROFNG_JAVA_PROFILING
+/* Define to 1 if you have the `clock_gettime' function. */
+#undef HAVE_CLOCK_GETTIME
+
/* Define to 1 if you have the declaration of `basename', and to 0 if you
don't. */
#undef HAVE_DECL_BASENAME
diff --git a/gprofng/common/gp-time.h b/gprofng/common/gp-time.h
index 775537041d1..14eda83df13 100644
--- a/gprofng/common/gp-time.h
+++ b/gprofng/common/gp-time.h
@@ -30,6 +30,10 @@ typedef struct timespec timestruc_t;
#define NANOSEC 1000000000
#define MICROSEC 1000000
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+#endif
+
#ifdef __cplusplus
extern "C"
{
diff --git a/gprofng/configure b/gprofng/configure
index 3cf4dc768ce..c4b9c9dd1a9 100755
--- a/gprofng/configure
+++ b/gprofng/configure
@@ -15444,6 +15444,69 @@ if test "$enable_shared" = "yes"; then
GPROFNG_LIBADD="-L../../libiberty/pic -liberty"
fi
+# Check for the clock_gettime function.
+for ac_func in clock_gettime
+do :
+ ac_fn_c_check_func "$LINENO" "clock_gettime" "ac_cv_func_clock_gettime"
+if test "x$ac_cv_func_clock_gettime" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_CLOCK_GETTIME 1
+_ACEOF
+
+fi
+done
+
+clock_gettime_link=
+# At least for glibc, clock_gettime is in librt. But don't
+# pull that in if it still doesn't give us the function we want.
+
+if test "$ac_cv_func_clock_gettime" = no; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5
+$as_echo_n "checking for clock_gettime in -lrt... " >&6; }
+if ${ac_cv_lib_rt_clock_gettime+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lrt $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char clock_gettime ();
+int
+main ()
+{
+return clock_gettime ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_rt_clock_gettime=yes
+else
+ ac_cv_lib_rt_clock_gettime=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5
+$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; }
+if test "x$ac_cv_lib_rt_clock_gettime" = xyes; then :
+ GPROFNG_LIBADD="$GPROFNG_LIBADD -lrt"
+
+$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
+
+fi
+
+fi
+
+
# Figure out what compiler warnings we can enable.
# See config/warnings.m4 for details.
diff --git a/gprofng/configure.ac b/gprofng/configure.ac
index 8977e8bd4bb..6522b6fab0e 100644
--- a/gprofng/configure.ac
+++ b/gprofng/configure.ac
@@ -35,8 +35,22 @@ GPROFNG_LIBADD="-L../../libiberty -liberty"
if test "$enable_shared" = "yes"; then
GPROFNG_LIBADD="-L../../libiberty/pic -liberty"
fi
+
+# Check for the clock_gettime function.
+AC_CHECK_FUNCS(clock_gettime)
+clock_gettime_link=
+# At least for glibc, clock_gettime is in librt. But don't
+# pull that in if it still doesn't give us the function we want.
+
+if test "$ac_cv_func_clock_gettime" = no; then
+ AC_CHECK_LIB(rt, clock_gettime,
+ [GPROFNG_LIBADD="$GPROFNG_LIBADD -lrt"
+ AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+ [Define to 1 if you have the `clock_gettime' function.])])
+fi
AC_SUBST(GPROFNG_LIBADD)
+
# Figure out what compiler warnings we can enable.
# See config/warnings.m4 for details.
diff --git a/gprofng/src/gethrtime.c b/gprofng/src/gethrtime.c
index 8ba7295efaf..8473de9fe58 100644
--- a/gprofng/src/gethrtime.c
+++ b/gprofng/src/gethrtime.c
@@ -120,6 +120,15 @@ get_ncpus (void)
return ncpus;
}
+#ifndef HAVE_CLOCK_GETTIME
+int
+clock_gettime (clockid_t clk_id __attribute__ ((unused)),
+ struct timespec *res __attribute__ ((unused)))
+{
+ return -1;
+}
+#endif
+
/* gethrvtime -- generic solution, getting user time from
* clock_gettime(CLOCK_THREAD_CPUTIME_ID,..), and reformatting.
* need -lrt to compile.*/
--
2.27.0
next reply other threads:[~2022-03-14 22:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 22:38 vladimir.mezentsev [this message]
2022-03-14 23:13 Tobias Burnus
2022-03-15 20:16 vladimir.mezentsev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220314223819.3549925-1-vladimir.mezentsev@oracle.com \
--to=vladimir.mezentsev@oracle.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).