-nodefaultlibs and pthreads

Michael Hunold hunold at linuxtv.org
Fri Jun 30 08:58:57 UTC 2006


Hi,

please have a look at the attached program.

It uses the pthread library, creates a mutex, locks the mutex and the
calls pthread_mutex_timedlock() which is expected to time out because
the mutex is already locked, then calls pthread_mutex_timedlock() again,
but this code should never be called.

I'm using uClibc 0.9.29 on a MIPS platform.

First I'm compiling the program the usual way as a shared executable:

/opt/uclibc/bin/mips-linux-uclibc-gcc -Wall timedlock.c -o timedlock
-lpthread

On my target I get the expected result:

/target $ ./ldd timedlock
ldd: can't open cache '/etc/ld.so.cache'
        libpthread.so.0 => /lib/libpthread.so.0 (0x2aaee000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2ab43000)
        libc.so.0 => /lib/libc.so.0 (0x2ab91000)
        ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x2aaa8000)
/target $ ./timedlock
main(): trying to lock mutex
main(): pthread_mutex_lock() ok
main(): pthread_mutex_timedlock() timeout

When I use "-nodefaultlibs -lc -lpthread", however, things are different.

/opt/uclibc/bin/mips-linux-uclibc-gcc -Wall timedlock.c -o timedlock
-nodefaultlibs -lc -lpthread

On the target:

/target $ ./ldd timedlock
ldd: can't open cache '/etc/ld.so.cache'
        libc.so.0 => /lib/libc.so.0 (0x2aaee000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x2ab93000)
        ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x2aaa8000)
/target $ ./timedlock
main(): trying to lock mutex
main(): pthread_mutex_lock() ok
main(): pthread_mutex_timedlock() ok
[system hangs]

My observations:

1. libgcc_s.so.1 is not referenced any more (thus saving about 200kB on
my platform)
2. first call to pthread_mutex_timedlock() succeeds, although the mutex
is already locked. argh!
3. seconds call to pthread_mutex_timedlock() hangs forever

I'm wondering what libgcc_s is for and why it is not referenced when
-nodefaultlibs is used. I'm puzzled that the executable works but the
functions don't behave as expected.

Can anybody explain this?

Best regards
Michael.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timedlock.c
Type: text/x-csrc
Size: 2269 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20060630/8d8faa13/attachment.c 


More information about the uClibc mailing list