problem when pthread_* functions are invoked from dynamiclibrary

Joakim Tjernlund joakim.tjernlund at transmode.se
Mon Dec 5 09:07:40 UTC 2005


> 
> On Sat, Dec 03, 2005 at 09:01:40PM +0100, Joakim Tjernlund wrote:
> > > On Fri, Dec 02, 2005 at 05:46:07PM +0530, Kishore K wrote:
> > > > I am facing some problems if pthread_self() and some other 
> > > pthread_* 
> > > > functions are invoked from a dynamic library.
> > > 
> > > i just cleaned up weaks.c and removed all the weaks that 
> > > libc.so itself does not require (which includes pthread_self) 
> > > ... but, that doesnt change the fact that the mechanism in 
> > > ldso to handle weaks appears to be broken ...
> > 
> > I don't think weak handling is broken. Some time ago glibc 
> changed is weak
> > handling and I did the same to uClibc. I don't know why 
> this change was done.
> > In glibc you can set LD_DYNAMIC_WEAK=1 to use the old method.
> 
> ok, we chatted some more, and it turns out that glibc also updated
> their libpthread forward.c file to accommodate the new weak behavior
> 
> find attached an untested patch against current svn which updates our
> weaks.c in the same manner ... the good news is that this should fix
> the bugs people are seeing, the bad news is that it makes the weaks
> file a bit bigger :( ... although, if i declare the extern 
> weak pthread
> function as attribute_hidden, it shrinks it considerably, i'm just not
> sure if this is correct

Don't think thats correct. What does readelf -a say about the hidden
weak functions?

> 
> also, this will require us to change all the __pthread_X calls in libc
> to __libc_pthread_X ... basically, the way this patch works is:
> extern int weak __pthread_mutex_init();
> int hidden __libc_pthread_mutex_init() {
> 	if (__pthread_mutex_init == NULL)
> 		return 0;
> 	__pthread_mutex_init();
> }
> and then rinse/repeat for the other functions
> -mike

looks good, but a few minor changes should be made:
extern int weak pthread_mutex_init();
int hidden __pthread_mutex_init() {
 	if (pthread_mutex_init == NULL)
 		return 0;
 	pthread_mutex_init();
 }

Then the __ versions in linuxthreads should be made hidden. That way we
wont
export any __ functions and it will match glibc better.
Possibly one could add a #ifdef __UCLIBC_HAS_THREADS__ around this code.
Maybe turning __pthread_mutex_init() into a macro?

 Jocke

PS.
   I still think it is not allowed to dlopen pthreads. How would one
handle all
   pthread_mutex_init() calls that has already been performed?



More information about the uClibc mailing list