Hello.  When I try to create a lib:

gcc   -shared -Wl,-soname,libggi.so.1   -Wl,-exported_symbol,GGIdlinit
-Wl,-exported_symbol,GGIdlcleanup -o libggi.so.1.4.99 init.o events.o
mode.o gc.o stubs.o conf.o dl.o visual.o debug.o db.o gii.o -lpthread -lc 

and compare the difference between explicit and implicit linking of
pthreads at runtime,  explicit linking results in pthreads being loaded first, 
the libc.  On the otherhand implicit by the libggi dependencies loads libc 
first, the pthreads. This give the broken behaviour.  The libc (glibc)
behavior is diff than that of pthreads. This shows up in the apps where we
have to use -lpthread to get correct behavior (we do not want to force apps to
use pthreads just to compile).

Here is some nm output:

bash$ nm /lib/libc.so.6 | grep mutex
         U __pthread_mutex_destroy
         U __pthread_mutex_init
         U __pthread_mutex_lock
         U __pthread_mutex_trylock
         U __pthread_mutex_unlock
         U __pthread_mutexattr_destroy
         U __pthread_mutexattr_init
         U __pthread_mutexattr_setkind_np
00088490 W pthread_mutex_destroy
00088490 W pthread_mutex_init
00088490 W pthread_mutex_lock
00088490 W pthread_mutex_unlock
00088490 W pthread_mutexattr_getkind_np
00088490 W pthread_mutexattr_setkind_np

While libpthread has:

00004740 W __pthread_mutex_destroy
000046f0 W __pthread_mutex_init
00004930 W __pthread_mutex_lock
000047a0 W __pthread_mutex_trylock
00004c00 W __pthread_mutex_unlock
00004d70 W __pthread_mutexattr_destroy
00004db0 T __pthread_mutexattr_getkind_np
00004d50 W __pthread_mutexattr_init
00004d80 W __pthread_mutexattr_setkind_np
0000c4a0 d pthread_keys_mutex
00004740 W pthread_mutex_destroy
000046f0 W pthread_mutex_init
00004930 W pthread_mutex_lock
000047a0 W pthread_mutex_trylock
00004c00 W pthread_mutex_unlock
00004d70 W pthread_mutexattr_destroy
00004db0 W pthread_mutexattr_getkind_np
00004d50 W pthread_mutexattr_init
00004d80 W pthread_mutexattr_setkind_np

This causes LibGGI to use the seemingly broken libc mutexes, or we see some
strange interference between both of them.

The problem can be circumvented by linking in pthreads statically:

gcc -shared -Wl,-soname,libggi.so.1 -o libggi.so.1.4.99 init.o events.o
mode.o gc.o stubs.o conf.o dl.o visual.o debug.o db.o gii.o
/usr/lib/libpthread.a  -ldl -lc

This fixes the problem, otherwise apps must be linked with pthreads to work
correctly.  I was trying to read the ld manpages and see if there was a way to
force the usage of the pthread lib symbols and if I understood things
correctly one of --auxillary or --filter may work.  Does anyone have any idea
what the problem is or how to use the --auxillary and --filter options
correctly.  Thanks.

taylorcc

Reply via email to