Commit 759812fd by Jonathan Wakely

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.
parent 6c42e27c
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
* configure: Regenerate. * configure: Regenerate.
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-01-27 Jonathan Wakely <jwakely@redhat.com> 2020-01-27 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/93426 PR libstdc++/93426
......
...@@ -1422,20 +1422,14 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ ...@@ -1422,20 +1422,14 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
ac_has_nanosleep=yes ac_has_nanosleep=yes
;; ;;
gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu) gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
AC_MSG_CHECKING([for at least GNU libc 2.17]) # Don't use link test for freestanding library, in case gcc_no_link=yes
AC_TRY_COMPILE( if test x"$is_hosted" = xyes; then
[#include <features.h>], # Versions of glibc before 2.17 needed -lrt for clock_gettime.
[ AC_SEARCH_LIBS(clock_gettime, [rt])
#if ! __GLIBC_PREREQ(2, 17) if test x"$ac_cv_search_clock_gettime" = x"none required"; then
#error ac_has_clock_monotonic=yes
#endif ac_has_clock_realtime=yes
], fi
[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
fi fi
ac_has_nanosleep=yes ac_has_nanosleep=yes
ac_has_sched_yield=yes ac_has_sched_yield=yes
......
...@@ -21072,35 +21072,72 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu ...@@ -21072,35 +21072,72 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
ac_has_nanosleep=yes ac_has_nanosleep=yes
;; ;;
gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu) gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for at least GNU libc 2.17" >&5 # Don't use link test for freestanding library, in case gcc_no_link=yes
$as_echo_n "checking for at least GNU libc 2.17... " >&6; } if test x"$is_hosted" = xyes; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext # 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 ${ac_cv_search_clock_gettime+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* 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 int
main () main ()
{ {
return clock_gettime ();
#if ! __GLIBC_PREREQ(2, 17)
#error
#endif
; ;
return 0; return 0;
} }
_ACEOF _ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then : for ac_lib in '' rt; do
glibcxx_glibc217=yes 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 ${ac_cv_search_clock_gettime+:} false; then :
break
fi
done
if ${ac_cv_search_clock_gettime+:} false; then :
else else
glibcxx_glibc217=no ac_cv_search_clock_gettime=no
fi fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext rm conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_glibc217" >&5 LIBS=$ac_func_search_save_LIBS
$as_echo "$glibcxx_glibc217" >&6; } 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 fi
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes if test x"$ac_cv_search_clock_gettime" = x"none required"; then
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
fi
fi fi
ac_has_nanosleep=yes ac_has_nanosleep=yes
ac_has_sched_yield=yes ac_has_sched_yield=yes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment