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: gcc-patches at gcc dot gnu dot org, jakub at redhat dot com
- Date: Wed, 13 Aug 2014 12:13:50 +0400
- Subject: Re: Fix libgomp crash without TLS (PR42616)
- Authentication-results: sourceware.org; auth=none
- References: <CAAp9h93CTb_oZ-y4-GgJUN7wTkjUajWMzGD+eyY43wJHQFw5eg at mail dot gmail dot com>
*Ping*
Thanks,
Varvara
2014-08-06 14:05 GMT+04:00 Varvara Rainchik <varvara.s.rainchik@gmail.com>:
> Hi,
>
> The issue was firstly observed on NDK gcc since TLS is not supported
> in Android bionic. I also see the same failure on gcc configured for
> linux with âdisable-tls, libgomp make check log:
>
> FAIL: libgomp.c/affinity-1.c execution test
> FAIL: libgomp.c/icv-2.c execution test
> FAIL: libgomp.c/lock-3.c execution test
> FAIL: libgomp.c/target-6.c execution test
>
> These tests except affinity-1.c fail because gomp_thread () function
> returns null pointer. Iâve found 2 bugs, first one addresses this
> problem on Windows:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42616;
> second one addresses original problem (for both cases, with and without TLS):
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36242.
> Tests from both bugs fail with âdisable-tls. So, it seems that non TLS
> case was fixed just partially. The following patch solves the problem.
> With this patch 3 tests from make check pass, affinity-1.c fails, but
> I think itâs other non TLS problem.
> Changes are bootstrapped and regtested on x86_64-linux.
>
>
> 2014-08-06 Varvara Rainchik <varvara.rainchik@intel.com>
>
> * libgomp.h (gomp_thread): For non TLS case create thread data.
> * team.c (create_non_tls_thread_data): New function.
>
>
> ---
> diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
> index a1482cc..cf3ec8f 100644
> --- a/libgomp/libgomp.h
> +++ b/libgomp/libgomp.h
> @@ -479,9 +479,15 @@ static inline struct gomp_thread *gomp_thread (void)
> }
> #else
> extern pthread_key_t gomp_tls_key;
> +extern struct gomp_thread *create_non_tls_thread_data (void);
> static inline struct gomp_thread *gomp_thread (void)
> {
> - return pthread_getspecific (gomp_tls_key);
> + struct gomp_thread *thr = pthread_getspecific (gomp_tls_key);
> + if (thr == NULL)
> + {
> + thr = create_non_tls_thread_data ();
> + }
> + return thr;
> }
> #endif
>
> diff --git a/libgomp/team.c b/libgomp/team.c
> index e6a6d8f..bf8bd4b 100644
> --- a/libgomp/team.c
> +++ b/libgomp/team.c
> @@ -927,6 +927,17 @@ initialize_team (void)
> gomp_fatal ("could not create thread pool destructor.");
> }
>
> +#ifndef HAVE_TLS
> +struct gomp_thread *create_non_tls_thread_data (void)
> +{
> + struct gomp_thread *thr = gomp_malloc (sizeof (struct gomp_thread));
> + pthread_setspecific (gomp_tls_key, thr);
> + gomp_sem_init (&thr->release, 0);
> +
> + return thr;
> +}
> +#endif
> +
> static void __attribute__((destructor))
> team_destructor (void)
> {
> ---
>
>
> Is it ok?
>
>
> Best regards,
>
> Varvara