Introduce DISABLE_PTHREAD_SPINLOCK_INTERCEPT flag

The flag DISABLE_PTHREAD_SPINLOCK_INTERCEPT is set only for MIPS32, and it is
used in DRD and Helgrind as a workaround for the issue #311690.
In short, pthread_spin_lock implementation has local branches to the start of
the function which interferes with the redirection system in Valgrind that
assumes it has to redirect each call/branch to a particular address.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13190 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.in b/configure.in
index 78b5339..e0fb12d 100644
--- a/configure.in
+++ b/configure.in
@@ -2053,6 +2053,10 @@
 AM_CONDITIONAL([HAVE_PTHREAD_SPINLOCK],
                [test x$ac_cv_func_pthread_spin_lock = xyes])
 
+if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX ; then
+  AC_DEFINE([DISABLE_PTHREAD_SPINLOCK_INTERCEPT], 1,
+            [Disable intercept pthread_spin_lock() on MIPS32.])
+fi
 
 #----------------------------------------------------------------------------
 # MPI checks
diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c
index 9eaae07..a0db0cc 100644
--- a/drd/drd_pthread_intercepts.c
+++ b/drd/drd_pthread_intercepts.c
@@ -803,7 +803,8 @@
 PTH_FUNCS(int, pthreadZucondZubroadcast, pthread_cond_broadcast_intercept,
           (pthread_cond_t* cond), (cond));
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
+#if defined(HAVE_PTHREAD_SPIN_LOCK) \
+    && !defined(DISABLE_PTHREAD_SPINLOCK_INTERCEPT)
 static __always_inline
 int pthread_spin_init_intercept(pthread_spinlock_t *spinlock, int pshared)
 {
diff --git a/drd/tests/pth_spinlock.vgtest b/drd/tests/pth_spinlock.vgtest
index 48aa40d..213bec0 100644
--- a/drd/tests/pth_spinlock.vgtest
+++ b/drd/tests/pth_spinlock.vgtest
@@ -1,3 +1,3 @@
-prereq: test -e pth_spinlock && ./supported_libpthread
+prereq: test -e pth_spinlock && ./supported_libpthread && grep '#undef DISABLE_PTHREAD_SPINLOCK_INTERCEPT' ../../config.h > /dev/null
 vgopts: --read-var-info=yes --check-stack-var=yes
 prog: pth_spinlock
diff --git a/helgrind/hg_intercepts.c b/helgrind/hg_intercepts.c
index 944cadf..90a5e9e 100644
--- a/helgrind/hg_intercepts.c
+++ b/helgrind/hg_intercepts.c
@@ -1095,7 +1095,8 @@
 /*--- pthread_spinlock_t functions                             ---*/
 /*----------------------------------------------------------------*/
 
-#if defined(HAVE_PTHREAD_SPIN_LOCK)
+#if defined(HAVE_PTHREAD_SPIN_LOCK) \
+    && !defined(DISABLE_PTHREAD_SPINLOCK_INTERCEPT)
 
 /* Handled:   pthread_spin_init pthread_spin_destroy
               pthread_spin_lock pthread_spin_trylock