[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 06/20] tools: Correct PTHREAD options in config/StdGNU.mk



Sorry, I've mean to send this to the list, but my phone doesn't like
that, so I'm sending the mail again (you will receive this one two
times Ian Campbell).

On Mar 20, 2012 9:44 AM, "Ian Campbell" <Ian.Campbell@xxxxxxxxxx> wrote:
>
> On Fri, 2012-03-16 at 16:26 +0000, Ian Jackson wrote:
> > It is not correct to say -lpthread. ÂThe correct option is -pthread,
> > which may have sundry other effects on code generation etc. ÂIt needs
> > to be passed both to compilation and linking.
>
> I guess this is a gcc-ism rather than a Linux-ism and so applies to the
> BSDs too (at least so long as they use gcc and not clang)?

From what I've read (not tested) BSD is fine with -pthread, but
Solaris seems to only accept -lpthread (again from the information
I've found online).

>
> > Fix the configure test to test -pthread, and plumb the resulting flag
> > through to PTHREAD_{CFLAGS,LDFLAGS} in Tools.mk; also substitute
> > PTHREAD_LIBS (although this will currently always be empty).
> > Remove PTHREAD_LIBS setting from StdGNU.mk.
> >
> > Fix the one user (libxc) to use PTHREAD_{CFLAGS,LDFLAGS} too.
> >
> > There are still some other users in tree which pass -pthread or
> > -lpthread by adding it as a literal to their own compiler options.
> > These will be fixed in a later patch.
> >
> > Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> > Cc: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
> > ---
> > Âconfig/StdGNU.mk   |  Â1 -
> > Âconfig/Tools.mk.in  |  Â4 ++
> > Âtools/configure   Â|  95 
> > +++++++++++++++++++++++++++++++++++---------------
> > Âtools/configure.ac  |  Â5 ++-
> > Âtools/libxc/Makefile | Â Â4 ++-
> > Âtools/m4/pthread.m4 Â| Â 41 +++++++++++++++++++++
> > Âtools/m4/savevar.m4 Â| Â Â6 +++
> > Â7 files changed, 124 insertions(+), 32 deletions(-)
> > Âcreate mode 100644 tools/m4/pthread.m4
> > Âcreate mode 100644 tools/m4/savevar.m4
> >
> > diff --git a/config/StdGNU.mk b/config/StdGNU.mk
> > index e2c9335..e2f2e1e 100644
> > --- a/config/StdGNU.mk
> > +++ b/config/StdGNU.mk
> > @@ -67,7 +67,6 @@ XEN_CONFIG_DIR = $(CONFIG_DIR)/xen
> > ÂXEN_SCRIPT_DIR = $(XEN_CONFIG_DIR)/scripts
> >
> > ÂSOCKET_LIBS =
> > -PTHREAD_LIBS = -lpthread
> > ÂUTIL_LIBS = -lutil
> > ÂDLOPEN_LIBS = -ldl
> >
> > diff --git a/config/Tools.mk.in b/config/Tools.mk.in
> > index 057b055..8247e4a 100644
> > --- a/config/Tools.mk.in
> > +++ b/config/Tools.mk.in
> > @@ -23,6 +23,10 @@ PREPEND_LIB Â Â Â Â := @PREPEND_LIB@
> > ÂAPPEND_INCLUDES Â Â := @APPEND_INCLUDES@
> > ÂAPPEND_LIB Â Â Â Â Â:= @APPEND_LIB@
> >
> > +PTHREAD_CFLAGS Â Â Â:= @PTHREAD_CFLAGS@
> > +PTHREAD_LDFLAGS Â Â := @PTHREAD_LDFLAGS@
> > +PTHREAD_LIBS Â Â Â Â:= @PTHREAD_LIBS@
> > +
> > Â# Download GIT repositories via HTTP or GIT's own protocol?
> > Â# GIT's protocol is faster and more robust, when it works at all (firewalls
> > Â# may block it). We make it the default, but if your GIT repository 
> > downloads
> > diff --git a/tools/configure b/tools/configure
> > index c686130..7ee4e3e 100755
> > --- a/tools/configure
> > +++ b/tools/configure
> > @@ -602,6 +602,9 @@ POW_LIB
> > ÂLIBOBJS
> > ÂALLOCA
> > Âlibiconv
> > +PTHREAD_LIBS
> > +PTHREAD_LDFLAGS
> > +PTHREAD_CFLAGS
> > Âlibgcrypt
> > Âlibext2fs
> > Âsystem_aio
> > @@ -3844,6 +3847,9 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 
> > 's/ /-/g'`;; esac
> >
> >
> >
> > +
> > +
> > +
> > Â# pkg.m4 - Macros to locate and utilise pkg-config. Â Â Â Â Â Â-*- 
> > Autoconf -*-
> > Â# serial 1 (pkg-config-0.24)
> > Â#
> > @@ -3908,6 +3914,16 @@ case $host_os in *\ *) host_os=`echo "$host_os" | 
> > sed 's/ /-/g'`;; esac
> >
> >
> >
> > +
> > +
> > +
> > +
> > +
> > +
> > +
> > +
> > +
> > +
> > Â# Enable/disable options
> > Â# Check whether --enable-githttp was given.
> > Âif test "${enable_githttp+set}" = set; then :
> > @@ -7010,47 +7026,70 @@ else
> > Âfi
> >
> >
> > -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in 
> > -lpthread" >&5
> > -$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
> > -if test "${ac_cv_lib_pthread_pthread_create+set}" = set; then :
> > +
> > + Â Â{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread flag" >&5
> > +$as_echo_n "checking for pthread flag... " >&6; }
> > +if test "${ax_cv_pthread_flags+set}" = set; then :
> > Â Â$as_echo_n "(cached) " >&6
> > Âelse
> > - Âac_check_lib_save_LIBS=$LIBS
> > -LIBS="-lpthread Â$LIBS"
> > -cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> > +
> > + Â Â Â Âax_cv_pthread_flags=-pthread
> > +
> > + Â ÂPTHREAD_CFLAGS="$ax_cv_pthread_flags"
> > + Â ÂPTHREAD_LDFLAGS="$ax_cv_pthread_flags"
> > + Â ÂPTHREAD_LIBS=""
> > +
> > +
> > + Â Âsaved_CFLAGS="$CFLAGS"
> > +
> > + Â Âsaved_LDFLAGS="$LDFLAGS"
> > +
> > + Â Âsaved_LIBS="$LIBS"
> > +
> > +
> > + Â ÂCFLAGS="$CFLAGS $PTHREAD_CFLAGS"
> > +
> > + Â ÂLDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS"
> > +
> > + Â ÂLIBS="$LIBS $PTHREAD_LIBS"
> > +
> > + Â Â Â Âcat confdefs.h - <<_ACEOF >conftest.$ac_ext
> > Â/* end confdefs.h. Â*/
> >
> > -/* Override any GCC internal prototype to avoid an error.
> > - Â Use char because int might match the return type of a GCC
> > - Â builtin and then its argument prototype would still apply. Â*/
> > -#ifdef __cplusplus
> > -extern "C"
> > -#endif
> > -char pthread_create ();
> > -int
> > -main ()
> > -{
> > -return pthread_create ();
> > - Â;
> > - Âreturn 0;
> > +#include <pthread.h>
> > +int main(void) {
> > + Âpthread_atfork(0,0,0);
> > + Âpthread_create(0,0,0,0);
> > Â}
> > +
> > Â_ACEOF
> > Âif ac_fn_c_try_link "$LINENO"; then :
> > - Âac_cv_lib_pthread_pthread_create=yes
> > +
> > Âelse
> > - Âac_cv_lib_pthread_pthread_create=no
> > + Âax_cv_pthread_flags=failed
> > Âfi
> > Ârm -f core conftest.err conftest.$ac_objext \
> > Â Â Âconftest$ac_exeext conftest.$ac_ext
> > -LIBS=$ac_check_lib_save_LIBS
> > -fi
> > -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
> > $ac_cv_lib_pthread_pthread_create" >&5
> > -$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
> > -if test "x$ac_cv_lib_pthread_pthread_create" = x""yes; then :
> >
> > -else
> > - Âas_fn_error $? "Could not find libpthread" "$LINENO" 5
> > + Â ÂCFLAGS="$saved_CFLAGS"
> > +
> > + Â ÂLDFLAGS="$saved_LDFLAGS"
> > +
> > + Â ÂLIBS="$saved_LIBS"
> > +
> > +
> > Âfi
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_pthread_flags" >&5
> > +$as_echo "$ax_cv_pthread_flags" >&6; }
> > + Â Âif test "x$ax_cv_pthread_flags" = xfailed; then
> > + Â Â Â Âas_fn_error $? "-pthread does not work" "$LINENO" 5
> > + Â Âfi
> > +
> > + Â ÂPTHREAD_CFLAGS="$ax_cv_pthread_flags"
> > + Â ÂPTHREAD_LDFLAGS="$ax_cv_pthread_flags"
> > + Â ÂPTHREAD_LIBS=""
> > +
> > +
> >
> > Â{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in 
> > -lrt" >&5
> > Â$as_echo_n "checking for clock_gettime in -lrt... " >&6; }
> > diff --git a/tools/configure.ac b/tools/configure.ac
> > index 3d53a95..3da0c82 100644
> > --- a/tools/configure.ac
> > +++ b/tools/configure.ac
> > @@ -23,6 +23,7 @@ AC_USE_SYSTEM_EXTENSIONS
> > ÂAC_CANONICAL_HOST
> >
> > Â# M4 Macro includes
> > +m4_include([m4/savevar.m4])
> > Âm4_include([m4/enable_feature.m4])
> > Âm4_include([m4/disable_feature.m4])
> > Âm4_include([m4/path_or_fail.m4])
> > @@ -34,6 +35,7 @@ m4_include([m4/set_cflags_ldflags.m4])
> > Âm4_include([m4/uuid.m4])
> > Âm4_include([m4/pkg.m4])
> > Âm4_include([m4/curses.m4])
> > +m4_include([m4/pthread.m4])
> >
> > Â# Enable/disable options
> > ÂAX_ARG_ENABLE_AND_EXPORT([githttp], [Download GIT repositories via HTTP])
> > @@ -123,8 +125,7 @@ AC_CHECK_LIB([ext2fs], [ext2fs_open2], [libext2fs="y"], 
> > [libext2fs="n"])
> > ÂAC_SUBST(libext2fs)
> > ÂAC_CHECK_LIB([gcrypt], [gcry_md_hash_buffer], [libgcrypt="y"], 
> > [libgcrypt="n"])
> > ÂAC_SUBST(libgcrypt)
> > -AC_CHECK_LIB([pthread], [pthread_create], [] ,
> > - Â Â[AC_MSG_ERROR([Could not find libpthread])])
> > +AX_CHECK_PTHREAD
> > ÂAC_CHECK_LIB([rt], [clock_gettime])
> > ÂAC_CHECK_LIB([yajl], [yajl_alloc], [],
> > Â Â Â[AC_MSG_ERROR([Could not find yajl])])
> > diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
> > index 55eb755..a1ba134 100644
> > --- a/tools/libxc/Makefile
> > +++ b/tools/libxc/Makefile
> > @@ -73,6 +73,8 @@ CFLAGS Â += -I. $(CFLAGS_xeninclude)
> > Â# Needed for posix_fadvise64() in xc_linux.c
> > ÂCFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
> >
> > +CFLAGS Â Â Â += $(PTHREAD_CFLAGS)
> > +
> > Â# Define this to make it possible to run valgrind on code linked with these
> > Â# libraries.
> > Â#CFLAGS Â += -DVALGRIND -O0 -ggdb3
> > @@ -157,7 +159,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
> > Â Â Â ln -sf $< $@
> >
> > Âlibxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
> > - Â Â $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) 
> > $(SHLIB_LDFLAGS) -o $@ $^ $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
> > + Â Â $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
> > -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(DLOPEN_LIBS) 
> > $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
> >
> > Â# libxenguest
> >
> > diff --git a/tools/m4/pthread.m4 b/tools/m4/pthread.m4
> > new file mode 100644
> > index 0000000..57ea85c
> > --- /dev/null
> > +++ b/tools/m4/pthread.m4
> > @@ -0,0 +1,41 @@
> > +# We define, separately, PTHREAD_CFLAGS, _LDFLAGS and _LIBS
> > +# even though currently we don't set them very separately.
> > +# This means that the makefiles will not need to change in
> > +# the future if we make the test more sophisticated.
> > +
> > +AC_DEFUN([AX_PTHREAD_CV2VARS],[
> > + Â ÂPTHREAD_CFLAGS="$ax_cv_pthread_flags"
> > + Â ÂPTHREAD_LDFLAGS="$ax_cv_pthread_flags"
> > + Â ÂPTHREAD_LIBS=""
> > +])
> > +
> > +# We invoke AX_PTHREAD_VARS with the name of another macro
> > +# which is then expanded once for each variable.
> > +AC_DEFUN([AX_PTHREAD_VARS],[$1(CFLAGS) $1(LDFLAGS) $1(LIBS)])
> > +
> > +AC_DEFUN([AX_PTHREAD_VAR_APPLY],[
> > + Â Â$1="$$1 $PTHREAD_$1"
> > +])
> > +AC_DEFUN([AX_PTHREAD_VAR_SUBST],[AC_SUBST(PTHREAD_$1)])
> > +
> > +AC_DEFUN([AX_CHECK_PTHREAD],[
> > + Â ÂAC_CACHE_CHECK([for pthread flag], [ax_cv_pthread_flags], [
> > + Â Â Â Âax_cv_pthread_flags=-pthread
> > + Â Â Â ÂAX_PTHREAD_CV2VARS
> > + Â Â Â ÂAX_PTHREAD_VARS([AX_SAVEVAR_SAVE])
> > + Â Â Â ÂAX_PTHREAD_VARS([AX_PTHREAD_VAR_APPLY])
> > + Â Â Â ÂAC_LINK_IFELSE([
> > +#include <pthread.h>
> > +int main(void) {
> > + Âpthread_atfork(0,0,0);
> > + Âpthread_create(0,0,0,0);
> > +}
> > +],[],[ax_cv_pthread_flags=failed])
> > + Â Â Â ÂAX_PTHREAD_VARS([AX_SAVEVAR_RESTORE])
> > + Â Â])
> > + Â Âif test "x$ax_cv_pthread_flags" = xfailed; then
> > + Â Â Â ÂAC_MSG_ERROR([-pthread does not work])
> > + Â Âfi
> > + Â ÂAX_PTHREAD_CV2VARS
> > + Â ÂAX_PTHREAD_VARS([AX_PTHREAD_VAR_SUBST])
> > +])
> > diff --git a/tools/m4/savevar.m4 b/tools/m4/savevar.m4
> > new file mode 100644
> > index 0000000..2156bee
> > --- /dev/null
> > +++ b/tools/m4/savevar.m4
> > @@ -0,0 +1,6 @@
> > +AC_DEFUN([AX_SAVEVAR_SAVE],[
> > + Â Âsaved_$1="$$1"
> > +])
> > +AC_DEFUN([AX_SAVEVAR_RESTORE],[
> > + Â Â$1="$saved_$1"
> > +])
>
>

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.