Bug 965870 - Check for __builtin_ffsl before ffsl. r=mshal
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 06 Jun 2014 08:17:02 +0900
changeset 199445 7ab785fa6f362a98852f4bc28e7657ce230fc457
parent 199444 b3b490f2ddc6a9d31b4d5d209016519d61f440af
child 199446 8b809afd1ceaa0d8d53df0f9c7e764c98ae91085
push idunknown
push userunknown
push dateunknown
reviewersmshal
bugs965870
milestone32.0a1
Bug 965870 - Check for __builtin_ffsl before ffsl. r=mshal Cherry-picked from https://github.com/jemalloc/jemalloc/commit/1a3eafd1b045163f27e4a5acf01280edfe28c309
memory/jemalloc/0005-Check-for-__builtin_ffsl-before-ffsl.patch
memory/jemalloc/src/configure
memory/jemalloc/src/configure.ac
memory/jemalloc/update.sh
new file mode 100644
--- /dev/null
+++ b/memory/jemalloc/0005-Check-for-__builtin_ffsl-before-ffsl.patch
@@ -0,0 +1,225 @@
+diff --git a/configure b/configure
+--- a/configure
++++ b/configure
+@@ -6904,27 +6904,70 @@ if test "x${enable_tls}" = "x1" ; then
+ #define JEMALLOC_TLS
+ _ACEOF
+ 
+ elif test "x${force_tls}" = "x1" ; then
+   as_fn_error $? "Failed to configure TLS, which is mandatory for correct function" "$LINENO" 5
+ fi
+ 
+ 
++{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using __builtin_ffsl is compilable" >&5
++$as_echo_n "checking whether a program using __builtin_ffsl is compilable... " >&6; }
++if ${je_cv_gcc_builtin_ffsl+:} false; then :
++  $as_echo_n "(cached) " >&6
++else
++  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++
++#include <stdio.h>
++#include <strings.h>
++#include <string.h>
++
++int
++main ()
++{
++
++	{
++		int rv = __builtin_ffsl(0x08);
++		printf("%d\n", rv);
++	}
++
++  ;
++  return 0;
++}
++_ACEOF
++if ac_fn_c_try_link "$LINENO"; then :
++  je_cv_gcc_builtin_ffsl=yes
++else
++  je_cv_gcc_builtin_ffsl=no
++fi
++rm -f core conftest.err conftest.$ac_objext \
++    conftest$ac_exeext conftest.$ac_ext
++fi
++{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_gcc_builtin_ffsl" >&5
++$as_echo "$je_cv_gcc_builtin_ffsl" >&6; }
++
++if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
++  $as_echo "#define JEMALLOC_INTERNAL_FFSL __builtin_ffsl" >>confdefs.h
++
++  $as_echo "#define JEMALLOC_INTERNAL_FFS __builtin_ffs" >>confdefs.h
++
++else
++
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using ffsl is compilable" >&5
+ $as_echo_n "checking whether a program using ffsl is compilable... " >&6; }
+ if ${je_cv_function_ffsl+:} false; then :
+   $as_echo_n "(cached) " >&6
+ else
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h.  */
+ 
+-#include <stdio.h>
+-#include <strings.h>
+-#include <string.h>
++  #include <stdio.h>
++  #include <strings.h>
++  #include <string.h>
+ 
+ int
+ main ()
+ {
+ 
+ 	{
+ 		int rv = ffsl(0x08);
+ 		printf("%d\n", rv);
+@@ -6940,71 +6983,29 @@ else
+   je_cv_function_ffsl=no
+ fi
+ rm -f core conftest.err conftest.$ac_objext \
+     conftest$ac_exeext conftest.$ac_ext
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_function_ffsl" >&5
+ $as_echo "$je_cv_function_ffsl" >&6; }
+ 
+-if test "x${je_cv_function_ffsl}" == "xyes" ; then
+-  $as_echo "#define JEMALLOC_INTERNAL_FFSL ffsl" >>confdefs.h
+-
+-  $as_echo "#define JEMALLOC_INTERNAL_FFS ffs" >>confdefs.h
+-
+-else
+-
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using __builtin_ffsl is compilable" >&5
+-$as_echo_n "checking whether a program using __builtin_ffsl is compilable... " >&6; }
+-if ${je_cv_gcc_builtin_ffsl+:} false; then :
+-  $as_echo_n "(cached) " >&6
+-else
+-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+-/* end confdefs.h.  */
+-
+-  #include <stdio.h>
+-  #include <strings.h>
+-  #include <string.h>
+-
+-int
+-main ()
+-{
+-
+-	{
+-		int rv = __builtin_ffsl(0x08);
+-		printf("%d\n", rv);
+-	}
+-
+-  ;
+-  return 0;
+-}
+-_ACEOF
+-if ac_fn_c_try_link "$LINENO"; then :
+-  je_cv_gcc_builtin_ffsl=yes
+-else
+-  je_cv_gcc_builtin_ffsl=no
+-fi
+-rm -f core conftest.err conftest.$ac_objext \
+-    conftest$ac_exeext conftest.$ac_ext
+-fi
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_gcc_builtin_ffsl" >&5
+-$as_echo "$je_cv_gcc_builtin_ffsl" >&6; }
+-
+-  if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
+-    $as_echo "#define JEMALLOC_INTERNAL_FFSL __builtin_ffsl" >>confdefs.h
+-
+-    $as_echo "#define JEMALLOC_INTERNAL_FFS __builtin_ffs" >>confdefs.h
++  if test "x${je_cv_function_ffsl}" == "xyes" ; then
++    $as_echo "#define JEMALLOC_INTERNAL_FFSL ffsl" >>confdefs.h
++
++    $as_echo "#define JEMALLOC_INTERNAL_FFS ffs" >>confdefs.h
+ 
+   else
+     as_fn_error $? "Cannot build without ffsl(3) or __builtin_ffsl()" "$LINENO" 5
+   fi
+ fi
+ 
+ 
+ 
++
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether atomic(9) is compilable" >&5
+ $as_echo_n "checking whether atomic(9) is compilable... " >&6; }
+ if ${je_cv_atomic9+:} false; then :
+   $as_echo_n "(cached) " >&6
+ else
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h.  */
+ 
+diff --git a/configure.ac b/configure.ac
+--- a/configure.ac
++++ b/configure.ac
+@@ -1160,53 +1160,54 @@ fi
+ AC_SUBST([enable_tls])
+ if test "x${enable_tls}" = "x1" ; then
+   AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
+ elif test "x${force_tls}" = "x1" ; then
+   AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
+ fi
+ 
+ dnl ============================================================================
+-dnl Check for ffsl(3), then __builtin_ffsl(), and fail if neither are found.
++dnl Check for  __builtin_ffsl(), then ffsl(3), and fail if neither are found.
+ dnl One of those two functions should (theoretically) exist on all platforms
+ dnl that jemalloc currently has a chance of functioning on without modification.
+ dnl We additionally assume ffs() or __builtin_ffs() are defined if
+ dnl ffsl() or __builtin_ffsl() are defined, respectively.
+-JE_COMPILABLE([a program using ffsl], [
++JE_COMPILABLE([a program using __builtin_ffsl], [
+ #include <stdio.h>
+ #include <strings.h>
+ #include <string.h>
+ ], [
+ 	{
+-		int rv = ffsl(0x08);
++		int rv = __builtin_ffsl(0x08);
+ 		printf("%d\n", rv);
+ 	}
+-], [je_cv_function_ffsl])
+-if test "x${je_cv_function_ffsl}" == "xyes" ; then
+-  AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
+-  AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
++], [je_cv_gcc_builtin_ffsl])
++if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
++  AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
++  AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
+ else
+-  JE_COMPILABLE([a program using __builtin_ffsl], [
++  JE_COMPILABLE([a program using ffsl], [
+   #include <stdio.h>
+   #include <strings.h>
+   #include <string.h>
+   ], [
+ 	{
+-		int rv = __builtin_ffsl(0x08);
++		int rv = ffsl(0x08);
+ 		printf("%d\n", rv);
+ 	}
+-  ], [je_cv_gcc_builtin_ffsl])
+-  if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
+-    AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
+-    AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
++  ], [je_cv_function_ffsl])
++  if test "x${je_cv_function_ffsl}" == "xyes" ; then
++    AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
++    AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
+   else
+     AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
+   fi
+ fi
+ 
++
+ dnl ============================================================================
+ dnl Check for atomic(9) operations as provided on FreeBSD.
+ 
+ JE_COMPILABLE([atomic(9)], [
+ #include <sys/types.h>
+ #include <machine/atomic.h>
+ #include <inttypes.h>
+ ], [
--- a/memory/jemalloc/src/configure
+++ b/memory/jemalloc/src/configure
@@ -6904,33 +6904,76 @@ if test "x${enable_tls}" = "x1" ; then
 #define JEMALLOC_TLS
 _ACEOF
 
 elif test "x${force_tls}" = "x1" ; then
   as_fn_error $? "Failed to configure TLS, which is mandatory for correct function" "$LINENO" 5
 fi
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using ffsl is compilable" >&5
-$as_echo_n "checking whether a program using ffsl is compilable... " >&6; }
-if ${je_cv_function_ffsl+:} false; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using __builtin_ffsl is compilable" >&5
+$as_echo_n "checking whether a program using __builtin_ffsl is compilable... " >&6; }
+if ${je_cv_gcc_builtin_ffsl+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
 #include <stdio.h>
 #include <strings.h>
 #include <string.h>
 
 int
 main ()
 {
 
 	{
+		int rv = __builtin_ffsl(0x08);
+		printf("%d\n", rv);
+	}
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  je_cv_gcc_builtin_ffsl=yes
+else
+  je_cv_gcc_builtin_ffsl=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_gcc_builtin_ffsl" >&5
+$as_echo "$je_cv_gcc_builtin_ffsl" >&6; }
+
+if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
+  $as_echo "#define JEMALLOC_INTERNAL_FFSL __builtin_ffsl" >>confdefs.h
+
+  $as_echo "#define JEMALLOC_INTERNAL_FFS __builtin_ffs" >>confdefs.h
+
+else
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using ffsl is compilable" >&5
+$as_echo_n "checking whether a program using ffsl is compilable... " >&6; }
+if ${je_cv_function_ffsl+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+  #include <stdio.h>
+  #include <strings.h>
+  #include <string.h>
+
+int
+main ()
+{
+
+	{
 		int rv = ffsl(0x08);
 		printf("%d\n", rv);
 	}
 
   ;
   return 0;
 }
 _ACEOF
@@ -6940,71 +6983,29 @@ else
   je_cv_function_ffsl=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_function_ffsl" >&5
 $as_echo "$je_cv_function_ffsl" >&6; }
 
-if test "x${je_cv_function_ffsl}" == "xyes" ; then
-  $as_echo "#define JEMALLOC_INTERNAL_FFSL ffsl" >>confdefs.h
-
-  $as_echo "#define JEMALLOC_INTERNAL_FFS ffs" >>confdefs.h
-
-else
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program using __builtin_ffsl is compilable" >&5
-$as_echo_n "checking whether a program using __builtin_ffsl is compilable... " >&6; }
-if ${je_cv_gcc_builtin_ffsl+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-  #include <stdio.h>
-  #include <strings.h>
-  #include <string.h>
-
-int
-main ()
-{
-
-	{
-		int rv = __builtin_ffsl(0x08);
-		printf("%d\n", rv);
-	}
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  je_cv_gcc_builtin_ffsl=yes
-else
-  je_cv_gcc_builtin_ffsl=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $je_cv_gcc_builtin_ffsl" >&5
-$as_echo "$je_cv_gcc_builtin_ffsl" >&6; }
-
-  if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
-    $as_echo "#define JEMALLOC_INTERNAL_FFSL __builtin_ffsl" >>confdefs.h
-
-    $as_echo "#define JEMALLOC_INTERNAL_FFS __builtin_ffs" >>confdefs.h
+  if test "x${je_cv_function_ffsl}" == "xyes" ; then
+    $as_echo "#define JEMALLOC_INTERNAL_FFSL ffsl" >>confdefs.h
+
+    $as_echo "#define JEMALLOC_INTERNAL_FFS ffs" >>confdefs.h
 
   else
     as_fn_error $? "Cannot build without ffsl(3) or __builtin_ffsl()" "$LINENO" 5
   fi
 fi
 
 
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether atomic(9) is compilable" >&5
 $as_echo_n "checking whether atomic(9) is compilable... " >&6; }
 if ${je_cv_atomic9+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
--- a/memory/jemalloc/src/configure.ac
+++ b/memory/jemalloc/src/configure.ac
@@ -1160,53 +1160,54 @@ fi
 AC_SUBST([enable_tls])
 if test "x${enable_tls}" = "x1" ; then
   AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
 elif test "x${force_tls}" = "x1" ; then
   AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
 fi
 
 dnl ============================================================================
-dnl Check for ffsl(3), then __builtin_ffsl(), and fail if neither are found.
+dnl Check for  __builtin_ffsl(), then ffsl(3), and fail if neither are found.
 dnl One of those two functions should (theoretically) exist on all platforms
 dnl that jemalloc currently has a chance of functioning on without modification.
 dnl We additionally assume ffs() or __builtin_ffs() are defined if
 dnl ffsl() or __builtin_ffsl() are defined, respectively.
-JE_COMPILABLE([a program using ffsl], [
+JE_COMPILABLE([a program using __builtin_ffsl], [
 #include <stdio.h>
 #include <strings.h>
 #include <string.h>
 ], [
 	{
-		int rv = ffsl(0x08);
+		int rv = __builtin_ffsl(0x08);
 		printf("%d\n", rv);
 	}
-], [je_cv_function_ffsl])
-if test "x${je_cv_function_ffsl}" == "xyes" ; then
-  AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
-  AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
+], [je_cv_gcc_builtin_ffsl])
+if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
+  AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
+  AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
 else
-  JE_COMPILABLE([a program using __builtin_ffsl], [
+  JE_COMPILABLE([a program using ffsl], [
   #include <stdio.h>
   #include <strings.h>
   #include <string.h>
   ], [
 	{
-		int rv = __builtin_ffsl(0x08);
+		int rv = ffsl(0x08);
 		printf("%d\n", rv);
 	}
-  ], [je_cv_gcc_builtin_ffsl])
-  if test "x${je_cv_gcc_builtin_ffsl}" == "xyes" ; then
-    AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
-    AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
+  ], [je_cv_function_ffsl])
+  if test "x${je_cv_function_ffsl}" == "xyes" ; then
+    AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
+    AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
   else
     AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
   fi
 fi
 
+
 dnl ============================================================================
 dnl Check for atomic(9) operations as provided on FreeBSD.
 
 JE_COMPILABLE([atomic(9)], [
 #include <sys/types.h>
 #include <machine/atomic.h>
 #include <inttypes.h>
 ], [
--- a/memory/jemalloc/update.sh
+++ b/memory/jemalloc/update.sh
@@ -13,13 +13,14 @@ git checkout "$UPSTREAM_COMMIT"
 autoconf
 git describe --long --abbrev=40 > VERSION
 rm -rf .git .gitignore autom4te.cache
 
 patch -p1 < ../0001-Use-a-configure-test-to-detect-whether-to-use-a-cons.patch
 patch -p1 < ../0002-Use-ULL-prefix-instead-of-LLU-for-unsigned-long-long.patch
 patch -p1 < ../0003-Don-t-use-msvc_compat-s-C99-headers-with-MSVC-versio.patch
 patch -p1 < ../0004-Try-to-use-__builtin_ffsl-if-ffsl-is-unavailable.patch
+patch -p1 < ../0005-Check-for-__builtin_ffsl-before-ffsl.patch
 
 cd ..
 hg addremove -q src
 
 echo "jemalloc has now been updated.  Don't forget to run hg commit!"