This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libmudflap and emutls question


Jakub Jelinek wrote:
On Wed, Jan 07, 2009 at 11:38:55AM +0100, Paolo Bonzini wrote:
Which version of gcc did you use? gcc 4.1 (maybe and 4.2) will report
error. But gcc 4.3 compiles OK. I tested using x86_64 native gcc from
Debian unstable.  __emutls_get_address is defined in libgcc even the
target has real TLS.
Uff... not my day.  I used 4.2 (emutls was posted in 4.2 time but
committed in 4.3 only).  But I didn't think of the simplest solution:
use greps together with strings(1): "strings ./conftest | grep
__emutls_get_address".

I'd say much better would be just to grep assembly. See e.g. libffi/configure.ac's libffi_cv_hidden_visibility_attribute test.

This is what I was looking for. Thanks! The updated patch is attached. Is it OK now?


Jie

	libmudflap/
	* mf-impl.h (__mf_get_state, __mf_set_state): Don't use
	__thread when TLS support is emulated.
	* mf-hooks3.c (__mf_get_state, __mf_set_state): Likewise.
	* mf-runtime.c (__mf_state_1): Likewise.
	* configure.ac: Use GCC_CHECK_EMUTLS.
	* configure: Regenerate.
	* config.h.in: Regenerate.

	config/
	* tls.m4 (GCC_CHECK_EMUTLS): Define.


Index: libmudflap/mf-impl.h
===================================================================
--- libmudflap/mf-impl.h	(revision 143076)
+++ libmudflap/mf-impl.h	(working copy)
@@ -244,7 +244,7 @@ extern pthread_mutex_t __mf_biglock;
 #define UNLOCKTH() do {} while (0)
 #endif
 
-#if defined(LIBMUDFLAPTH) && !defined(HAVE_TLS)
+#if defined(LIBMUDFLAPTH) && (!defined(HAVE_TLS) || defined(USE_EMUTLS))
 extern enum __mf_state_enum __mf_get_state (void);
 extern void __mf_set_state (enum __mf_state_enum);
 #else
Index: libmudflap/mf-hooks3.c
===================================================================
--- libmudflap/mf-hooks3.c	(revision 143076)
+++ libmudflap/mf-hooks3.c	(working copy)
@@ -78,7 +78,7 @@ DECLARE(int, pthread_create, pthread_t *
 /* Multithreading support hooks.  */
 
 
-#ifndef HAVE_TLS
+#if !defined(HAVE_TLS) || defined(USE_EMUTLS)
 /* We don't have TLS.  Ordinarily we could use pthread keys, but since we're
    commandeering malloc/free that presents a few problems.  The first is that
    we'll recurse from __mf_get_state to pthread_setspecific to malloc back to
@@ -217,7 +217,7 @@ __mf_pthread_cleanup (void *arg)
   if (__mf_opts.heur_std_data)
     __mf_unregister (&errno, sizeof (errno), __MF_TYPE_GUESS);
 
-#ifndef HAVE_TLS
+#if !defined(HAVE_TLS) || defined(USE_EMUTLS)
   struct mf_thread_data *data = __mf_find_threadinfo (0);
   if (data)
     data->used_p = 0;
Index: libmudflap/configure.ac
===================================================================
--- libmudflap/configure.ac	(revision 143076)
+++ libmudflap/configure.ac	(working copy)
@@ -265,6 +265,7 @@ fi
 
 # See if we support thread-local storage.
 GCC_CHECK_TLS
+GCC_CHECK_EMUTLS
 
 AC_CONFIG_FILES([Makefile testsuite/Makefile testsuite/mfconfig.exp])
 AC_OUTPUT
Index: libmudflap/mf-runtime.c
===================================================================
--- libmudflap/mf-runtime.c	(revision 143076)
+++ libmudflap/mf-runtime.c	(working copy)
@@ -178,7 +178,7 @@ struct __mf_options __mf_opts;
 int __mf_starting_p = 1;
 
 #ifdef LIBMUDFLAPTH
-#ifdef HAVE_TLS
+#if defined(HAVE_TLS) && !defined(USE_EMUTLS)
 __thread enum __mf_state_enum __mf_state_1 = reentrant;
 #endif
 #else
Index: config/tls.m4
===================================================================
--- config/tls.m4	(revision 143076)
+++ config/tls.m4	(working copy)
@@ -86,3 +86,21 @@ AC_DEFUN([GCC_CHECK_CC_TLS], [
     AC_DEFINE(HAVE_CC_TLS, 1,
 	      [Define to 1 if the target assembler supports thread-local storage.])
   fi])
+
+dnl Check whether TLS is emulated.
+AC_DEFUN([GCC_CHECK_EMUTLS], [
+  AC_CACHE_CHECK([whether the thread-local storage support is from emutls],
+  		 gcc_cv_use_emutls, [
+    gcc_cv_use_emutls=no
+    echo '__thread int a; int b; int main() { return a = b; }' > conftest.c
+    if AC_TRY_COMMAND(${CC-cc} -Werror -S -o conftest.s conftest.c 1>&AS_MESSAGE_LOG_FD); then
+      if grep __emutls_get_address conftest.s > /dev/null; then
+	gcc_cv_use_emutls=yes
+      fi
+    fi
+    rm -f conftest.*
+    ])
+  if test "$gcc_cv_use_emutls" = "yes" ; then
+    AC_DEFINE(USE_EMUTLS, 1,
+      	      [Define to 1 if the target use emutls for thread-local storage.])
+  fi])

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]