public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Tobias Burnus <tobias@codesourcery.com>,
	Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
Date: Wed, 16 Mar 2022 12:29:07 +0000	[thread overview]
Message-ID: <2dd3d4ad-3912-6935-064a-524af339125a@redhat.com> (raw)
In-Reply-To: <0d4bbabb-c123-f77e-ccf0-45a611acc4f1@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

Hi Tobias,

> Thanks for the commit – but it fails for
> .../bin/ld: ./.libs/libgprofng.a(gethrtime.o): in function `gethrvtime':
> obj/binutils-src-mainline-0-x86_64-none-linux-gnu-x86_64-linux-gnu/gprofng/src/gethrtime.c:131: undefined reference to `clock_gettime'

Hmm, it looks like I missed a few places where the -lrt library is needed.

Please could you try out the attached patch and let me know if these changes
(on top of the ones that have already been checked in) are enough to solve
your build problems ?

Cheers
   Nick

[-- Attachment #2: gprofng.configure-tweaks.2.patch --]
[-- Type: text/x-patch, Size: 13600 bytes --]

diff --git a/gprofng/Makefile.in b/gprofng/Makefile.in
index 08ffdd2b65a..7b0df747e03 100644
--- a/gprofng/Makefile.in
+++ b/gprofng/Makefile.in
@@ -241,6 +241,7 @@ BUILD_SUBDIRS = @BUILD_SUBDIRS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
+CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
diff --git a/gprofng/configure b/gprofng/configure
index 9a4a334854b..6bbbf4abeee 100755
--- a/gprofng/configure
+++ b/gprofng/configure
@@ -634,6 +634,7 @@ am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
 BUILD_SUBDIRS
+CLOCK_GETTIME_LINK
 GPROFNG_LIBDIR
 GPROFNG_CPPFLAGS
 GPROFNG_CFLAGS
@@ -12089,7 +12090,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12092 "configure"
+#line 12093 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12195,7 +12196,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12198 "configure"
+#line 12199 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16536,6 +16537,58 @@ 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.  This
+# test is copied from libgomp, and modified to not link in -lrt as
+# we're using this for test timing only.
+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 :
+  CLOCK_GETTIME_LINK=-lrt
+
+$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
+
+fi
+
+fi
+
+
 
 
 ac_config_files="$ac_config_files Makefile src/Makefile gp-display-html/Makefile doc/Makefile"
diff --git a/gprofng/configure.ac b/gprofng/configure.ac
index fa924dcee62..e39ad907787 100644
--- a/gprofng/configure.ac
+++ b/gprofng/configure.ac
@@ -180,6 +180,19 @@ AC_SUBST(GPROFNG_LIBDIR, [${libdir}])
 AC_CHECK_DECLS([basename])
 AC_CHECK_FUNCS(clock_gettime strsignal)
 
+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.  This
+# test is copied from libgomp, and modified to not link in -lrt as
+# we're using this for test timing only.
+if test "$ac_cv_func_clock_gettime" = no; then
+  AC_CHECK_LIB(rt, clock_gettime,
+    [CLOCK_GETTIME_LINK=-lrt
+     AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+	       [Define to 1 if you have the `clock_gettime' function.])])
+fi
+AC_SUBST(CLOCK_GETTIME_LINK)
+
 AC_SUBST(BUILD_SUBDIRS)
 
 AC_CONFIG_FILES([Makefile src/Makefile gp-display-html/Makefile doc/Makefile])
diff --git a/gprofng/doc/Makefile.in b/gprofng/doc/Makefile.in
index b45d6888f76..456693e32da 100644
--- a/gprofng/doc/Makefile.in
+++ b/gprofng/doc/Makefile.in
@@ -225,6 +225,7 @@ BUILD_SUBDIRS = @BUILD_SUBDIRS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
+CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
diff --git a/gprofng/gp-display-html/Makefile.in b/gprofng/gp-display-html/Makefile.in
index 10f59ee067e..30b650ec73e 100644
--- a/gprofng/gp-display-html/Makefile.in
+++ b/gprofng/gp-display-html/Makefile.in
@@ -189,6 +189,7 @@ BUILD_SUBDIRS = @BUILD_SUBDIRS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
+CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
diff --git a/gprofng/libcollector/Makefile.in b/gprofng/libcollector/Makefile.in
index f9ed2d95db5..a274d95e5b0 100644
--- a/gprofng/libcollector/Makefile.in
+++ b/gprofng/libcollector/Makefile.in
@@ -156,8 +156,7 @@ am__uninstall_files_from_dir = { \
   }
 am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(myincludedir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
-am__DEPENDENCIES_1 =
-libgp_collector_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
+libgp_collector_la_DEPENDENCIES =
 am__objects_1 = libgp_collector_la-gethrtime.lo \
 	libgp_collector_la-dispatcher.lo libgp_collector_la-iolib.lo \
 	libgp_collector_la-mmaptrace.lo libgp_collector_la-memmgr.lo \
@@ -306,7 +305,6 @@ AWK = @AWK@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
-CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
diff --git a/gprofng/libcollector/configure b/gprofng/libcollector/configure
index 887d2719910..ed23350d7b6 100755
--- a/gprofng/libcollector/configure
+++ b/gprofng/libcollector/configure
@@ -633,7 +633,6 @@ ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
-CLOCK_GETTIME_LINK
 GPROFNG_VARIANT
 CXXCPP
 OTOOL64
@@ -12014,7 +12013,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12017 "configure"
+#line 12016 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12120,7 +12119,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12123 "configure"
+#line 12122 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15438,58 +15437,6 @@ case "${target}" in
 esac
 
 
-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.  This
-# test is copied from libgomp, and modified to not link in -lrt as
-# we're using this for test timing only.
-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 :
-  CLOCK_GETTIME_LINK=-lrt
-
-$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
-
-fi
-
-fi
-
-
 ac_config_files="$ac_config_files Makefile"
 
 ac_config_headers="$ac_config_headers lib-config.h:../common/config.h.in"
diff --git a/gprofng/libcollector/configure.ac b/gprofng/libcollector/configure.ac
index bc8c3f1e144..8acd66f6977 100644
--- a/gprofng/libcollector/configure.ac
+++ b/gprofng/libcollector/configure.ac
@@ -54,19 +54,6 @@ case "${target}" in
 esac
 AC_SUBST(GPROFNG_VARIANT)
 
-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.  This
-# test is copied from libgomp, and modified to not link in -lrt as
-# we're using this for test timing only.
-if test "$ac_cv_func_clock_gettime" = no; then
-  AC_CHECK_LIB(rt, clock_gettime,
-    [CLOCK_GETTIME_LINK=-lrt
-     AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
-	       [Define to 1 if you have the `clock_gettime' function.])])
-fi
-AC_SUBST(CLOCK_GETTIME_LINK)
-
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_HEADERS([lib-config.h:../common/config.h.in])
 AC_OUTPUT
diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
index b874b5b32aa..1c968f89a4c 100644
--- a/gprofng/src/Makefile.am
+++ b/gprofng/src/Makefile.am
@@ -132,19 +132,19 @@ dbe_DATA = $(srcdir)/gprofng.rc
 bin_PROGRAMS = gp-archive gp-collect-app gprofng gp-display-text gp-display-src
 
 gp_archive_SOURCES = gp-archive.cc ArchiveExp.cc
-gp_archive_LDADD = $(LIBGPROFNG)
+gp_archive_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 
 gp_collect_app_SOURCES = gp-collect-app.cc checks.cc envsets.cc count.cc
-gp_collect_app_LDADD = $(LIBGPROFNG)
+gp_collect_app_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 
 gprofng_SOURCES = gprofng.cc
-gprofng_LDADD = $(LIBGPROFNG)
+gprofng_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 
 gp_display_src_SOURCES = gp-display-src.cc
-gp_display_src_LDADD = $(LIBGPROFNG)
+gp_display_src_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 
 gp_display_text_SOURCES = gp-display-text.cc ipc.cc ipcio.cc
-gp_display_text_LDADD = $(LIBGPROFNG)
+gp_display_text_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 
 
 if BUILD_MAN
diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
index f21671d9e67..9d29d877ee8 100644
--- a/gprofng/src/Makefile.in
+++ b/gprofng/src/Makefile.in
@@ -192,21 +192,21 @@ libgprofng_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 PROGRAMS = $(bin_PROGRAMS)
 am_gp_archive_OBJECTS = gp-archive.$(OBJEXT) ArchiveExp.$(OBJEXT)
 gp_archive_OBJECTS = $(am_gp_archive_OBJECTS)
-gp_archive_DEPENDENCIES = $(LIBGPROFNG)
+gp_archive_DEPENDENCIES = $(LIBGPROFNG) $(am__DEPENDENCIES_1)
 am_gp_collect_app_OBJECTS = gp-collect-app.$(OBJEXT) checks.$(OBJEXT) \
 	envsets.$(OBJEXT) count.$(OBJEXT)
 gp_collect_app_OBJECTS = $(am_gp_collect_app_OBJECTS)
-gp_collect_app_DEPENDENCIES = $(LIBGPROFNG)
+gp_collect_app_DEPENDENCIES = $(LIBGPROFNG) $(am__DEPENDENCIES_1)
 am_gp_display_src_OBJECTS = gp-display-src.$(OBJEXT)
 gp_display_src_OBJECTS = $(am_gp_display_src_OBJECTS)
-gp_display_src_DEPENDENCIES = $(LIBGPROFNG)
+gp_display_src_DEPENDENCIES = $(LIBGPROFNG) $(am__DEPENDENCIES_1)
 am_gp_display_text_OBJECTS = gp-display-text.$(OBJEXT) ipc.$(OBJEXT) \
 	ipcio.$(OBJEXT)
 gp_display_text_OBJECTS = $(am_gp_display_text_OBJECTS)
-gp_display_text_DEPENDENCIES = $(LIBGPROFNG)
+gp_display_text_DEPENDENCIES = $(LIBGPROFNG) $(am__DEPENDENCIES_1)
 am_gprofng_OBJECTS = gprofng.$(OBJEXT)
 gprofng_OBJECTS = $(am_gprofng_OBJECTS)
-gprofng_DEPENDENCIES = $(LIBGPROFNG)
+gprofng_DEPENDENCIES = $(LIBGPROFNG) $(am__DEPENDENCIES_1)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
 am__v_P_0 = false
@@ -308,6 +308,7 @@ BUILD_SUBDIRS = @BUILD_SUBDIRS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
+CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
@@ -540,15 +541,15 @@ libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
 dbedir = $(prefix)/etc
 dbe_DATA = $(srcdir)/gprofng.rc
 gp_archive_SOURCES = gp-archive.cc ArchiveExp.cc
-gp_archive_LDADD = $(LIBGPROFNG)
+gp_archive_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 gp_collect_app_SOURCES = gp-collect-app.cc checks.cc envsets.cc count.cc
-gp_collect_app_LDADD = $(LIBGPROFNG)
+gp_collect_app_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 gprofng_SOURCES = gprofng.cc
-gprofng_LDADD = $(LIBGPROFNG)
+gprofng_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 gp_display_src_SOURCES = gp-display-src.cc
-gp_display_src_LDADD = $(LIBGPROFNG)
+gp_display_src_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 gp_display_text_SOURCES = gp-display-text.cc ipc.cc ipcio.cc
-gp_display_text_LDADD = $(LIBGPROFNG)
+gp_display_text_LDADD = $(LIBGPROFNG) $(CLOCK_GETTIME_LINK)
 
 # The man pages depend on the version number and on a help2man include file.
 @BUILD_MAN_TRUE@common_mandeps = $(top_srcdir)/../bfd/version.m4
diff --git a/gprofng/src/gethrtime.c b/gprofng/src/gethrtime.c
index 8ba7295efaf..9e17f1eaa11 100644
--- a/gprofng/src/gethrtime.c
+++ b/gprofng/src/gethrtime.c
@@ -159,7 +159,11 @@ gethrtime (void)
    * There is no issue on Solaris, where gethrtime() is provided by the kernel
    * and used by DTrace.
    */
+#ifdef CLOCK_MONOTONIC_RAW
   int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
+#else
+  int r = clock_gettime (CLOCK_MONOTONIC, &tp);
+#endif
   if (r == 0)
     rc = ((hrtime_t) tp.tv_sec) * 1000000000 + (hrtime_t) tp.tv_nsec;
   return rc;
diff --git a/gprofng/testsuite/gprofng.display/mttest/gethrtime.c b/gprofng/testsuite/gprofng.display/mttest/gethrtime.c
index a9854019a68..aa5a4b92bcf 100644
--- a/gprofng/testsuite/gprofng.display/mttest/gethrtime.c
+++ b/gprofng/testsuite/gprofng.display/mttest/gethrtime.c
@@ -222,7 +222,12 @@ gethrtime (void)
 {
   struct timespec tp;
   hrtime_t rc = 0;
+#ifdef CLOCK_MONOTONIC_RAW
+  int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
+#else
   int r = clock_gettime (CLOCK_MONOTONIC, &tp);
+#endif
+
   if (r == 0)
     rc = ((hrtime_t) tp.tv_sec) * 1000000000 + (hrtime_t) tp.tv_nsec;
   return rc;

  reply	other threads:[~2022-03-16 12:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 10:57 Tobias Burnus
2022-03-14 18:16 ` Vladimir Mezentsev
2022-03-15 15:24   ` Nick Clifton
2022-03-15 16:24     ` Tobias Burnus
2022-03-16 12:29       ` Nick Clifton [this message]
2022-03-16 14:55         ` Tobias Burnus
2022-03-18 15:25           ` Tobias Burnus
2022-03-18 15:47             ` Nick Clifton
2022-03-15 16:54     ` Vladimir Mezentsev
2022-03-15 16:59       ` Vladimir Mezentsev
2022-03-16  7:56       ` Tobias Burnus
2022-03-14 20:53 ` Joseph Myers
2022-03-14 21:52   ` Vladimir Mezentsev
2022-03-16 11:30   ` Nick Alcock

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=2dd3d4ad-3912-6935-064a-524af339125a@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=tobias@codesourcery.com \
    --cc=vladimir.mezentsev@oracle.com \
    /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).