From: Dmitry V. Levin Date: Wed, 14 Mar 2018 21:15:55 +0000 (+0000) Subject: build: do not hardcode -lrt X-Git-Tag: v4.22~84 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85b35818dbec200050b8becd8e62036e758ff371;p=strace build: do not hardcode -lrt Depending on libc implementation, various -lrt functions can be implemented either in -lc or in -lrt. For example, starting with glibc-2.17 the clock_* suite of functions is available directly in -lc. Check whether clock_* and mq_* suites of functions are provided by -lrt or by the main C library, do not link with -lrt unnecessarily. This change affects only tests yet, but this is going to be more important as soon as strace starts using clock_gettime. * configure.ac (AC_SEARCH_LIBS): Check for clock_gettime and mq_open in -lrt. (AC_SUBST): Add clock_LIBS and mq_LIBS. * tests/Makefile.am (mq_LDADD): Replace -lrt with $(mq_LIBS). (threads_execve_LDADD, times_LDADD): Replace -lrt with $(clock_LIBS). --- diff --git a/configure.ac b/configure.ac index b4c1990f..0895cde7 100644 --- a/configure.ac +++ b/configure.ac @@ -809,6 +809,25 @@ if test "x$ac_cv_lib_dl_dladdr" = xyes; then fi AC_SUBST(dl_LIBS) +saved_LIBS="$LIBS" +AC_SEARCH_LIBS([clock_gettime], [rt]) +LIBS="$saved_LIBS" +case "$ac_cv_search_clock_gettime" in + no) AC_MSG_FAILURE([failed to find clock_gettime]) ;; + -l*) clock_LIBS="$ac_cv_search_clock_gettime" ;; + *) clock_LIBS= ;; +esac +AC_SUBST(clock_LIBS) + +saved_LIBS="$LIBS" +AC_SEARCH_LIBS([mq_open], [rt]) +LIBS="$saved_LIBS" +case "$ac_cv_search_mq_open" in + -l*) mq_LIBS="$ac_cv_search_mq_open" ;; + *) mq_LIBS= ;; +esac +AC_SUBST(mq_LIBS) + AC_PATH_PROG([PERL], [perl]) AC_CHECK_TOOL([READELF], [readelf]) diff --git a/tests/Makefile.am b/tests/Makefile.am index ec307012..813bdb37 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -172,7 +172,7 @@ fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 -mq_LDADD = -lrt $(LDADD) +mq_LDADD = $(mq_LIBS) $(LDADD) newfstatat_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 pc_LDADD = $(dl_LIBS) $(LDADD) pread64_pwrite64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 @@ -181,8 +181,8 @@ preadv_pwritev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 pwritev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 stat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 statfs_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 -threads_execve_LDADD = -lrt -lpthread $(LDADD) -times_LDADD = -lrt $(LDADD) +threads_execve_LDADD = -lpthread $(clock_LIBS) $(LDADD) +times_LDADD = $(clock_LIBS) $(LDADD) truncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64 uio_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64