Revision: 40 http://trac.macosforge.org/projects/libdispatch/changeset/40 Author: robert@fledge.watson.org Date: 2009-09-25 02:53:30 -0700 (Fri, 25 Sep 2009) Log Message: ----------- Rather than hard-code -march in order to enable gcc built-in atomics on i386, which caused build problems for other architectures, add configure support for detecting the requirement. This proves somewhat subtle: gcc is sometimes able to partially implement built-in atomics even with reduced instruction sets and will only fall back to unimplemented library symbols. As such, we must specifically not just test for __sync_add_and_fetch linking, but also with it used with a return value. Arguably, we should only try -march=i486 on i386 systems. Submitted by: Peter O'Gorman (earlier version) Modified Paths: -------------- trunk/configure.ac trunk/src/Makefile.am Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-09-25 08:44:52 UTC (rev 39) +++ trunk/configure.ac 2009-09-25 09:53:30 UTC (rev 40) @@ -109,6 +109,32 @@ AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) # +# This is a bit subtle: on i386 systems without at least -march=i486 defined, +# certain built-in atomics fall back to depending on undefined symbols if +# their return values are used. +# +AC_CACHE_CHECK([for gcc atomic builtins],[dispatch_cv_atomic], +[AC_LINK_IFELSE([AC_LANG_PROGRAM([],[[ +int i, x =0; +i = __sync_add_and_fetch(&x,1); +return x;]])],[dispatch_cv_atomic=yes], + [saveCFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -march=i486" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[[ + int i, x =0; + i = __sync_add_and_fetch(&x,1); + return x;]])],[CFLAGS="$saveCFLAGS" +dispatch_cv_atomic="-march=i486" +])])]) + +case $dispatch_cv_atomic in + yes) ;; + -march*) MARCH_FLAGS="$dispatch_cv_atomic" + AC_SUBST([MARCH_FLAGS]) ;; + *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;; +esac + +# # Find libraries we will need # AC_SEARCH_LIBS(clock_gettime, rt) Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2009-09-25 08:44:52 UTC (rev 39) +++ trunk/src/Makefile.am 2009-09-25 09:53:30 UTC (rev 40) @@ -19,13 +19,7 @@ INCLUDES=-I$(top_builddir) -I$(top_srcdir) \ @APPLE_LIBC_SOURCE_PATH@ @APPLE_XNU_SOURCE_PATH@ -# -# This will need some refinement: gcc requires a minimum of -march=i486 on -# x86 in order to implement built-in atomic operations. But when should we -# define this optional argument? We need appropriate configure parts to make -# this conditional. -# -libdispatch_la_CFLAGS+=-march=i686 +libdispatch_la_CFLAGS+=$(MARCH_FLAGS) if USE_LEGACY_API libdispatch_la_SOURCES+= \