User account creation filtered due to spam.

Bug 52738 - libgomp configured with --enable-tls=no crash inside pthread function
Summary: libgomp configured with --enable-tls=no crash inside pthread function
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgomp (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2012-03-27 14:11 UTC by Mateusz Kielar
Modified: 2012-04-19 13:23 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mateusz Kielar 2012-03-27 14:11:13 UTC
I configured libgomp with --enable-tls=no and build it as static library. But I get segmentation fault when I use such OpenMP inside Pthread funcion. gomp_thread inline function from libgomp.h uses pthread_getspecific and it returns null. Then this null value is used in context where null is not allowed. Also in team.c when HAVE_TLS is not defined there is such code:
struct gomp_thread local_thr;
thr = &local_thr;
pthread_setspecific (gomp_tls_key, thr);
Is it safe to remember address of local variable? In team.c without HAVE_TLS such pthread_setspecific is used multiple times.
When I use the same static library with --enable-tls=yes there is no such problem. I think there is general problem with OpenMP without TLS and Pthreads.
Comment 1 Mateusz Kielar 2012-03-30 06:30:00 UTC
(In reply to comment #0)
> I configured libgomp with --enable-tls=no and build it as static library. But I
> get segmentation fault when I use such OpenMP inside Pthread funcion.
> gomp_thread inline function from libgomp.h uses pthread_getspecific and it
> returns null. Then this null value is used in context where null is not
> allowed. Also in team.c when HAVE_TLS is not defined there is such code:
> struct gomp_thread local_thr;
> thr = &local_thr;
> pthread_setspecific (gomp_tls_key, thr);
> Is it safe to remember address of local variable? In team.c without HAVE_TLS
> such pthread_setspecific is used multiple times.
> When I use the same static library with --enable-tls=yes there is no such
> problem. I think there is general problem with OpenMP without TLS and Pthreads.

Ok, I see that in this case it's safe to call pthread_setspecific with address to local variable. But pthread_setspecific is called just for main thread (in initialize_team when library is loaded). It should also be called when pthread is created, so we can use OpenMP inside pthread function. Without it gomp_thread returns null. Also gomp_tls_key should be deleted in team_destructor function. Without it libgomp sometimes crashes in dlclose.
Comment 2 Mateusz Kielar 2012-04-19 13:23:17 UTC
The only way I see to resolve this issue is to check if pthread_getspecific returns null in gomp_thread and if yes then allocate new thread struct and use pthread_setspecific to store it. Could anyone share their opinion?