public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] gprofng: the gprofng build failed with glibc versions before 2.17
@ 2022-03-14 23:13 Tobias Burnus
  0 siblings, 0 replies; 3+ messages in thread
From: Tobias Burnus @ 2022-03-14 23:13 UTC (permalink / raw)
  To: Vladimir Mezentsev, Binutils

Hi Vladimir,

I can confirm that your patch fixes my two build issues
(CLOCK_MONOTONIC_RAW and the -lrt issue).

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.
(cf. https://sourceware.org/pipermail/binutils/2022-March/120019.html)

Thanks,

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] gprofng: the gprofng build failed with glibc versions before 2.17
@ 2022-03-15 20:16 vladimir.mezentsev
  0 siblings, 0 replies; 3+ messages in thread
From: vladimir.mezentsev @ 2022-03-15 20:16 UTC (permalink / raw)
  To: nickc; +Cc: binutils

From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>

gprofng/ChangeLog
2022-03-15  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/src/gethrtime.c: Add clock_gettime.
---
 gprofng/common/gp-time.h |  4 +++
 gprofng/configure        | 63 ++++++++++++++++++++++++++++++++++++++++
 gprofng/configure.ac     | 14 +++++++++
 gprofng/src/gethrtime.c  |  9 ++++++
 4 files changed, 90 insertions(+)

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 9a4a334854b..3c3b3c0086e 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 fa924dcee62..430465423dc 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] gprofng: the gprofng build failed with glibc versions before 2.17
@ 2022-03-14 22:38 vladimir.mezentsev
  0 siblings, 0 replies; 3+ messages in thread
From: vladimir.mezentsev @ 2022-03-14 22:38 UTC (permalink / raw)
  To: binutils

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-15 20:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 23:13 [PATCH] gprofng: the gprofng build failed with glibc versions before 2.17 Tobias Burnus
  -- strict thread matches above, loose matches on Subject: below --
2022-03-15 20:16 vladimir.mezentsev
2022-03-14 22:38 vladimir.mezentsev

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).