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.
Don't do something so silly then. The dynamic linker has to hold locks guarding some of its internal state during dlopen until the dlopening finishes, so if you spawn another thread and try to call stuff that needs that lock, it will obviously block until dlopen finishes and the lock is released. But the initial thread waits on this thread, so it is an obvious deadlock.
Thanks for sharing your useful opinion. By the time glibc calls shared library constructors it must have already set up thread local storage. It looks like one big mutex is used for both dlopen() and tls setup. The mutex protecting tls must be released before calling shared library constructors.
This message is a reminder that Fedora 13 is nearing its end of life. Approximately 30 (thirty) days from now Fedora will stop maintaining and issuing updates for Fedora 13. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as WONTFIX if it remains open with a Fedora 'version' of '13'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, simply change the 'version' to a later Fedora version prior to Fedora 13's end of life. Bug Reporter: Thank you for reporting this issue and we are sorry that we may not be able to fix it before Fedora 13 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora please change the 'version' of this bug to the applicable version. If you are unable to change the version, please add a comment here and someone will do it for you. Although we aim to fix as many bugs as possible during every release's lifetime, sometimes those efforts are overtaken by events. Often a more recent Fedora release includes newer upstream software that fixes bugs or makes them obsolete. The process we are following is described here: http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Still broken with Fedora 14 and glibc-2.13-1.x86_64
This package has changed ownership in the Fedora Package Database. Reassigning to the new owner of this component.
I know it is a tough one. Are there any plans to fix it?
No plans to fix this.
Why not? Any comment?
Nothing beyond what Jakub has already stated in c#1.