svn commit: samba r15928 - branches/SAMBA_3_0/source trunk/source

jpeach at samba.org jpeach at samba.org
Mon May 29 02:25:38 GMT 2006


Author: jpeach
Date: 2006-05-29 02:25:36 +0000 (Mon, 29 May 2006)
New Revision: 15928

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15928

Log:
When we search for clock_gettime, we might find it in librt, but librt
might pull in libpthread. This is quite bad, firstly because it can
cause oplock signals on Linux to go wonky, and secondly because merely
linking with pthreads can cause performance degradations due to implicit
locking requirements.

The solution is to only search for clock_gettime if --with-profiling-data
was specified. If we do end up searching for it, then we test whether
linking with librt pulled in libpthread, and we only allow the definition
for clock_gettime to succeed if libpthread was NOT linked in.

Problem reported by Thomas Bork and diagnosed by Volker Lendecke.

Modified:
   branches/SAMBA_3_0/source/aclocal.m4
   branches/SAMBA_3_0/source/configure.in
   trunk/source/aclocal.m4
   trunk/source/configure.in


Changeset:
Modified: branches/SAMBA_3_0/source/aclocal.m4
===================================================================
--- branches/SAMBA_3_0/source/aclocal.m4	2006-05-29 01:30:02 UTC (rev 15927)
+++ branches/SAMBA_3_0/source/aclocal.m4	2006-05-29 02:25:36 UTC (rev 15928)
@@ -104,31 +104,64 @@
 ])
 
 
+dnl AC_LIBTESTFUNC(lib, function, [actions if found], [actions if not found])
 dnl Check for a function in a library, but don't keep adding the same library
 dnl to the LIBS variable.  Check whether the function is available in the
 dnl current LIBS before adding the library which prevents us spuriously
-dnl adding libraries for symbols that are in libc. On success, this ensures that
-dnl HAVE_FOO is defined.
-AC_LIBTESTFUNC(lib,func)
-AC_DEFUN(AC_LIBTESTFUNC,
+dnl adding libraries for symbols that are in libc.
+dnl
+dnl On success, the default actions ensure that HAVE_FOO is defined. The lib
+dnl is always added to $LIBS if it was found to be necessary. The caller
+dnl can use SMB_LIB_REMOVE to strp this if necessary.
+AC_DEFUN([AC_LIBTESTFUNC],
 [
   AC_CHECK_FUNCS($2,
       [
         # $2 was found in libc or existing $LIBS
-	AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
-	    [Whether $2 is available])
+	ifelse($3, [],
+	    [
+		AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
+		    [Whether $2 is available])
+	    ],
+	    [
+		$3
+	    ])
       ],
       [
         # $2 was not found, try adding lib$1
 	case " $LIBS " in
-          *\ -l$1\ *) ;;
-          *) AC_CHECK_LIB($1, $2,
+          *\ -l$1\ *)
+	    ifelse($4, [],
+		[
+		    # $2 was not found and we already had lib$1
+		    # nothing to do here by default
+		    true
+		],
+		[ $4 ])
+	    ;;
+          *)
+	    # $2 was not found, try adding lib$1
+	    AC_CHECK_LIB($1, $2,
 	      [
-		AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
-		    [Whether $2 is available])
-	        LIBS="-l$1 $LIBS"
+		LIBS="-l$1 $LIBS"
+		ifelse($3, [],
+		    [
+			AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
+			    [Whether $2 is available])
+		    ],
+		    [
+			$3
+		    ])
 	      ],
-	      [])
+	      [
+		ifelse($4, [],
+		    [
+			# $2 was not found in lib$1
+			# nothing to do here by default
+			true
+		    ],
+		    [ $4 ])
+	      ])
 	  ;;
         esac
       ])
@@ -800,3 +833,22 @@
 	AC_DEFINE(SYSCONF$1, 1, [Whether sysconf($1) is available])
     fi
 ])
+
+dnl SMB_IS_LIBPTHREAD_LINKED([actions if true], [actions if false])
+dnl Test whether the current LIBS results in libpthread being present.
+dnl Execute the corresponding user action list.
+AC_DEFUN([SMB_IS_LIBPTHREAD_LINKED],
+[
+    AC_TRY_LINK([],
+	[return pthread_create(0, 0, 0, 0);],
+	[$1],
+	[$2])
+])
+
+dnl SMB_REMOVE_LIB(lib)
+dnl Remove the given library from $LIBS
+AC_DEFUN([SMB_REMOVELIB],
+[
+    LIBS=`echo $LIBS | sed -es/-l$1//g`
+])
+

Modified: branches/SAMBA_3_0/source/configure.in
===================================================================
--- branches/SAMBA_3_0/source/configure.in	2006-05-29 01:30:02 UTC (rev 15927)
+++ branches/SAMBA_3_0/source/configure.in	2006-05-29 02:25:36 UTC (rev 15928)
@@ -412,6 +412,25 @@
 	LIBS="$LIBS -ldmalloc"	
 fi
 
+#################################################
+# check for a shared memory profiling support
+AC_MSG_CHECKING(whether to use profiling)
+AC_ARG_WITH(profiling-data,
+[  --with-profiling-data   Include gathering source code profile information (default=no)],
+[ case "$withval" in
+  yes)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
+    samba_cv_WITH_PROFILE=yes
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    samba_cv_WITH_PROFILE=no
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
+
 dnl Checks for programs.
 
 ##
@@ -2024,8 +2043,23 @@
     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available])
 fi
 
-AC_LIBTESTFUNC(rt, clock_gettime)
+if test x"$samba_cv_WITH_PROFILE" = x"yes"; then
 
+    # On some systems (eg. Linux) librt can pull in libpthread. We
+    # don't want this to happen because libpthreads changes signal delivery
+    # semantics in ways we are not prepared for. This breaks Linux oplocks
+    # which rely on signals.
+
+    AC_LIBTESTFUNC(rt, clock_gettime,
+	    [
+		SMB_IS_LIBPTHREAD_LINKED(
+			[ SMB_REMOVELIB(rt) ],
+			[ AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+			    [Whether clock_gettime is available]) ])
+	    ])
+
+fi
+
 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
 AC_TRY_LINK([#include <stdarg.h>
 va_list ap1,ap2;], [va_copy(ap1,ap2);],
@@ -3976,24 +4010,6 @@
 )
 
 #################################################
-# check for a shared memory profiling support
-AC_MSG_CHECKING(whether to use profiling)
-AC_ARG_WITH(profiling-data,
-[  --with-profiling-data   Include gathering source code profile information (default=no)],
-[ case "$withval" in
-  yes)
-    AC_MSG_RESULT(yes)
-    AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
-    ;;
-  *)
-    AC_MSG_RESULT(no)
-    ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
-
-
-#################################################
 # check for experimental disk-quotas support
 
 samba_cv_WITH_QUOTAS=auto

Modified: trunk/source/aclocal.m4
===================================================================
--- trunk/source/aclocal.m4	2006-05-29 01:30:02 UTC (rev 15927)
+++ trunk/source/aclocal.m4	2006-05-29 02:25:36 UTC (rev 15928)
@@ -104,24 +104,64 @@
 ])
 
 
+dnl AC_LIBTESTFUNC(lib, function, [actions if found], [actions if not found])
 dnl Check for a function in a library, but don't keep adding the same library
 dnl to the LIBS variable.  Check whether the function is available in the
 dnl current LIBS before adding the library which prevents us spuriously
-dnl adding libraries for symbols that are in libc. On success, this ensures that
-dnl HAVE_FOO is defined.
-AC_LIBTESTFUNC(lib,func)
-AC_DEFUN(AC_LIBTESTFUNC,
+dnl adding libraries for symbols that are in libc.
+dnl
+dnl On success, the default actions ensure that HAVE_FOO is defined. The lib
+dnl is always added to $LIBS if it was found to be necessary. The caller
+dnl can use SMB_LIB_REMOVE to strp this if necessary.
+AC_DEFUN([AC_LIBTESTFUNC],
 [
-  AC_CHECK_FUNCS($2, [],
-      [ case "$LIBS" in
-          *-l$1*) ;;
-          *) AC_CHECK_LIB($1, $2,
-	      [
+  AC_CHECK_FUNCS($2,
+      [
+        # $2 was found in libc or existing $LIBS
+	ifelse($3, [],
+	    [
 		AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
 		    [Whether $2 is available])
-	        LIBS="-l$1 $LIBS"
+	    ],
+	    [
+		$3
+	    ])
+      ],
+      [
+        # $2 was not found, try adding lib$1
+	case " $LIBS " in
+          *\ -l$1\ *)
+	    ifelse($4, [],
+		[
+		    # $2 was not found and we already had lib$1
+		    # nothing to do here by default
+		    true
+		],
+		[ $4 ])
+	    ;;
+          *)
+	    # $2 was not found, try adding lib$1
+	    AC_CHECK_LIB($1, $2,
+	      [
+		LIBS="-l$1 $LIBS"
+		ifelse($3, [],
+		    [
+			AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
+			    [Whether $2 is available])
+		    ],
+		    [
+			$3
+		    ])
 	      ],
-	      [])
+	      [
+		ifelse($4, [],
+		    [
+			# $2 was not found in lib$1
+			# nothing to do here by default
+			true
+		    ],
+		    [ $4 ])
+	      ])
 	  ;;
         esac
       ])
@@ -793,3 +833,22 @@
 	AC_DEFINE(SYSCONF$1, 1, [Whether sysconf($1) is available])
     fi
 ])
+
+dnl SMB_IS_LIBPTHREAD_LINKED([actions if true], [actions if false])
+dnl Test whether the current LIBS results in libpthread being present.
+dnl Execute the corresponding user action list.
+AC_DEFUN([SMB_IS_LIBPTHREAD_LINKED],
+[
+    AC_TRY_LINK([],
+	[return pthread_create(0, 0, 0, 0);],
+	[$1],
+	[$2])
+])
+
+dnl SMB_REMOVE_LIB(lib)
+dnl Remove the given library from $LIBS
+AC_DEFUN([SMB_REMOVELIB],
+[
+    LIBS=`echo $LIBS | sed -es/-l$1//g`
+])
+

Modified: trunk/source/configure.in
===================================================================
--- trunk/source/configure.in	2006-05-29 01:30:02 UTC (rev 15927)
+++ trunk/source/configure.in	2006-05-29 02:25:36 UTC (rev 15928)
@@ -412,6 +412,25 @@
 	LIBS="$LIBS -ldmalloc"	
 fi
 
+#################################################
+# check for a shared memory profiling support
+AC_MSG_CHECKING(whether to use profiling)
+AC_ARG_WITH(profiling-data,
+[  --with-profiling-data   Include gathering source code profile information (default=no)],
+[ case "$withval" in
+  yes)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
+    samba_cv_WITH_PROFILE=yes
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    samba_cv_WITH_PROFILE=no
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
+
 dnl Checks for programs.
 
 ##
@@ -2024,8 +2043,23 @@
     AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday() is available])
 fi
 
-AC_LIBTESTFUNC(rt, clock_gettime)
+if test x"$samba_cv_WITH_PROFILE" = x"yes"; then
 
+    # On some systems (eg. Linux) librt can pull in libpthread. We
+    # don't want this to happen because libpthreads changes signal delivery
+    # semantics in ways we are not prepared for. This breaks Linux oplocks
+    # which rely on signals.
+
+    AC_LIBTESTFUNC(rt, clock_gettime,
+	    [
+		SMB_IS_LIBPTHREAD_LINKED(
+			[ SMB_REMOVELIB(rt) ],
+			[ AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+			    [Whether clock_gettime is available]) ])
+	    ])
+
+fi
+
 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
 AC_TRY_LINK([#include <stdarg.h>
 va_list ap1,ap2;], [va_copy(ap1,ap2);],
@@ -3976,24 +4010,6 @@
 )
 
 #################################################
-# check for a shared memory profiling support
-AC_MSG_CHECKING(whether to use profiling)
-AC_ARG_WITH(profiling-data,
-[  --with-profiling-data   Include gathering source code profile information (default=no)],
-[ case "$withval" in
-  yes)
-    AC_MSG_RESULT(yes)
-    AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling])
-    ;;
-  *)
-    AC_MSG_RESULT(no)
-    ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
-
-
-#################################################
 # check for experimental disk-quotas support
 
 samba_cv_WITH_QUOTAS=auto



More information about the samba-cvs mailing list