From d3a8ccb8073c3d76b8bfbb4205cfddfd5a351831 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 10 Jul 2009 19:38:16 +0000 Subject: [PATCH] Change use of AC_CHECK_LIB to AC_SEARCH_LIBS. Patch from Zack Weinberg. His message: This one eliminates all use of AC_CHECK_LIB in the configure script. AC_CHECK_LIB has a serious flaw: if the library you mention *exists* but is not *necessary* for the function you want, it adds it to $(LIBS) anyway. This was fine in the days of static libraries, because the linker would ignore an .a library that didn't contain anything you needed. However, ELF shared libraries are different (let's not get into why): the linker will by default record a DT_NEEDED entry for every shared object mentioned on the link command line. Thus, every use of AC_CHECK_LIB is a potential unnecessary DT_NEEDED, making extra work for the dynamic loader. The cure is simply to use AC_SEARCH_LIBS instead; it first tries to find the function you ask for in libc, and only if that doesn't work does it try to use the extra library you mention. For the same reasons, pkg-config .pc files should distinguish between the libraries to use for shared linkage (Libs:) and the additional libraries needed for static linkage (Libs.private:). I have also made that correction in this patch. I also took the opportunity to clean up the substitution variables a little and make absolutely sure that the core library does not get linked against zlib. svn:r1338 --- ChangeLog | 1 + configure.in | 24 +++++++++++++----------- libevent.pc.in | 3 ++- 3 files changed, 16 insertions(+), 12 deletions(-) Index: libevent-1.4.14b-stable/configure.in =================================================================== --- libevent-1.4.14b-stable.orig/configure.in 2011-06-25 16:14:52.480006333 +0400 +++ libevent-1.4.14b-stable/configure.in 2011-06-25 16:14:52.984008832 +0400 @@ -59,10 +59,10 @@ AC_SUBST(LIBTOOL_DEPS) dnl Checks for libraries. -AC_CHECK_LIB(socket, socket, [AC_SUBST( [LIBSOCKET], ["-lsocket"] )] ) -AC_CHECK_LIB(resolv, inet_aton, [AC_SUBST( [LIBRESOLV], ["-lresolv"] )] ) -AC_CHECK_LIB(rt, clock_gettime, [AC_SUBST( [LIBRT], ["-lrt"] )] ) -AC_CHECK_LIB(nsl, inet_ntoa, [AC_SUBST( [LIBNSL], ["-lnsl"] )] ) +AC_SEARCH_LIBS([inet_ntoa], [nsl]) +AC_SEARCH_LIBS([socket], [socket]) +AC_SEARCH_LIBS([inet_aton], [resolv]) +AC_SEARCH_LIBS([clock_gettime], [rt]) dnl Checks for header files. AC_HEADER_STDC Index: libevent-1.4.14b-stable/libevent.pc.in =================================================================== --- libevent-1.4.14b-stable.orig/libevent.pc.in 2011-06-25 16:14:52.480006333 +0400 +++ libevent-1.4.14b-stable/libevent.pc.in 2011-06-25 16:14:52.984008832 +0400 @@ -10,6 +10,7 @@ Version: @VERSION@ Requires: Conflicts: -Libs: -L${libdir} -levent @LIBSOCKET@ @LIBRESOLV@ @LIBRT@ @LIBNSL@ @ZLIB_LIBS@ +Libs: -L${libdir} -levent +Libs.private: @LIBS@ Cflags: -I${includedir}