[PATCH] Add missing pthread_condattr_{init, destroy} stubs to libc

Kostik Belousov kostikbel at gmail.com
Fri Nov 27 22:07:12 UTC 2009


On Fri, Nov 27, 2009 at 04:53:20PM -0500, Joe Marcus Clarke wrote:
> On Fri, 2009-11-27 at 23:30 +0200, Kostik Belousov wrote:
> > On Fri, Nov 27, 2009 at 04:19:38PM -0500, Daniel Eischen wrote:
> > > 
> > > On Nov 27, 2009, at 2:14 PM, Joe Marcus Clarke <marcus at freebsd.org>  
> > > wrote:
> > > 
> > > >On Fri, 2009-11-27 at 15:12 +0200, Kostik Belousov wrote:
> > > >>On Fri, Nov 27, 2009 at 12:15:18AM -0500, Joe Marcus Clarke wrote:
> > > >>>I would like permission to commit this patch which adds missing
> > > >>>pthread_condattr_{init,destroy} symbols to libc.  I think I did the
> > > >>>symbol addition correctly (and it seems to work).  Without this, the
> > > >>>weak symbols added in the libpthread-stubs port conflict with  
> > > >>>those in
> > > >>>libthr, and applications with use these symbols can crash.
> > > >>>
> > > >>>I have temporarily hacked libpthread-stubs to fix this, but I really
> > > >>>feel these stubs should be added to libc.  I've also copied kib as  
> > > >>>he
> > > >>>has been kind enough to review my work in the past.  Thanks.
> > > >>>
> > > >>>http://www.marcuscom.com/downloads/stubs.diff
> > > >>
> > > >>It is FBSD_1.2 version that we use for symbols added after HEAD  
> > > >>become
> > > >>CURRENT-9.
> > > >
> > > >Done.
> > > 
> > > I don't think the symbols belong in FBSD_1.2.  They already exist in  
> > > libthr in a previous namespace.  If you use FBSD_1.2, then you  
> > > probably need to bump them in libthr and libc_r, and add compatible  
> > > symbols (no problem there since there are no differences) for the  
> > > previous versions.
> > Oh, yes.
> > 
> > > 
> > > Still not sure why libc needs all libpthread stubs.  Shouldn't be  
> > > necessary.
> > 
> > The privately discussed plan for 9.0 is to have libthr merged into
> > libc, and have libpthread and libthr as only filter object against libc
> > providing pthread_* and related symbols.
> > 
> > This would eliminate the need for pthread stubs and solve the issues
> > with (wrongly built) binaries that do not link to libthr but dlopen()
> > libraries that are linked with it.
> 
> Yeah, I think that would be a great overall solution.  However, in this
> case, the binaries in question ARE linked with -pthread.  The problem
> can be easily seen by taking this C program:
> 
> #include <sys/time.h>
> #include <pthread.h>
> #include <string.h>
> 
> int
> main(void) {
>         pthread_condattr_t attr;
> 
>         pthread_condattr_init (&attr);
>         pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
> 
>         pthread_condattr_destroy (&attr);
> 
>         return 0;
> }
> 
> And compiling it as:
> 
> cc -o xxx -L/usr/local/lib -lpthread-stubs -pthread xxx.c
> 
> You will need devel/libpthread-stubs (version 0.3) installed.  When you
> run it, it will segfault.  If you then rebuild libc and libthr with my
> stubs.diff patch, then rebuild libpthread-stubs, the problem will go
> away.

I see. What happen there is that both libpthread-stubs and libthr
provide _weak_ symbols pthread_condattr_destroy and pthread_condattr_init.
Actually, these two symbols are the only exported symbols from stubs
library. Due to specified library order, rtld for xxx resolves these
symbols from stubs, not from libthr. But pthread_condattr_setclock
is only exported weak from libthr, and it gets used.

This ends up supplying initialized attributes to pthread_condattr_setclock.

Your patch makes libc provide these two weak symbols, and then
stubs seems to become empty library.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-threads/attachments/20091127/4d82ec2c/attachment.pgp


More information about the freebsd-threads mailing list