public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
@ 2022-03-14 10:57 Tobias Burnus
  2022-03-14 18:16 ` Vladimir Mezentsev
  2022-03-14 20:53 ` Joseph Myers
  0 siblings, 2 replies; 14+ messages in thread
From: Tobias Burnus @ 2022-03-14 10:57 UTC (permalink / raw)
  To: Binutils, Vladimir Mezentsev, Nick Clifton

Hi Vladimir, hi Nick,

Friday's commit "gprofng: a new GNU profiler",
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bb368aad297fe3ad40cf397e6fc85aa471429a28

broke the build here (build server using on purpose an older Linux/glibc):

gprofng/libcollector/gethrtime.c:35:26: error: 'CLOCK_MONOTONIC_RAW' undeclared (first use in this function); did you mean 'CLOCK_MONOTONIC'?
    int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
                           ^~~~~~~~~~~~~~~~~~~
                           CLOCK_MONOTONIC

According to https://linux.die.net/man/2/clock_gettime:

   CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
     Similar to CLOCK_MONOTONIC, but provides access to a raw hardware-based
     time that is not subject to NTP adjustments or the incremental
     adjustments performed by adjtime(3).

Thus, it seems as if either a config check or a much
simpler patch as the following is needed:

--- a/gprofng/libcollector/gethrtime.c
+++ b/gprofng/libcollector/gethrtime.c
@@ -34,3 +34,7 @@ linux_gethrtime ()
    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)

--- a/gprofng/src/gethrtime.c
+++ b/gprofng/src/gethrtime.c
@@ -161,3 +161,7 @@ gethrtime (void)
     */
+#ifdef CLOCK_MONOTONIC_RAW
    int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
+#else
+  int r = clock_gettime (CLOCK_MONOTONIC, &tp);
+#endif
    if (r == 0)

  * * *

Additionally, the build fails with the link error:
    gprofng/src/gethrtime.c:131: undefined reference to `clock_gettime'

The problem seems to be what the 'clock_gettime(3)' man page states:
        Link with -lrt (only for glibc versions before 2.17).

Please consider as fix to copy the following check from libbacktrace/configure.ac:

# Check for the clock_gettime function.
AC_CHECK_FUNCS(clock_gettime)
...
AC_SUBST(CLOCK_GETTIME_LINK)


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] 14+ messages in thread

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-14 10:57 Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined Tobias Burnus
@ 2022-03-14 18:16 ` Vladimir Mezentsev
  2022-03-15 15:24   ` Nick Clifton
  2022-03-14 20:53 ` Joseph Myers
  1 sibling, 1 reply; 14+ messages in thread
From: Vladimir Mezentsev @ 2022-03-14 18:16 UTC (permalink / raw)
  To: Tobias Burnus, Binutils, Nick Clifton



On 3/14/22 03:57, Tobias Burnus wrote:
> Hi Vladimir, hi Nick,
>
> Friday's commit "gprofng: a new GNU profiler",
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bb368aad297fe3ad40cf397e6fc85aa471429a28 
>
>
> broke the build here (build server using on purpose an older 
> Linux/glibc):
>
> gprofng/libcollector/gethrtime.c:35:26: error: 'CLOCK_MONOTONIC_RAW' 
> undeclared (first use in this function); did you mean 'CLOCK_MONOTONIC'?
>    int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
>                           ^~~~~~~~~~~~~~~~~~~
>                           CLOCK_MONOTONIC
>
> According to https://linux.die.net/man/2/clock_gettime:
>
>   CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
>     Similar to CLOCK_MONOTONIC, but provides access to a raw 
> hardware-based
>     time that is not subject to NTP adjustments or the incremental
>     adjustments performed by adjtime(3).
>
> Thus, it seems as if either a config check or a much
> simpler patch as the following is needed:
>
> --- a/gprofng/libcollector/gethrtime.c
> +++ b/gprofng/libcollector/gethrtime.c
> @@ -34,3 +34,7 @@ linux_gethrtime ()
>    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)
>
> --- a/gprofng/src/gethrtime.c
> +++ b/gprofng/src/gethrtime.c
> @@ -161,3 +161,7 @@ gethrtime (void)
>     */
> +#ifdef CLOCK_MONOTONIC_RAW
>    int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
> +#else
> +  int r = clock_gettime (CLOCK_MONOTONIC, &tp);
> +#endif
>    if (r == 0)
>
>  * * *
>
> Additionally, the build fails with the link error:
>    gprofng/src/gethrtime.c:131: undefined reference to `clock_gettime'
>
> The problem seems to be what the 'clock_gettime(3)' man page states:
>        Link with -lrt (only for glibc versions before 2.17).
>
> Please consider as fix to copy the following check from 
> libbacktrace/configure.ac:
>
> # Check for the clock_gettime function.
> AC_CHECK_FUNCS(clock_gettime)
> ...
> AC_SUBST(CLOCK_GETTIME_LINK)


  Hi Tobia,
Your fixes look good to me.
Could you apply these fixes.
I can prepare a patch but I cannot  build on your configuration.

Thank you,
-Vladimir



>
>
> 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] 14+ messages in thread

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-14 10:57 Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined Tobias Burnus
  2022-03-14 18:16 ` Vladimir Mezentsev
@ 2022-03-14 20:53 ` Joseph Myers
  2022-03-14 21:52   ` Vladimir Mezentsev
  2022-03-16 11:30   ` Nick Alcock
  1 sibling, 2 replies; 14+ messages in thread
From: Joseph Myers @ 2022-03-14 20:53 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Binutils, Vladimir Mezentsev, Nick Clifton

On Mon, 14 Mar 2022, Tobias Burnus wrote:

> Hi Vladimir, hi Nick,
> 
> Friday's commit "gprofng: a new GNU profiler",
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bb368aad297fe3ad40cf397e6fc85aa471429a28
> 
> broke the build here (build server using on purpose an older Linux/glibc):

I'm seeing other errors as well from my glibc bot 
<https://sourceware.org/pipermail/libc-testresults/2022q1/009449.html>.

Building a cross from x86_64-linux-gnu to aarch64-linux-gnu, I get:

libtool: link: gcc -shared  -fPIC -DPIC  .libs/synctrace.o    -Wl,--version-script -Wl,/scratch/jmyers/bmg/many12/src/binutils/gprofng/libcollector/mapfile.aarch64-Linux -Wl,--no-as-needed -Wl,-lrt -Wl,-ldl   -Wl,-soname -Wl,libgp-sync.so -o .libs/libgp-sync.so
/usr/bin/ld: .libs/libgp-sync.so: version node not found for symbol pthread_cond_wait@@GLIBC_2.3.2
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make[6]: *** [Makefile:573: libgp-sync.la] Error 1

Using mapfile.aarch64-Linux - which has symbol versions appropriate for 
the target - is fundamentally incorrect when building a library for the 
host.  (You can't build libraries for the target at all when building 
binutils; binutils is an early bootstrap step, before building GCC, before 
building glibc.)

And on a system with older host compiler (GCC 5), 
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu 
--target=x86_64-glibc-linux-gnu, I get a series of errors of the form:

QLParser.yy: In function 'QL::Parser::symbol_type QL::yylex(QL::Result&)':
QLParser.yy:267:82: error: invalid initialization of non-const reference of type 'const Expression*&' from an rvalue of type 'const Expression*'

(I might ask incidentally why the Bison output files QLParser.tab.cc and 
QLParser.tab.hh are checked in - normally binutils doesn't commit Bison 
output files to the repository on master, although it makes sure to 
include them in release tarballs.  If there's a Bison version dependency 
issue, then arrange not to build gprofng when the installed Bison is too 
old.)

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-14 20:53 ` Joseph Myers
@ 2022-03-14 21:52   ` Vladimir Mezentsev
  2022-03-16 11:30   ` Nick Alcock
  1 sibling, 0 replies; 14+ messages in thread
From: Vladimir Mezentsev @ 2022-03-14 21:52 UTC (permalink / raw)
  To: Joseph Myers, Tobias Burnus; +Cc: Binutils, Nick Clifton



On 3/14/22 13:53, Joseph Myers wrote:
> On Mon, 14 Mar 2022, Tobias Burnus wrote:
>
>> Hi Vladimir, hi Nick,
>>
>> Friday's commit "gprofng: a new GNU profiler",
>> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bb368aad297fe3ad40cf397e6fc85aa471429a28
>>
>> broke the build here (build server using on purpose an older Linux/glibc):


   I sent the patch  to Tobias Burnus <tobias@codesourcery.com> to check 
that the build issues are fixed on old libc.


> I'm seeing other errors as well from my glibc bot
> <https://sourceware.org/pipermail/libc-testresults/2022q1/009449.html>.
>
> Building a cross from x86_64-linux-gnu to aarch64-linux-gnu, I get:
>
> libtool: link: gcc -shared  -fPIC -DPIC  .libs/synctrace.o    -Wl,--version-script -Wl,/scratch/jmyers/bmg/many12/src/binutils/gprofng/libcollector/mapfile.aarch64-Linux -Wl,--no-as-needed -Wl,-lrt -Wl,-ldl   -Wl,-soname -Wl,libgp-sync.so -o .libs/libgp-sync.so
> /usr/bin/ld: .libs/libgp-sync.so: version node not found for symbol pthread_cond_wait@@GLIBC_2.3.2
> /usr/bin/ld: failed to set dynamic section sizes: bad value
> collect2: error: ld returned 1 exit status
> make[6]: *** [Makefile:573: libgp-sync.la] Error 1
>
> Using mapfile.aarch64-Linux - which has symbol versions appropriate for
> the target - is fundamentally incorrect when building a library for the
> host.  (You can't build libraries for the target at all when building
> binutils; binutils is an early bootstrap step, before building GCC, before
> building glibc.)

  I understood.
Give me time to understand what need to do to fix this.

>
> And on a system with older host compiler (GCC 5),
> --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
> --target=x86_64-glibc-linux-gnu, I get a series of errors of the form:
>
> QLParser.yy: In function 'QL::Parser::symbol_type QL::yylex(QL::Result&)':
> QLParser.yy:267:82: error: invalid initialization of non-const reference of type 'const Expression*&' from an rvalue of type 'const Expression*'

We tested with gcc-8 - gcc-11.
I am looking for gcc-5 to fix the problems.


>
> (I might ask incidentally why the Bison output files QLParser.tab.cc and
> QLParser.tab.hh are checked in - normally binutils doesn't commit Bison
> output files to the repository on master, although it makes sure to
> include them in release tarballs.  If there's a Bison version dependency
> issue, then arrange not to build gprofng when the installed Bison is too
> old.)

OK. I will fix this.

We need bison 3.6 or late.
The user cannot simply install this version. `yum install`  installs an 
old bison.
The user should download and build sources . It is why we checked in 
these files.


Thank you,
-Vladimir


>


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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-14 18:16 ` Vladimir Mezentsev
@ 2022-03-15 15:24   ` Nick Clifton
  2022-03-15 16:24     ` Tobias Burnus
  2022-03-15 16:54     ` Vladimir Mezentsev
  0 siblings, 2 replies; 14+ messages in thread
From: Nick Clifton @ 2022-03-15 15:24 UTC (permalink / raw)
  To: Vladimir Mezentsev, Tobias Burnus, Binutils

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

Hi Vladimir, Hi Tobias,

   To save time I have gone ahead and applied a patch myself (attached).
   Please let me know if I missed anything or made a mistake...

Cheers
   Nick

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

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/configure b/gprofng/configure
index 3cf4dc768ce..9a4a334854b 100755
--- a/gprofng/configure
+++ b/gprofng/configure
@@ -16523,12 +16523,13 @@ cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_BASENAME $ac_have_decl
 _ACEOF
 
-for ac_func in strsignal
+for ac_func in clock_gettime strsignal
 do :
-  ac_fn_c_check_func "$LINENO" "strsignal" "ac_cv_func_strsignal"
-if test "x$ac_cv_func_strsignal" = xyes; then :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
   cat >>confdefs.h <<_ACEOF
-#define HAVE_STRSIGNAL 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
 
 fi
diff --git a/gprofng/configure.ac b/gprofng/configure.ac
index 8977e8bd4bb..fa924dcee62 100644
--- a/gprofng/configure.ac
+++ b/gprofng/configure.ac
@@ -178,7 +178,7 @@ AC_SUBST(GPROFNG_CPPFLAGS, [${gprofng_cppflags}])
 AC_SUBST(GPROFNG_LIBDIR, [${libdir}])
 
 AC_CHECK_DECLS([basename])
-AC_CHECK_FUNCS([strsignal])
+AC_CHECK_FUNCS(clock_gettime strsignal)
 
 AC_SUBST(BUILD_SUBDIRS)
 
diff --git a/gprofng/libcollector/Makefile.am b/gprofng/libcollector/Makefile.am
index bd86e97753d..a41b92030e0 100644
--- a/gprofng/libcollector/Makefile.am
+++ b/gprofng/libcollector/Makefile.am
@@ -63,7 +63,7 @@ libgp_collector_la_CPPFLAGS = $(AM_CPPFLAGS) $(jdk_inc) \
 # Prevent libtool from reordering -Wl,--no-as-needed after -lrt by
 # disguising -lrt as a linker flag.
 libgp_collector_la_LDFLAGS = $(AM_LDFLAGS)
-libgp_collector_la_LIBADD =
+libgp_collector_la_LIBADD = $(CLOCK_GETTIME_LINK)
 
 libgp_heap_la_SOURCES = heaptrace.c
 libgp_heap_la_LDFLAGS = $(AM_LDFLAGS)
diff --git a/gprofng/libcollector/Makefile.in b/gprofng/libcollector/Makefile.in
index 920c7a7ad11..f9ed2d95db5 100644
--- a/gprofng/libcollector/Makefile.in
+++ b/gprofng/libcollector/Makefile.in
@@ -156,7 +156,8 @@ am__uninstall_files_from_dir = { \
   }
 am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(myincludedir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
-libgp_collector_la_DEPENDENCIES =
+am__DEPENDENCIES_1 =
+libgp_collector_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
 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 \
@@ -305,6 +306,7 @@ AWK = @AWK@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
+CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@
 CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CXX = @CXX@
@@ -459,7 +461,7 @@ libgp_collector_la_CPPFLAGS = $(AM_CPPFLAGS) $(jdk_inc) \
 # Prevent libtool from reordering -Wl,--no-as-needed after -lrt by
 # disguising -lrt as a linker flag.
 libgp_collector_la_LDFLAGS = $(AM_LDFLAGS)
-libgp_collector_la_LIBADD = 
+libgp_collector_la_LIBADD = $(CLOCK_GETTIME_LINK)
 libgp_heap_la_SOURCES = heaptrace.c
 libgp_heap_la_LDFLAGS = $(AM_LDFLAGS)
 libgp_sync_la_SOURCES = synctrace.c
diff --git a/gprofng/libcollector/configure b/gprofng/libcollector/configure
index ed23350d7b6..887d2719910 100755
--- a/gprofng/libcollector/configure
+++ b/gprofng/libcollector/configure
@@ -633,6 +633,7 @@ ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
+CLOCK_GETTIME_LINK
 GPROFNG_VARIANT
 CXXCPP
 OTOOL64
@@ -12013,7 +12014,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12016 "configure"
+#line 12017 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12119,7 +12120,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12122 "configure"
+#line 12123 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15437,6 +15438,58 @@ 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 8acd66f6977..bc8c3f1e144 100644
--- a/gprofng/libcollector/configure.ac
+++ b/gprofng/libcollector/configure.ac
@@ -54,6 +54,19 @@ 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/libcollector/gethrtime.c b/gprofng/libcollector/gethrtime.c
index f369cdc8ee1..002de7c77ba 100644
--- a/gprofng/libcollector/gethrtime.c
+++ b/gprofng/libcollector/gethrtime.c
@@ -22,17 +22,22 @@
 #include <time.h>
 #include "gp-time.h"
 
-/*
- *  CLOCK_MONOTONIC
- *  Clock that cannot be set and represents monotonic time since some
- *           unspecified starting point.
- */
+/*  CLOCK_MONOTONIC
+    Clock that cannot be set and represents monotonic time since some
+             unspecified starting point.  */
+
 static hrtime_t
-linux_gethrtime ()
+linux_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;

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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-15 15:24   ` Nick Clifton
@ 2022-03-15 16:24     ` Tobias Burnus
  2022-03-16 12:29       ` Nick Clifton
  2022-03-15 16:54     ` Vladimir Mezentsev
  1 sibling, 1 reply; 14+ messages in thread
From: Tobias Burnus @ 2022-03-15 16:24 UTC (permalink / raw)
  To: Nick Clifton, Vladimir Mezentsev, Binutils

Hi Nick,

On 15.03.22 16:24, Nick Clifton wrote:
> To save time I have gone ahead and applied a patch myself (attached).
> Please let me know if I missed anything or made a mistake...

Thanks for the commit – but it fails for

libtool: link: x86_64-linux-gnu-g++ -Wall -pthread -Wno-switch -Wno-format-truncation
      -g -O2 -static-libstdc++ -static-libgcc
      -o gp-display-text gp-display-text.o ipc.o ipcio.o
      -L...
      ./.libs/libgprofng.a .../bfd/.libs/libbfd.a -lz -liberty -ldl -pthread

with

.../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'
.../bin/ld: ./.libs/libgprofng.a(gethrtime.o): in function `gethrtime':
obj/binutils-src-mainline-0-x86_64-none-linux-gnu-x86_64-linux-gnu/gprofng/src/gethrtime.c:162: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status

Thus, it works for libcollector – but not for libgprofng / gp-display-text.

 From the build dir:

libcollector/Makefile:CLOCK_GETTIME_LINK = -lrt
libcollector/Makefile:libgp_collector_la_LIBADD = $(CLOCK_GETTIME_LINK)
libcollector/config.log:CLOCK_GETTIME_LINK='-lrt'
libcollector/config.status:S["CLOCK_GETTIME_LINK"]="-lrt"


Thanks for looking into build issue,

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] 14+ messages in thread

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-15 15:24   ` Nick Clifton
  2022-03-15 16:24     ` Tobias Burnus
@ 2022-03-15 16:54     ` Vladimir Mezentsev
  2022-03-15 16:59       ` Vladimir Mezentsev
  2022-03-16  7:56       ` Tobias Burnus
  1 sibling, 2 replies; 14+ messages in thread
From: Vladimir Mezentsev @ 2022-03-15 16:54 UTC (permalink / raw)
  To: Nick Clifton, Tobias Burnus, Binutils



On 3/15/22 08:24, Nick Clifton wrote:
> Hi Vladimir, Hi Tobias,
>
>   To save time I have gone ahead and applied a patch myself (attached).
>   Please let me know if I missed anything or made a mistake...
>
> Cheers
>   Nick


  Hi Nick,
I did not add -lrt for the gprofng/src build.


I suggested the following fix:

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


Thank you,
-Vladimir


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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-15 16:54     ` Vladimir Mezentsev
@ 2022-03-15 16:59       ` Vladimir Mezentsev
  2022-03-16  7:56       ` Tobias Burnus
  1 sibling, 0 replies; 14+ messages in thread
From: Vladimir Mezentsev @ 2022-03-15 16:59 UTC (permalink / raw)
  To: Nick Clifton, Binutils



On 3/15/22 09:54, Vladimir Mezentsev via Binutils wrote:
>
>
> On 3/15/22 08:24, Nick Clifton wrote:
>> Hi Vladimir, Hi Tobias,
>>
>>   To save time I have gone ahead and applied a patch myself (attached).
>>   Please let me know if I missed anything or made a mistake...
>>
>> Cheers
>>   Nick
>
>
>  Hi Nick,
> I did not add -lrt for the gprofng/src build.

Sorry,
  not me.

-lrt is needed in the gprofng build.

-Vladimir

>
>
> I suggested the following fix:
>
> % 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.
>
>
> Thank you,
> -Vladimir
>


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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-15 16:54     ` Vladimir Mezentsev
  2022-03-15 16:59       ` Vladimir Mezentsev
@ 2022-03-16  7:56       ` Tobias Burnus
  1 sibling, 0 replies; 14+ messages in thread
From: Tobias Burnus @ 2022-03-16  7:56 UTC (permalink / raw)
  To: Vladimir Mezentsev, Nick Clifton, Binutils

Hi Nick & Vladimir, hello all,

I still get the following, which I think I missed before because it
first already failed in gprofng/libcollector/ – and my last build was
on a slightly newer system which still required -lrt but did provide
CLOCK_MONOTONIC_RAW:

.../gprofng/src/gethrtime.c: In function 'gethrtime':
.../gprofng/src/gethrtime.c:162:26: error: 'CLOCK_MONOTONIC_RAW' undeclared (first use in this fun
ction); did you mean 'CLOCK_MONOTONIC'?
    int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
                           ^~~~~~~~~~~~~~~~~~~

Thanks - and I am sure we have almost fixed everything :-)

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] 14+ messages in thread

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-14 20:53 ` Joseph Myers
  2022-03-14 21:52   ` Vladimir Mezentsev
@ 2022-03-16 11:30   ` Nick Alcock
  1 sibling, 0 replies; 14+ messages in thread
From: Nick Alcock @ 2022-03-16 11:30 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Tobias Burnus, Binutils

On 14 Mar 2022, Joseph Myers outgrape:
> (I might ask incidentally why the Bison output files QLParser.tab.cc and 
> QLParser.tab.hh are checked in - normally binutils doesn't commit Bison 
> output files to the repository on master, although it makes sure to 
> include them in release tarballs.  If there's a Bison version dependency 
> issue, then arrange not to build gprofng when the installed Bison is too 
> old.)

There is. Since we have a reentrant parser, we need either gross
hand-hacking of the generated parser to move everything into a class
(which is what the code *used* to do, and is a non-starter in my eyes),
or at least Bison 3.3 (for api.parser.class): it is quite possible that
some dependency on a later Bison has crept in, but that's not
*fundamental* to the parser the way the api.parser.class dependency is.

The right approach seems to me to be to check the generated parser into
the disted release tarball, and then to configure gprofng only if Bison
is sufficiently recent or if the generated parser is already present
(i.e. this is a release tarball). In any case the generated parser would
disappear from version control and dbe/Makefile.am would gain rules to
regenerate it (and also at dist time for the tarball).

I think the default Automake rules already do this, as do the gnulib
rules we would probably have to use instead due to the Automake rules
forcing bison -y. At any rate this does not look impossible, or even
that hard, certainly not compared to rewriting the parser or something.
And there's certainly no justification for bumping the treewide bison
version (if there even is one: I thought there was, but now I look for
it I can't find it). The only people who will need to upgrade bison for
this are people building gprofng from git checkouts and who want its
building to not be skipped, who are presumably either developing gprofng
(in which case upgrading bison is no trouble), or are distributors
working in recent distro leading edges (in which case they are almost
certainly both used to upgrading bison and are using a newer version
already).


It looks like the skip-configure-if-unsuitable stuff is hardwired into
the top-level configure.ac, but it also looks like it can use basically
any reason to suppress building of single directories, so checking for
new-bison-or-gprofng/dbe/QLParser.cc-exists seems at least technically
doable.

Does this all seem sane to everyone else?

-- 
NULL && (void)

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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-15 16:24     ` Tobias Burnus
@ 2022-03-16 12:29       ` Nick Clifton
  2022-03-16 14:55         ` Tobias Burnus
  0 siblings, 1 reply; 14+ messages in thread
From: Nick Clifton @ 2022-03-16 12:29 UTC (permalink / raw)
  To: Tobias Burnus, Vladimir Mezentsev; +Cc: Binutils

[-- 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;

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

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-16 12:29       ` Nick Clifton
@ 2022-03-16 14:55         ` Tobias Burnus
  2022-03-18 15:25           ` Tobias Burnus
  0 siblings, 1 reply; 14+ messages in thread
From: Tobias Burnus @ 2022-03-16 14:55 UTC (permalink / raw)
  To: Nick Clifton, Binutils, Vladimir Mezentsev

Hi Nick,

On 16.03.22 13:29, Nick Clifton wrote:
>> 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 ?

Works – I had some patch-apply fails due to HJ's commits, but fixing the
.rej was trivial. (One line removed, two #line number changes, and two
changes in makefiles (.in, .mk) in two files which were already there.)

After doing so, your patch did build with the two x86-64 Linux build
servers (both require  -lrt, but only one has CLOCK_MONOTONIC_RAW). Thus:

:-)

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] 14+ messages in thread

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-16 14:55         ` Tobias Burnus
@ 2022-03-18 15:25           ` Tobias Burnus
  2022-03-18 15:47             ` Nick Clifton
  0 siblings, 1 reply; 14+ messages in thread
From: Tobias Burnus @ 2022-03-18 15:25 UTC (permalink / raw)
  To: Nick Clifton, Binutils, Vladimir Mezentsev

Hi Nick,

I was wondering whether you still intent to apply the patch? It would be
great if the build would work again after a week ...

Thanks,

Tobias

PS: Regarding the proposed patch, I wrote:

On 16.03.22 15:55, Tobias Burnus wrote:
> Hi Nick,
>
> On 16.03.22 13:29, Nick Clifton wrote:
>>> 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 ?
>
> Works – I had some patch-apply fails due to HJ's commits, but fixing
> the .rej was trivial. (One line removed, two #line number changes, and
> two changes in makefiles (.in, .mk) in two files which were already
> there.)
>
> After doing so, your patch did build with the two x86-64 Linux build
> servers (both require  -lrt, but only one has CLOCK_MONOTONIC_RAW). Thus:
>
> :-)
>
> 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] 14+ messages in thread

* Re: Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined
  2022-03-18 15:25           ` Tobias Burnus
@ 2022-03-18 15:47             ` Nick Clifton
  0 siblings, 0 replies; 14+ messages in thread
From: Nick Clifton @ 2022-03-18 15:47 UTC (permalink / raw)
  To: Tobias Burnus, Binutils, Vladimir Mezentsev

Hi Tobias,

> I was wondering whether you still intent to apply the patch? It would be
> great if the build would work again after a week ...

Sorry - I was busy with some other work.

I have now applied the patch.

Cheers
   Nick


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

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

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 10:57 Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined 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
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

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