Bug#786397: glibc: deadlock in dlopen with TLS and threads
Source: glibc
Version: 2.19-18
Severity: important
When using dlopen on a library with TLS and using threads in its constructor,
there can be a deadlock.
The bug is discuted here:
https://bugzilla.redhat.com/show_bug.cgi?id=1223055
Code to reproduce (taken from the above bug report):
main.c:
#include <stdio.h>
#include <dlfcn.h>
#include <assert.h>
int
main (void)
{
void *h = dlopen ("./mod1.so", RTLD_NOW | RTLD_GLOBAL);
assert (h != NULL);
return 0;
}
mod1.cc:
#include <pthread.h>
class A
{
private:
int i;
public:
A () {i = 0;}
~A () {i = 42;}
void hello (void) {}
};
thread_local A a;
static void *
thr (void *u)
{
a.hello ();
return NULL;
}
void
__attribute__((constructor))
init (void)
{
pthread_t t;
pthread_create (&t, NULL, thr, NULL);
pthread_join (t, NULL);
}
Build mod1.cc with:
g++ -std=c++11 -shared -fPIC -g -o mod1.so mod1.cc -pthread
Note that, on Debian, I can observe the bug in the stable glibc version
(2.19-18) and also in the experimental one (2.21-0experimental0)
Regards,
Vincent
-- System Information:
Debian Release: 8.0
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'oldstable-updates'), (500, 'oldoldstable'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), (500, 'oldstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, armel, mipsel
Kernel: Linux 3.19.0-trunk-amd64 (SMP w/8 CPU cores)
Locale: LANG=fr_FR.utf8, LC_CTYPE=fr_FR.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Reply to: