[gcc(refs/vendors/ibm/heads/gcc-8-branch)] libstdc++: Replace glibc-specific check for clock_gettime (PR 93325)

Peter Bergner bergner@gcc.gnu.org
Thu Apr 23 18:45:47 GMT 2020


https://gcc.gnu.org/g:655434f5ae93a4222a48c39c37a3a6fe0bdfc071

commit 655434f5ae93a4222a48c39c37a3a6fe0bdfc071
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 26 15:32:34 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.
    
    Backport from mainline
    2020-01-28  Jonathan Wakely  <jwakely@redhat.com>
    
            PR libstdc++/93325
            * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Use AC_SEARCH_LIBS for
            clock_gettime instead of explicit glibc version check.
            * configure: Regenerate.

Diff:
---
 libstdc++-v3/ChangeLog    | 10 +++++++
 libstdc++-v3/acinclude.m4 | 22 ++++++--------
 libstdc++-v3/configure    | 73 +++++++++++++++++++++++++++++++++++------------
 3 files changed, 73 insertions(+), 32 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c4203dfb93c..03d621332e3 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2020-02-26  Jonathan Wakely  <jwakely@redhat.com>
+
+	Backport from mainline
+	2020-01-28  Jonathan Wakely  <jwakely@redhat.com>
+
+	PR libstdc++/93325
+	* acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Use AC_SEARCH_LIBS for
+	clock_gettime instead of explicit glibc version check.
+	* configure: Regenerate.
+
 2020-02-26  Jonathan Wakely  <jwakely@redhat.com>
 
 	Backport from mainline
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 44e132beab5..b380a2628c1 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1413,20 +1413,14 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
         ac_has_sched_yield=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
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index da1dcd9817f..61457e940ec 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -20738,35 +20738,72 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
         ac_has_sched_yield=yes
         ;;
       gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
-        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for at least GNU libc 2.17" >&5
-$as_echo_n "checking for at least GNU libc 2.17... " >&6; }
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+        # 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.
+          { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing clock_gettime" >&5
+$as_echo_n "checking for library containing clock_gettime... " >&6; }
+if test "${ac_cv_search_clock_gettime+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <features.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 ()
 {
-
-          #if ! __GLIBC_PREREQ(2, 17)
-          #error
-          #endif
-
+return clock_gettime ();
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
-  glibcxx_glibc217=yes
+for ac_lib in '' rt; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if test x$gcc_no_link = xyes; then
+  as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
+fi
+if ac_fn_cxx_try_link "$LINENO"; then :
+  ac_cv_search_clock_gettime=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if test "${ac_cv_search_clock_gettime+set}" = set; then :
+  break
+fi
+done
+if test "${ac_cv_search_clock_gettime+set}" = set; then :
+
 else
-  glibcxx_glibc217=no
+  ac_cv_search_clock_gettime=no
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_glibc217" >&5
-$as_echo "$glibcxx_glibc217" >&6; }
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clock_gettime" >&5
+$as_echo "$ac_cv_search_clock_gettime" >&6; }
+ac_res=$ac_cv_search_clock_gettime
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 
-        if test x"$glibcxx_glibc217" = x"yes"; then
-          ac_has_clock_monotonic=yes
-          ac_has_clock_realtime=yes
+fi
+
+          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


More information about the Libstdc++-cvs mailing list