public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix libgomp crash without TLS (PR42616)
@ 2014-08-06 10:05 Varvara Rainchik
  2014-08-13  8:14 ` Varvara Rainchik
  2014-08-29 17:41 ` Richard Henderson
  0 siblings, 2 replies; 25+ messages in thread
From: Varvara Rainchik @ 2014-08-06 10:05 UTC (permalink / raw)
  To: gcc-patches, jakub

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

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2014-12-09 16:37 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-06 10:05 Fix libgomp crash without TLS (PR42616) Varvara Rainchik
2014-08-13  8:14 ` Varvara Rainchik
2014-08-29 11:21   ` Varvara Rainchik
2014-08-29 17:41 ` Richard Henderson
2014-09-01 10:38   ` Varvara Rainchik
2014-09-01 10:51   ` Jakub Jelinek
2014-09-02 10:37     ` Varvara Rainchik
2014-09-19 11:42       ` Varvara Rainchik
2014-09-24 10:19         ` Varvara Rainchik
2014-09-30  7:03           ` Varvara Rainchik
2014-09-30  9:52             ` Jakub Jelinek
2014-09-30 14:40               ` Richard Henderson
2014-10-01 16:45                 ` Varvara Rainchik
2014-10-07  7:11                   ` Jakub Jelinek
2014-10-13 10:49                     ` Varvara Rainchik
2014-11-10 13:32                       ` Varvara Rainchik
2014-12-01 15:25                         ` Varvara Rainchik
2014-12-08 13:30                           ` Varvara Rainchik
2014-12-08 14:03                             ` Jakub Jelinek
2014-12-08 16:01                               ` Varvara Rainchik
2014-12-08 16:28                                 ` Jakub Jelinek
2014-12-09 11:49                                   ` Varvara Rainchik
2014-12-09 12:12                                     ` Jakub Jelinek
2014-12-09 14:53                                       ` Varvara Rainchik
2014-12-09 16:37                                         ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).