Strange dynamic linking issue
Alexandros Frantzis
alexandros at echovision.gr
Thu Apr 2 13:01:29 UTC 2009
Hello,
I have been trying to use uClibc 0.9.28 (I know its an old version but I
cannot upgrade) on a mipsel system and I have come across what seems to
be a strange dynamic linking issue.
The problem is than if I compile a program against a library that has
been linked with pthread but the program itself has not been linked with
pthread, some pthread functions are not resolved correctly.
A minimal example is:
<------- start libfunc.c -------->
#include <pthread.h>
#include <stdio.h>
int func(void)
{
pthread_attr_t attr;
pthread_attr_init(&attr);
printf("attr: %d\n", attr.__stackaddr_set);
}
<------- end libfunc.c -------->
<------- start functest.c -------->
int func(void);
int main(void)
{
func();
}
<------- end functest.c -------->
$ mipsel-linux-gcc -shared -o libfunc.so libfunc.c -lpthread
$ mipsel-linux-gcc -L. -ofunctest functest.c -lfunc
$ ./functest
1 << random value that happened to be in the uninitialized attr struct
>From a quick debugging/tracing session what happens is that when
pthread_attr_init() is called, the dynamic linker for some strange
reason ends up calling what gdb seems to think is the
pthread_setschedparam function (probably a stub).
-> 0x2aaf869c <pthread_setschedparam>: jr ra
0x2aaf86a0 <pthread_setschedparam+4>: move v0,zero
0x2aaf86a4 <pthread_equal>: jr ra
0x2aaf86a8 <pthread_equal+4>: li v0,1
0x2aaf86ac <pthread_equal+8>: nop
0x2aaf86b0 <pthread_equal+12>: sra v0,a2,0x8
This also happens when I use LD_BIND_NOW.
If I compile functest explicitly linking against pthread (which should
not be needed):
$ mipsel-linux-gcc -L. -ofunctest functest.c -lfunc -lpthread
$ ./functest
0
everything works as expected.
I have used both gcc 3.4.6 and gcc 4.0.4 and the result is the same.
Any thoughts?
--
Alexandros
More information about the uClibc
mailing list