[patch] libmudflap threads configury

James E Wilson wilson@specifix.com
Thu Sep 29 18:47:00 GMT 2005


I'm looking at porting libmudflap to other targets.  In particular,
embedded targets using newlib.

newlib contains a pthread.h file, but it is only usable for rtems and
cygwin.  For other newlib targets, it is just a stub that doesn't define
anything.  libmudflap always builds a thread aware library if pthread.h
exists.  The result is that trying to build libmudflap for an embedded
target results in syntax errors.

The problem here isn't the pthread.h file though.  The problem is that
libmudflap is building a thread library when it shouldn't.  Gcc already
knows which targets have thread support, and has an --enable-threads
option for finer control.  libmudflap should be using this info.  This
is already handled in libstdc++ by running gcc -v and grepping for
threads info.  I added the same trick to libmudflap, simplied a bit,
since libmudflap only supports posix threads or no threads at all.

Since libmudflap is only enabled by default for linux and freebsd, and
since both default to posix thread, there is no change to default
behaviour.  This patch has an effect only if you use --enable-libmudflap
and/or --enable-threads with non-default values, which is what I'm
trying to do.  For instance, if you specify --disable-threads, then
libmudflap won't compile the thread-aware library anymore with this
patch.

This was tested with an x86_64-linux build and libmudflap make check. 
There were no regressions.  I also verified that --disable-threads now
works as it should.

I'll wait a bit in case anyone wants to comment on the patch before I
check it in .
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com
-------------- next part --------------
2005-09-28  James E. Wilson  <wilson@specifix.com>

	* configure.ac (pthread.h): Use AC_CHECK_HEADERS instead of
	AC_CHECK_HEADER.
	(target_thread_file): New.  Set from sed'ed gcc output.
	(posix_threads): New.  Set from target_thread_file.  Use instead of
	ac_have_pthread_h.
	(pthread_create_version): Move initialization before code using it.
	* configure: Regenerate.

Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/configure.ac,v
retrieving revision 1.14
diff -p -p -r1.14 configure.ac
*** configure.ac	23 Sep 2005 16:33:46 -0000	1.14
--- configure.ac	29 Sep 2005 01:58:56 -0000
*************** then
*** 114,128 ****
    mkdir pth
  fi
  
! pthread_create_version='""'
! AC_CHECK_HEADER(pthread.h,[
! AC_DEFINE_UNQUOTED(HAVE_PTHREAD_H, 1, [define if you have <pthread.h>])
! ac_have_pthread_h=yes
! ],[
! ac_have_pthread_h=
! ])
! AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$ac_have_pthread_h" != "x"])
! if test "x$ac_have_pthread_h" != "x"
  then
          build_libmudflapth=1
  else
--- 114,141 ----
    mkdir pth
  fi
  
! AC_CHECK_HEADERS(pthread.h)
! 
! AC_MSG_CHECKING([for thread model used by GCC])
! target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
! AC_MSG_RESULT([$target_thread_file])
! 
! # We only support posix threads, or no threads at all.
! posix_threads=
! case ${target_thread_file} in
!   posix)
!     posix_threads=yes
!     ;;
!   single)
!     ;;
!   *)
!     echo "${target_thread_file} is an unsupported thread package" 1>&2
!     exit 1
!     ;;
! esac
! 
! AM_CONDITIONAL(LIBMUDFLAPTH, [test "x$posix_threads" != "x"])
! if test "x$posix_threads" != "x"
  then
          build_libmudflapth=1
  else
*************** esac
*** 162,168 ****
  AC_SUBST(toolexecdir)
  AC_SUBST(toolexeclibdir)
  
! if test "x$enable_shared" = "xyes" && test "x$ac_have_pthread_h" != "x"; then
    # NB: don't check for -lpthread here, because then it would be
    # added to LIBS.  For the thread-unaware libmudflap.la, we don't
    # want it there.
--- 175,182 ----
  AC_SUBST(toolexecdir)
  AC_SUBST(toolexeclibdir)
  
! pthread_create_version='""'
! if test "x$enable_shared" = "xyes" && test "x$posix_threads" != "x"; then
    # NB: don't check for -lpthread here, because then it would be
    # added to LIBS.  For the thread-unaware libmudflap.la, we don't
    # want it there.


More information about the Gcc-patches mailing list