Patchwork Patch committed: Re: libgo assumes -pthread

login
register
mail settings
Submitter Ian Taylor
Date Dec. 3, 2010, 9:28 p.m.
Message ID <mcrtyiuzguw.fsf_-_@google.com>
Download mbox | patch
Permalink /patch/74214/
State New
Headers show

Comments

Ian Taylor - Dec. 3, 2010, 9:28 p.m.
Dave Korn <dave.korn.cygwin@gmail.com> writes:

>   And indeed some fullly-hosted ports, such as cygwin and mingw.  The -pthread
> option can't be assumed to exist on any given target, even some of those that
> actually support pthreads functionality.  It needs to be added only where
> actually needed, subject to some kind of autoconf test or other.

I have committed the appended patch to libgo to avoid this problem.

Ian

Patch

diff -r 4285c955369f libgo/Makefile.am
--- a/libgo/Makefile.am	Fri Dec 03 12:40:50 2010 -0800
+++ b/libgo/Makefile.am	Fri Dec 03 13:18:34 2010 -0800
@@ -30,7 +30,7 @@ 
 WARN_CFLAGS = $(WARN_FLAGS) $(WERROR)
 
 # -I/-D flags to pass when compiling.
-AM_CPPFLAGS = -I $(srcdir)/runtime $(LIBFFIINCS) -pthread
+AM_CPPFLAGS = -I $(srcdir)/runtime $(LIBFFIINCS) $(PTHREAD_CFLAGS)
 
 ACLOCAL_AMFLAGS = -I ./config -I ../config
 
@@ -1263,7 +1263,7 @@ 
 
 libgo_la_SOURCES = $(runtime_files)
 
-libgo_la_LIBADD = $(libgo_go_objs) $(LIBFFI) -lpthread
+libgo_la_LIBADD = $(libgo_go_objs) $(LIBFFI) $(PTHREAD_LIBS)
 
 libgobegin_a_SOURCES = \
 	runtime/go-main.c
@@ -1279,7 +1279,7 @@ 
 
 GOLINK = $(LIBTOOL) --tag GO --mode-link $(GOC) \
 	$(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_GOCFLAGS) $(LTLDFLAGS) \
-	-lpthread -o $@
+	$(PTHREAD_LIBS) -o $@
 
 # Build a package.
 BUILDARCHIVE = \
diff -r 4285c955369f libgo/configure.ac
--- a/libgo/configure.ac	Fri Dec 03 12:40:50 2010 -0800
+++ b/libgo/configure.ac	Fri Dec 03 13:18:34 2010 -0800
@@ -187,6 +187,26 @@ 
 	    [Define if the linker support split stack adjustments])
 fi
 
+dnl Test whether the compiler supports the -pthread option.
+AC_CACHE_CHECK([whether -pthread is supported],
+[ac_cv_libgo_pthread_supported],
+[CFLAGS_hold=$CFLAGS
+CFLAGS="$CFLAGS -pthread"
+AC_COMPILE_IFELSE([[int i;]],
+[ac_cv_libgo_pthread_supported=yes],
+[ac_cv_libgo_pthread_supported=no])
+CFLAGS=$CFLAGS_hold])
+PTHREAD_CFLAGS=
+if test "$ac_cv_libgo_pthread_supported" = yes; then
+  PTHREAD_CFLAGS=-pthread
+fi
+AC_SUBST(PTHREAD_CFLAGS)
+
+dnl Test for the -lpthread library.
+PTHREAD_LIBS=
+AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS=-lpthread)
+AC_SUBST(PTHREAD_LIBS)
+
 AC_C_BIGENDIAN
 
 GCC_CHECK_UNWIND_GETIPINFO