RFC: [Long] Change PTHREAD_LIBS to -pthread for -CURRENT

Joe Marcus Clarke marcus at FreeBSD.org
Tue Jun 8 05:39:10 GMT 2004


I'm not sure how many of you have seen the recent thread (no pun
intended) on either ports@, current@, gnome@, or threads@ about the
problems with linking shared objects with -lpthread on -CURRENT.

Basically, when shared objects are explicitly linked with -lpthread,
they retain a link to the libpthread.  This means that any executable
which links to these libraries must also link to libpthread.  If they do
not, they will most certainly crash or behave erratically (this also
includes any dynamically loadable objects).  Some examples of this
include the gnome-vfs gtk+ file system backend, apache2/php4, nss_ldap,
wine, etc.

Note: if the shared object actually contains pthread symbols, then any
executable that links to it will still have to be linked with -pthread,
but in the examples above, this is not the case.

To get around this, we can use -pthread to link shared objects as well
as executables.  This works exactly the same way as in 4.X.  By using
-pthread, when shared objects are linked, libpthread will only be used
to resolve symbols at link-time, but the resulting shared object will
not retain a link to libpthread.  (One way to test this is to write a
simple helloworld.c, and compile it with ``cc -shared -o helloworld.so
-pthread helloworld.c'' and ``cc -shared -o helloworld.so -lpthread
helloworld.c'', then look at the resulting helloworld.so files with
ldd).

So, I propose changing PTHREAD_LIBS to -pthread for -CURRENT.  This will
match what we have in 4.X, and will last for the life of 5.X going
forward.  The threading people tell me this is doable now.  Thoughts?

Joe

-- 
Joe Marcus Clarke
FreeBSD GNOME Team	::	gnome at FreeBSD.org
FreeNode / #freebsd-gnome
http://www.FreeBSD.org/gnome
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20040608/d09ecccb/attachment.bin


More information about the freebsd-ports mailing list