public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12307] New: accessing thread local storage blocks forever when using dlopen
@ 2010-12-09 17:13 maxim.yegorushkin at gmail dot com
  2011-08-24 10:36 ` [Bug libc/12307] " andrewjcg at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: maxim.yegorushkin at gmail dot com @ 2010-12-09 17:13 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12307

           Summary: accessing thread local storage blocks forever when
                    using dlopen
           Product: glibc
           Version: 2.12
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: maxim.yegorushkin@gmail.com


Description of problem:
A new thread created by a shared library initialization routine blocks forever
accessing thread local storage when the shared library is loaded during
run-time using dlopen().

Version-Release number of selected component (if applicable):
$ rpm -q glibc
glibc-2.12.1-4.x86_64

How reproducible:
Always.

Steps to Reproduce:
$ cat shared.cc
#include <cassert>
#include <pthread.h>
#include <stdio.h>

namespace {

__thread void* some_value;

void* thread(void*)
{
    printf("thread enter\n");
    void* value = some_value; // hangs here forever
    printf("thread leave\n");
    return value;
}

struct X
{
    X()
    {
        pthread_t thread_id;
        int r = pthread_create(&thread_id, NULL, thread, NULL);
        assert(!r);
        void* value;
        r = pthread_join(thread_id, &value);
        assert(!r);
    }
} x;

}

$ g++ -Wall -shared -fpic -pthread -g -o shared.so shared.cc

$ cat loader.cc
#include <stdio.h>
#include <dlfcn.h>

char const shared_path[] = "./shared.so";

int main()
{
    printf("loading %s\n", shared_path);
    void* h = dlopen(shared_path, RTLD_NOW | RTLD_GLOBAL);
    printf("%s loaded at %p\n", shared_path, h);
    dlclose(h);
    printf("%s unloaded\n", shared_path);
}

$ g++ -Wall -pthread -ldl -g -o loader loader.cc


Actual results:
$ ./loader
loading ./shared.so
thread enter
(the above hangs forever)
  C-c C-c

Expected results:
$ ./loader
loading ./shared.so
thread enter
thread leave
./shared.so loaded at 0x7ff97355eb18
./shared.so unloaded

Additional info:
When the executable links the shared library explicitly at link time, i.e.:

$ g++ -Wall -pthread -ldl -g -o loader -l:./shared.so loader.cc 

it works as expected.

P.S. It was originally filed against Fedora.
https://bugzilla.redhat.com/show_bug.cgi?id=661676

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

end of thread, other threads:[~2014-06-30  6:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-09 17:13 [Bug libc/12307] New: accessing thread local storage blocks forever when using dlopen maxim.yegorushkin at gmail dot com
2011-08-24 10:36 ` [Bug libc/12307] " andrewjcg at gmail dot com
2012-02-21  2:16 ` [Bug ld.so|libdl/12307] " jsm28 at gcc dot gnu.org
2012-12-19 10:51 ` [Bug dynamic-link/12307] " schwab@linux-m68k.org
2013-10-13  8:58 ` neleai at seznam dot cz
2013-10-13 11:42 ` maxim.yegorushkin at gmail dot com
2013-10-14 23:09 ` bugdal at aerifal dot cx
2013-10-15  6:15   ` Ondřej Bílka
2013-10-15  6:15 ` neleai at seznam dot cz
2013-10-15  8:59 ` maxim.yegorushkin at gmail dot com
2014-06-30  6:22 ` fweimer at redhat dot com

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).