"-lc -lpthread" link order works on x86_64 glibc-2.9, but cause hang on uClibc-0.9.32-rc1 on mipsel with NPTL

Jian Peng jipeng at broadcom.com
Tue Jan 11 08:03:30 UTC 2011


"-lc -lpthread" link order works on Linux with glibc-2.9 on x86_64, but cause hang on uClibc-0.9.32-rc1 on mipsel with NPTL
The testing program is very simple as follow

#include <stdio.h>
#include <pthread.h>

int main(int argc, char *argv[])
{
        pthread_cond_t cond;

        printf(" ===  Start  Pthread Test !!!       === \n");

        pthread_cond_init(&cond, NULL);

        printf(" ===  End  Pthread Test !!!       === \n");

        return 0;
}

In following build,

$ mipsel-linux-gcc main.c -o /tftpboot/maintest.1 -lpthread
$ mipsel-linux-gcc main.c -o /tftpboot/maintest.2 -pthread
$ mipsel-linux-gcc main.c -o /tftpboot/maintest.3 -pthread -lc
$ mipsel-linux-gcc main.c -o /tftpboot/maintest.4 -lc -pthread
$ mipsel-linux-gcc main.c -o /tftpboot/maintest.5 -lc -lpthread

Only maintest.1 and maintest.2 works as expected, while the rest hang as

# ./maintest.3
 ===  Start  Pthread Test !!!       ===

^C
#

The problem was reported before and treated as wrong linking order (should be -lpthread -lc), but for lots of complicated projects, it is very hard to control link order due to stacking of LD_FLAGS from multiple makefiles.
IMHO, this can be resolved by defining pthread_* as libc_hidden_def to avoid to be overridden by the one from libc.so.

Any suggestion?

Thanks,
Jian


More information about the uClibc mailing list