diff --git a/gcc/config.in b/gcc/config.in index 3fc4666d60b..0a506d1783a 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -883,6 +883,12 @@ #endif +/* Define to 1 if you have the `clock_gettime' function. */ +#ifndef USED_FOR_TARGET +#undef HAVE_CLOCK_GETTIME +#endif + + /* Define if defines clock_t. */ #ifndef USED_FOR_TARGET #undef HAVE_CLOCK_T diff --git a/gcc/configure b/gcc/configure index 47c58036530..150ab616414 100755 --- a/gcc/configure +++ b/gcc/configure @@ -10613,7 +10613,8 @@ fi for ac_func in times clock kill getrlimit setrlimit atoq \ popen sysconf strsignal getrusage nl_langinfo \ gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \ - clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked madvise mallinfo mallinfo2 fstatat getauxval + clearerr_unlocked feof_unlocked ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked fread_unlocked fwrite_unlocked getchar_unlocked getc_unlocked putchar_unlocked putc_unlocked madvise mallinfo mallinfo2 fstatat getauxval \ + clock_gettime do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -10626,6 +10627,54 @@ fi done +# 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 + { $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_cxx_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 : + LIBS="-lrt $LIBS" + +$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h + +fi + +fi + if test x$ac_cv_func_mbstowcs = xyes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mbstowcs works" >&5 $as_echo_n "checking whether mbstowcs works... " >&6; } @@ -21405,7 +21454,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21408 "configure" +#line 21457 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -21511,7 +21560,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21514 "configure" +#line 21563 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index dc8346a7b82..bdb22d53e2c 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1557,7 +1557,17 @@ define(gcc_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked dnl AC_CHECK_FUNCS(times clock kill getrlimit setrlimit atoq \ popen sysconf strsignal getrusage nl_langinfo \ gettimeofday mbstowcs wcswidth mmap posix_fallocate setlocale \ - gcc_UNLOCKED_FUNCS madvise mallinfo mallinfo2 fstatat getauxval) + gcc_UNLOCKED_FUNCS madvise mallinfo mallinfo2 fstatat getauxval \ + clock_gettime) + +# 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, + [LIBS="-lrt $LIBS" + AC_DEFINE(HAVE_CLOCK_GETTIME, 1, + [Define to 1 if you have the `clock_gettime' function.])]) +fi if test x$ac_cv_func_mbstowcs = xyes; then AC_CACHE_CHECK(whether mbstowcs works, gcc_cv_func_mbstowcs_works, diff --git a/gcc/timevar.cc b/gcc/timevar.cc index 4a57e74230d..e12775e6ff3 100644 --- a/gcc/timevar.cc +++ b/gcc/timevar.cc @@ -158,7 +158,7 @@ get_time (struct timevar_time_def *now) now->wall = 0; now->ggc_mem = timevar_ggc_mem_total; -#if _POSIX_C_SOURCE >= 199309L +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; clock_gettime (CLOCK_MONOTONIC, &ts); now->wall = ts.tv_sec * 1000000000 + ts.tv_nsec;