This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix libgomp crash without TLS (PR42616)
- From: Varvara Rainchik <varvara dot s dot rainchik at gmail dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Richard Henderson <rth at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 9 Dec 2014 17:53:06 +0300
- Subject: Re: Fix libgomp crash without TLS (PR42616)
- Authentication-results: sourceware.org; auth=none
- References: <CAAp9h92JrSYjicz1A2ysfNniXAVk2LkE9WsLNiGXQehgS2yKdQ at mail dot gmail dot com> <20141007071125 dot GE1986 at tucnak dot redhat dot com> <CAAp9h91_2rLg8_GsNcaiA5D9MuTcUiskxkufdydENok1OAxLZQ at mail dot gmail dot com> <CAAp9h91yhuDnD607RO4+=E8DFVfrMKpN5kAa9nCzsq8_XqeTuw at mail dot gmail dot com> <CAAp9h921vFhhu+-6-SsRnN9kqP1SGfO+enciwXw4FoP26UfmcA at mail dot gmail dot com> <CAAp9h900CX-Fxu2inY35xf7rf29ZoFN88kwGUwy2bP_smW6s-g at mail dot gmail dot com> <20141208140352 dot GJ1667 at tucnak dot redhat dot com> <CAAp9h933G6OvF4MkKyjOfjck+27o++Q1G0s7YX9exEpatFepgw at mail dot gmail dot com> <20141208162816 dot GK1667 at tucnak dot redhat dot com> <CAAp9h93KvsMm2-n=CtX9HhYT3MjQRsEmPRKCA4=_QnLDLjFWqw at mail dot gmail dot com> <20141209121209 dot GP1667 at tucnak dot redhat dot com>
Ok, the following patch works for Android:
2014-12-09 Varvara Rainchik <varvara.rainchik@intel.com>
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Add GCC_CHECK_EMUTLS.
* libgomp.h: Add check for USE_EMUTLS: this case
is equal to HAVE_TLS.
* team.c: Likewise.
--
diff --git a/libgomp/configure.ac b/libgomp/configure.ac
index cea6366..16ec158 100644
--- a/libgomp/configure.ac
+++ b/libgomp/configure.ac
@@ -245,6 +245,9 @@ fi
# See if we support thread-local storage.
GCC_CHECK_TLS
+# See if we have emulated thread-local storage.
+GCC_CHECK_EMUTLS
+
# See what sort of export controls are available.
LIBGOMP_CHECK_ATTRIBUTE_VISIBILITY
LIBGOMP_CHECK_ATTRIBUTE_DLLEXPORT
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index a1482cc..b694356 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -471,7 +471,7 @@ enum gomp_cancel_kind
/* ... and here is that TLS data. */
-#ifdef HAVE_TLS
+#if defined HAVE_TLS || defined USE_EMUTLS
extern __thread struct gomp_thread gomp_tls_data;
static inline struct gomp_thread *gomp_thread (void)
{
diff --git a/libgomp/team.c b/libgomp/team.c
index e6a6d8f..594127c 100644
--- a/libgomp/team.c
+++ b/libgomp/team.c
@@ -37,7 +37,7 @@ pthread_key_t gomp_thread_destructor;
/* This is the libgomp per-thread data structure. */
-#ifdef HAVE_TLS
+#if defined HAVE_TLS || defined USE_EMUTLS
__thread struct gomp_thread gomp_tls_data;
#else
pthread_key_t gomp_tls_key;
@@ -70,7 +70,7 @@ gomp_thread_start (void *xdata)
void (*local_fn) (void *);
void *local_data;
-#ifdef HAVE_TLS
+#if defined HAVE_TLS || defined USE_EMUTLS
thr = &gomp_tls_data;
#else
struct gomp_thread local_thr;
@@ -916,7 +916,7 @@ gomp_team_end (void)
static void __attribute__((constructor))
initialize_team (void)
{
-#ifndef HAVE_TLS
+#if !defined HAVE_TLS && !defined USE_EMUTLS
static struct gomp_thread initial_thread_tls_data;
pthread_key_create (&gomp_tls_key, NULL);
Changes are bootstrapped and regtested on linux, all make check tests
now also pass with --disable-tls.
Is it ok for upstream?
2014-12-09 15:12 GMT+03:00 Jakub Jelinek <jakub@redhat.com>:
> On Tue, Dec 09, 2014 at 02:49:44PM +0300, Varvara Rainchik wrote:
>> Can we instead of adding new macroses in config/tls.m4 use something
>> like that in libgomp:
>>
>> #if defined (HAVE_TLS) && defined (USE_EMUTLS)
>>
>> (with GCC_CHECK_EMUTLS in libgomp/configure.ac)?
>
> That would be fine too.
>
> Jakub