Build issues due to patch "gprofng: a new GNU profiler" – CLOCK_MONOTONIC_RAW not defined

Tobias Burnus tobias@codesourcery.com
Mon Mar 14 10:57:15 GMT 2022


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


More information about the Binutils mailing list