[Pixman] Build system patches for threading.

M Joonas Pihlaja jpihlaja at cc.helsinki.fi
Sun Jul 11 06:24:43 PDT 2010


Hey,

I've spent some time making pixman work on different unixlikes and 
fixed a bunch of problems.  Patches attached, but also in the (no 
longer volatile) pthreads branch at

http://cgit.freedesktop.org/~joonas/pixman/log/?h=pthreads.

Cheers,

Joonas
-------------- next part --------------
From 1c6f4a9efa1a465db1135ae374411f526aa33e4f Mon Sep 17 00:00:00 2001
From: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Fri, 9 Jul 2010 12:07:35 +0300
Subject: [PATCH 1/4] Try harder to find suitable flags for pthreads.

The flags -D_REENTRANT -lpthread work on more systems than
does -pthread unfortunately, so give that a go too.
---
 configure.ac       |   65 ++++++++++++++++++++++++++++++++-------------------
 pixman/Makefile.am |    2 +-
 2 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 56a6e4d..b9488d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -527,12 +527,12 @@ dnl Thread local storage
 support_for__thread=no
 
 AC_MSG_CHECKING(for __thread)
-AC_COMPILE_IFELSE([
+AC_LINK_IFELSE([
 #ifdef __MINGW32__
 #error MinGW has broken __thread support
 #endif
-__thread int x ;
-int main () { return 0; }
+static __thread int x ;
+int main () { x = 123; return x; }
 ], support_for__thread=yes)
 
 if test $support_for__thread = yes; then 
@@ -541,21 +541,11 @@ fi
 
 AC_MSG_RESULT($support_for__thread)
 
+dnl
 dnl posix tls
+dnl
 
-if test $support_for__thread = no; then
-
-support_for_pthread_setspecific=no
-   
-AC_MSG_CHECKING(for pthread_setspecific)
-
-save_LDFLAGS=$LDFLAGS
-
-LDFLAGS="-pthread"
-
-AC_LINK_IFELSE([
-#include <pthread.h>
-
+m4_define([pthread_test_program],[dnl
 #include <stdlib.h>
 #include <pthread.h>
 
@@ -572,7 +562,7 @@ int
 main ()
 {
     void *value = NULL;
-    
+
     if (pthread_once (&once_control, make_key) != 0)
     {
 	value = NULL;
@@ -586,23 +576,50 @@ main ()
 	    pthread_setspecific (key, value);
 	}
     }
+    return 0;
 }
-], support_for_pthread_setspecific=yes);
+])
+
+AC_DEFUN([PIXMAN_CHECK_PTHREAD],[dnl
+    if test "z$support_for_pthread_setspecific" != "zyes"; then
+	save_CFLAGS="$CFLAGS"
+	save_LDFLAGS="$LDFLAGS"
+	save_LIBS="$LIBS"
+	CFLAGS=""
+	LDFLAGS=""
+	LIBS=""
+	$1
+	AC_LINK_IFELSE([pthread_test_program],
+		[PTHREAD_CFLAGS="$CFLAGS"
+		 PTHREAD_LIBS="$LIBS"
+		 PTHREAD_LDFLAGS="$LDFLAGS"
+		 support_for_pthread_setspecific=yes])
+	CFLAGS="$save_CFLAGS"
+	LDFLAGS="$save_LDFLAGS"
+	LIBS="$save_LIBS"
+    fi
+])
+
+if test $support_for__thread = no; then
+    support_for_pthread_setspecific=no
 
-LDFLAGS=$save_LDFLAGS
+    AC_MSG_CHECKING(for pthread_setspecific)
 
-if test $support_for_pthread_setspecific = yes; then
-   PTHREAD_LDFLAGS="-pthread"
-   AC_DEFINE([HAVE_PTHREAD_SETSPECIFIC], [], [Whether pthread_setspecific() is supported])
-fi
+    PIXMAN_CHECK_PTHREAD([CFLAGS="-D_REENTRANT"; LIBS="-lpthread"])
+    PIXMAN_CHECK_PTHREAD([CFLAGS="-pthread"; LDFLAGS="-pthread"])
 
-AC_MSG_RESULT($support_for_pthread_setspecific);
+    if test $support_for_pthread_setspecific = yes; then
+	CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+	AC_DEFINE([HAVE_PTHREAD_SETSPECIFIC], [], [Whether pthread_setspecific() is supported])
+    fi
 
+    AC_MSG_RESULT($support_for_pthread_setspecific);
 fi
 
 AC_SUBST(TOOLCHAIN_SUPPORTS__THREAD)
 AC_SUBST(HAVE_PTHREAD_SETSPECIFIC)
 AC_SUBST(PTHREAD_LDFLAGS)
+AC_SUBST(PTHREAD_LIBS)
 
 AC_OUTPUT([pixman-1.pc
            pixman-1-uninstalled.pc
diff --git a/pixman/Makefile.am b/pixman/Makefile.am
index 66ad7f0..7538219 100644
--- a/pixman/Makefile.am
+++ b/pixman/Makefile.am
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libpixman-1.la
 libpixman_1_la_LDFLAGS = -version-info $(LT_VERSION_INFO) -no-undefined @PTHREAD_LDFLAGS@ 
-libpixman_1_la_LIBADD = @DEP_LIBS@ -lm
+libpixman_1_la_LIBADD = @PTHREAD_LIBS@ @DEP_LIBS@ -lm
 libpixman_1_la_SOURCES =			\
 	pixman.h				\
 	pixman-accessor.h			\
-- 
1.7.1.GIT

-------------- next part --------------
From aa3b84c205e4f6824cef158e4c06eed37a8c1145 Mon Sep 17 00:00:00 2001
From: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Fri, 9 Jul 2010 12:09:07 +0300
Subject: [PATCH 2/4] Don't trust OpenBSD's gcc to produce working code for __thread.

The gcc on OpenBSD 4.5 to 4.7 at least produces bad code for __thread,
without as much as a warning.

See PR #6410 "Using __thread TLS variables compiles ok but segfault at runtime."

http://cvs.openbsd.org/cgi-bin/query-pr-wrapper?full=yes&numbers=6410
---
 configure.ac |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index b9488d9..3c6f01d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -531,6 +531,9 @@ AC_LINK_IFELSE([
 #ifdef __MINGW32__
 #error MinGW has broken __thread support
 #endif
+#ifdef __OpenBSD__
+#error OpenBSD has broken __thread support
+#endif
 static __thread int x ;
 int main () { x = 123; return x; }
 ], support_for__thread=yes)
-- 
1.7.1.GIT

-------------- next part --------------
From ef6e06058878a46c4eb9b0f8fdaea3a2ad71386f Mon Sep 17 00:00:00 2001
From: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sat, 10 Jul 2010 02:41:01 +0100
Subject: [PATCH 3/4] Check that the OpenMP pragmas don't cause link errors.

This patch adds extra guards around our use of
OpenMP pragmas and checks that the pragmas won't
cause link errors.  This fixes the build on
Tru64 and Solaris with the native compilers and clang.
---
 configure.ac |   87 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 test/utils.c |    2 +
 test/utils.h |    2 +
 3 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/configure.ac b/configure.ac
index 3c6f01d..d6f1d1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,9 +77,22 @@ AC_CHECK_FUNCS([getisax])
 AC_C_BIGENDIAN
 AC_C_INLINE
 
-# Check for OpenMP support (only supported by autoconf >=2.62)
-OPENMP_CFLAGS=
-m4_ifdef([AC_OPENMP], [AC_OPENMP], [AC_SUBST(OPENMP_CFLAGS)])
+dnl PIXMAN_LINK_WITH_ENV(
+dnl	CFLAGS=... LDFLAGS=... LIBS=...,
+dnl	program, true-action, false-action)
+AC_DEFUN([PIXMAN_LINK_WITH_ENV],[dnl
+	save_CFLAGS="$CFLAGS"
+	save_LDFLAGS="$LDFLAGS"
+	save_LIBS="$LIBS"
+	CFLAGS=""
+	LDFLAGS=""
+	LIBS=""
+	$1
+	AC_LINK_IFELSE([$2], [$3], [$4])
+	CFLAGS="$save_CFLAGS"
+	LDFLAGS="$save_LDFLAGS"
+	LIBS="$save_LIBS"
+])
 
 AC_CHECK_SIZEOF(long)
 
@@ -143,6 +156,61 @@ fi
 AC_SUBST(PERL)
 
 dnl =========================================================================
+dnl OpenMP for the test suite?
+dnl
+
+# Check for OpenMP support (only supported by autoconf >=2.62)
+OPENMP_CFLAGS=
+m4_ifdef([AC_OPENMP], [AC_OPENMP])
+
+m4_define([openmp_test_program],[dnl
+#include <stdio.h>
+
+extern unsigned int lcg_seed;
+#pragma omp threadprivate(lcg_seed)
+unsigned int lcg_seed;
+
+unsigned function(unsigned a, unsigned b)
+{
+	lcg_seed ^= b;
+	return ((a + b) ^ a ) + lcg_seed;
+}
+
+int main(int argc, char **argv)
+{
+	int i;
+	int n1 = 0, n2 = argc;
+	unsigned checksum = 0;
+	int verbose = argv != NULL;
+	unsigned (*test_function)(unsigned, unsigned);
+	test_function = function;
+    #pragma omp parallel for reduction(+:checksum) default(none) \
+					shared(n1, n2, test_function, verbose)
+	for (i = n1; i < n2; i++)
+    	{
+		unsigned crc = test_function (i, 0);
+		if (verbose)
+			printf ("%d: %08X\n", i, crc);
+		checksum += crc;
+	}
+	printf("%u\n", checksum);
+	return 0;
+}
+])
+
+PIXMAN_LINK_WITH_ENV(
+	[CFLAGS="$OPENMP_CFLAGS" LDFLAGS="$OPENMP_CFLAGS"],
+	[openmp_test_program],
+	[have_openmp=yes],
+	[have_openmp=no])
+if test "x$have_openmp" = "xyes"; then
+   AC_DEFINE(USE_OPENMP, 1, [use OpenMP in the test suite])
+else
+   OPENMP_CFLAGS=""
+fi
+AC_SUBST(OPENMP_CFLAGS)
+
+dnl =========================================================================
 dnl -fvisibility stuff
 
 have_gcc4=no
@@ -585,21 +653,12 @@ main ()
 
 AC_DEFUN([PIXMAN_CHECK_PTHREAD],[dnl
     if test "z$support_for_pthread_setspecific" != "zyes"; then
-	save_CFLAGS="$CFLAGS"
-	save_LDFLAGS="$LDFLAGS"
-	save_LIBS="$LIBS"
-	CFLAGS=""
-	LDFLAGS=""
-	LIBS=""
-	$1
-	AC_LINK_IFELSE([pthread_test_program],
+	PIXMAN_LINK_WITH_ENV(
+		[$1], [pthread_test_program],
 		[PTHREAD_CFLAGS="$CFLAGS"
 		 PTHREAD_LIBS="$LIBS"
 		 PTHREAD_LDFLAGS="$LDFLAGS"
 		 support_for_pthread_setspecific=yes])
-	CFLAGS="$save_CFLAGS"
-	LDFLAGS="$save_LDFLAGS"
-	LIBS="$save_LIBS"
     fi
 ])
 
diff --git a/test/utils.c b/test/utils.c
index e9b29c8..1ee5c9c 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -286,8 +286,10 @@ fuzzer_test_main (const char *test_name,
 	n2 = default_number_of_iterations;
     }
 
+#ifdef USE_OPENMP
     #pragma omp parallel for reduction(+:checksum) default(none) \
 					shared(n1, n2, test_function, verbose)
+#endif
     for (i = n1; i <= n2; i++)
     {
 	uint32_t crc = test_function (i, 0);
diff --git a/test/utils.h b/test/utils.h
index 26a244c..8ec7b17 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -7,7 +7,9 @@
  */
 
 extern uint32_t lcg_seed;
+#ifdef USE_OPENMP
 #pragma omp threadprivate(lcg_seed)
+#endif
 
 static inline uint32_t
 lcg_rand (void)
-- 
1.7.1.GIT

-------------- next part --------------
From 2a6e12df0a6daad604ac1cfadc9f5b9982b35663 Mon Sep 17 00:00:00 2001
From: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date: Sat, 10 Jul 2010 15:36:41 +0300
Subject: [PATCH 4/4] Check for specific flags by actually trying to compile and link.

Instead of relying on preprocessor version checks to see if a
some compiler flags are supported, actually try to compile and
link a test program with the flags.
---
 configure.ac |  100 ++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 59 insertions(+), 41 deletions(-)

diff --git a/configure.ac b/configure.ac
index d6f1d1c..c97c45d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,9 +77,10 @@ AC_CHECK_FUNCS([getisax])
 AC_C_BIGENDIAN
 AC_C_INLINE
 
-dnl PIXMAN_LINK_WITH_ENV(
-dnl	CFLAGS=... LDFLAGS=... LIBS=...,
-dnl	program, true-action, false-action)
+dnl PIXMAN_LINK_WITH_ENV(env-setup, program, true-action, false-action)
+dnl
+dnl Compiles and links the given program in the environment setup by env-setup
+dnl and executes true-action on success and false-action on failure.
 AC_DEFUN([PIXMAN_LINK_WITH_ENV],[dnl
 	save_CFLAGS="$CFLAGS"
 	save_LDFLAGS="$LDFLAGS"
@@ -88,10 +89,55 @@ AC_DEFUN([PIXMAN_LINK_WITH_ENV],[dnl
 	LDFLAGS=""
 	LIBS=""
 	$1
-	AC_LINK_IFELSE([$2], [$3], [$4])
-	CFLAGS="$save_CFLAGS"
-	LDFLAGS="$save_LDFLAGS"
-	LIBS="$save_LIBS"
+	AC_LINK_IFELSE(
+		[$2],
+		[pixman_cc_stderr=`test -f conftest.err && cat conftest.err`
+		 pixman_cc_flag=yes],
+		[pixman_cc_stderr=`test -f conftest.err && cat conftest.err`
+		 pixman_cc_flag=no])
+
+	if test "x$pixman_cc_stderr" != "x"; then
+		pixman_cc_flag=no
+	fi
+
+	if test "x$pixman_cc_flag" = "xyes"; then
+		ifelse([$3], , :, [$3])
+	else
+		ifelse([$4], , :, [$4])
+	fi
+	CFLAGS="$save_cflags"
+	LDFLAGS="$save_ldflags"
+	LIBS="$save_libs"
+])
+
+dnl Find a -Werror for catching warnings.
+WERROR=
+for w in -Werror -errwarn; do
+    if test "z$WERROR" = "z"; then
+        AC_MSG_CHECKING([whether the compiler supports $w])
+        PIXMAN_LINK_WITH_ENV(
+		[CFLAGS=$w],
+		[int main(int c, char **v) { (void)c; (void)v; return 0; }],
+		[WERROR=$w; yesno=yes], [yesno=no])
+	AC_MSG_RESULT($_yesno)
+    fi
+done
+
+dnl PIXMAN_CHECK_CFLAG(flag, [program])
+dnl  Adds flag to CFLAGS if the given program links without warnings or errors.
+AC_DEFUN([PIXMAN_CHECK_CFLAG], [dnl
+	AC_MSG_CHECKING([whether the compiler supports $1])
+	PIXMAN_LINK_WITH_ENV(
+		[CFLAGS="$WERROR $1"],
+		[$2
+		 int main(int c, char **v) { (void)c; (void)v; return 0; }
+		],
+		[_yesno=yes],
+		[_yesno=no])
+	if test "x$_yesno" = xyes; then
+	   CFLAGS="$CFLAGS $1"
+	fi
+	AC_MSG_RESULT($_yesno)
 ])
 
 AC_CHECK_SIZEOF(long)
@@ -134,20 +180,8 @@ AC_SUBST(LT_VERSION_INFO)
 # Check for dependencies
 #PKG_CHECK_MODULES(DEP, x11)
 
-changequote(,)dnl
-if test "x$GCC" = "xyes"; then
-
-  case " $CFLAGS " in
-  *[\ \	]-Wall[\ \	]*) ;;
-  *) CFLAGS="$CFLAGS -Wall" ;;
-  esac 
-
-  case " $CFLAGS " in
-  *[\ \	]-fno-strict-aliasing[\ \	]*) ;;
-  *) CFLAGS="$CFLAGS -fno-strict-aliasing" ;;
-  esac
-
-fi changequote([,])dnl
+PIXMAN_CHECK_CFLAG([-Wall])
+PIXMAN_CHECK_CFLAG([-fno-strict-aliasing])
 
 AC_PATH_PROG(PERL, perl, no)
 if test "x$PERL" = xno; then
@@ -213,35 +247,19 @@ AC_SUBST(OPENMP_CFLAGS)
 dnl =========================================================================
 dnl -fvisibility stuff
 
-have_gcc4=no
-AC_MSG_CHECKING(for -fvisibility)
-AC_COMPILE_IFELSE([
+PIXMAN_CHECK_CFLAG([-fvisibility=hidden], [dnl
 #if defined(__GNUC__) && (__GNUC__ >= 4)
 #else
 error Need GCC 4.0 for visibility
 #endif
-int main () { return 0; } 
-], have_gcc4=yes)
-
-if test "x$have_gcc4" = "xyes"; then
-   CFLAGS="$CFLAGS -fvisibility=hidden"
-fi
-AC_MSG_RESULT($have_gcc4)
+])
 
-have_sunstudio8=no
-AC_MSG_CHECKING([for -xldscope (Sun compilers)])
-AC_COMPILE_IFELSE([
+PIXMAN_CHECK_CFLAG([-xldscope=hidden], [dnl
 #if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
 #else
 error Need Sun Studio 8 for visibility
 #endif
-int main () { return 0; } 
-], have_sunstudio8=yes)
-
-if test "x$have_sunstudio8" = "xyes"; then
-   CFLAGS="$CFLAGS -xldscope=hidden"
-fi
-AC_MSG_RESULT($have_sunstudio8)
+])
 
 dnl ===========================================================================
 dnl Check for MMX
-- 
1.7.1.GIT



More information about the Pixman mailing list