Merge from vendor branch LIBEVENT:
[dragonfly.git] / lib / libpthread / README
1 $DragonFly: src/lib/libpthread/README,v 1.2 2008/01/20 19:14:09 corecode Exp $
2
3 Proxy libpthread
4 ================
5
6 We want to be able to switch between threading libraries at execution
7 time.  This problem is solved by this proxy libpthread.  Its operation is
8 as follows.
9
10 The operation at link time is as follows.
11 libc.so anyways defines all pthread functions as weak symbols
12 except for pthread_create.  libpthread.so now also defines a dummy
13 pthread_create as weak symbol and ld is satisfied.  At execution time
14 later rtld will resolve all these references to the strong symbols in the
15 right thread library.
16
17 Allowing the user to switch the threading lib works like this:  At link
18 time ld reads the SONAME of libpthread.so, which is set to libpthread.so.0
19 (or a higher major, if ABI changes).  Usually libfoo.so is a symlink to
20 libfoo.so.3 which also has set its SONAME to libfoo.so.3, so that if
21 libfoo.so.4 is being installed, programs will still continue to use
22 libfoo.so.3 and not follow the symlink libfoo.so to the newer -- and
23 possibly incompatible -- libfoo.so.4.  What we do is approximately the
24 opposite:  libpthread.so is no symlink, but nevertheless has its SONAME
25 set to libpthread.so.0.  Now, however, libpthread.so.0 is a symlink to the
26 threading library of your choice.  The linker will use the default
27 threading lib which libpthread.so is linked to, but the runtime linker
28 will instead follow the symlink.
29
30 This (obviously) does not work for static linking.