libstdc++: Replace glibc-specific check for clock_gettime (PR 93325)

Message ID 20200128132844.GA53619@redhat.com
State New
Headers show
Series
  • libstdc++: Replace glibc-specific check for clock_gettime (PR 93325)
Related show

Commit Message

Jonathan Wakely Jan. 28, 2020, 1:28 p.m.
It's wrong to assume that clock_gettime is unavailable on any *-*-linux*
target that doesn't have glibc 2.17 or later. Use a generic test instead
of using __GLIBC_PREREQ. Only do that test when is_hosted=yes so that we
don't get an error for cross targets without a working linker.

This ensures that C library's clock_gettime will be used on non-glibc
targets, instead of an incorrect syscall to SYS_clock_gettime.

	PR libstdc++/93325
	* acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Use AC_SEARCH_LIBS for
	clock_gettime instead of explicit glibc version check.
	* configure: Regenerate.

Tested powerpc64le-linux, built on centos7 and centos6 as well to
check the results are correct for various versions of glibc.

Committed to master. I plan to backport this later too.
commit 759812fddc81c0c131d4633b2a7f56412ce8dbed
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 28 13:24:09 2020 +0000

    libstdc++: Replace glibc-specific check for clock_gettime (PR 93325)
    
    It's wrong to assume that clock_gettime is unavailable on any *-*-linux*
    target that doesn't have glibc 2.17 or later. Use a generic test instead
    of using __GLIBC_PREREQ. Only do that test when is_hosted=yes so that we
    don't get an error for cross targets without a working linker.
    
    This ensures that C library's clock_gettime will be used on non-glibc
    targets, instead of an incorrect syscall to SYS_clock_gettime.
    
            PR libstdc++/93325
            * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Use AC_SEARCH_LIBS for
            clock_gettime instead of explicit glibc version check.
            * configure: Regenerate.

Patch

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 39147916e94..ee5e0336f2c 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1422,20 +1422,14 @@  AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
         ac_has_nanosleep=yes
         ;;
       gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
-        AC_MSG_CHECKING([for at least GNU libc 2.17])
-        AC_TRY_COMPILE(
-          [#include <features.h>],
-          [
-          #if ! __GLIBC_PREREQ(2, 17)
-          #error
-          #endif
-          ],
-          [glibcxx_glibc217=yes], [glibcxx_glibc217=no])
-        AC_MSG_RESULT($glibcxx_glibc217)
-
-        if test x"$glibcxx_glibc217" = x"yes"; then
-          ac_has_clock_monotonic=yes
-          ac_has_clock_realtime=yes
+        # Don't use link test for freestanding library, in case gcc_no_link=yes
+        if test x"$is_hosted" = xyes; then
+          # Versions of glibc before 2.17 needed -lrt for clock_gettime.
+          AC_SEARCH_LIBS(clock_gettime, [rt])
+          if test x"$ac_cv_search_clock_gettime" = x"none required"; then
+            ac_has_clock_monotonic=yes
+            ac_has_clock_realtime=yes
+          fi
         fi
         ac_has_nanosleep=yes
         ac_has_sched_yield=yes