[Xenomai-core] [PATCH] Wrong -lpthread/-lrt order in testsuite/clocktest/Makefile.am ?

2007-11-08 Thread Fillod Stephane
Hi,

Testing xenomai-2.4-rc5, I've encountered the following link error:

powerpc-linux-uclibc-gcc -Wl,--wrap -Wl,pthread_create 
-Wl,--wrap -Wl,mmap -Wl,--wrap -Wl,munmap -o clocktest
clocktest-clocktest.o  ../../skins/posix/.libs/libpthread_rt.a -lpthread
-lrt
.../powerpc-linux-uclibc/lib/libpthread.so: undefined reference to
`__wrap_mmap'
.../powerpc-linux-uclibc/lib/librt.so: undefined reference to
`__wrap_close'
.../powerpc-linux-uclibc/lib/libpthread.so: undefined reference to
`__wrap_munmap'
collect2: ld returned 1 exit status
gmake[4]: *** [clocktest] Error 1
$ powerpc-linux-uclibc-gcc --version
powerpc-linux-uclibc-gcc (GCC) 3.4.3
$ powerpc-linux-uclibc-ld --version
GNU ld version 2.16.90.0.1 20050408

If I swap the order of libpthread_rt.a and -lpthread -lrt, the link
succeeds.
I guess it has to do with the fact that a library which provides symbols
has to be after in the link order of a module which needs them.
Is it still okay with regard to pthread function wrapping?

--- src/testsuite/clocktest/Makefile.am 16 Sep 2007 17:20:32 -
1.1.1.1
+++ src/testsuite/clocktest/Makefile.am 8 Nov 2007 14:01:33 -
@@ -9,7 +9,7 @@
 clocktest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)

 clocktest_LDADD = \
-   ../../skins/posix/libpthread_rt.la -lpthread -lrt
+   -lpthread -lrt ../../skins/posix/libpthread_rt.la

 install-data-local:
$(mkinstalldirs) $(DESTDIR)$(testdir)

Here is the resulting command line (only -lrt is swapped actually):
powerpc-linux-uclibc-gcc -Wl,--wrap -Wl,pthread_create 
-Wl,--wrap -Wl,mmap -Wl,--wrap -Wl,munmap -o clocktest
clocktest-clocktest.o  -lrt ../../skins/posix/.libs/libpthread_rt.a
-lpthread

-- 
Stephane

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] [PATCH] Wrong -lpthread/-lrt order in testsuite/clocktest/Makefile.am ?

2007-11-08 Thread Gilles Chanteperdrix
On Nov 8, 2007 3:10 PM, Fillod Stephane [EMAIL PROTECTED] wrote:
 Hi,

 Testing xenomai-2.4-rc5, I've encountered the following link error:

 powerpc-linux-uclibc-gcc -Wl,--wrap -Wl,pthread_create 
 -Wl,--wrap -Wl,mmap -Wl,--wrap -Wl,munmap -o clocktest
 clocktest-clocktest.o  ../../skins/posix/.libs/libpthread_rt.a -lpthread
 -lrt
 .../powerpc-linux-uclibc/lib/libpthread.so: undefined reference to
 `__wrap_mmap'
 .../powerpc-linux-uclibc/lib/librt.so: undefined reference to
 `__wrap_close'
 .../powerpc-linux-uclibc/lib/libpthread.so: undefined reference to
 `__wrap_munmap'
 collect2: ld returned 1 exit status
 gmake[4]: *** [clocktest] Error 1
 $ powerpc-linux-uclibc-gcc --version
 powerpc-linux-uclibc-gcc (GCC) 3.4.3
 $ powerpc-linux-uclibc-ld --version
 GNU ld version 2.16.90.0.1 20050408

 If I swap the order of libpthread_rt.a and -lpthread -lrt, the link
 succeeds.
 I guess it has to do with the fact that a library which provides symbols
 has to be after in the link order of a module which needs them.
 Is it still okay with regard to pthread function wrapping?

No, libpthread_rt.a uses symbols defined by libpthread.so and
librt.so, so, they should be after. What you are observing is likely
an issue with regard to --wrap with static libraries.

The solution to this problem is to either use the dynamic
libpthread_rt.so, or to do the link edit in two stages:
first stage with libpthread_rt.a and all the --wrap
second stage with -lpthread and -lrt without all the --wrap

Unfortunately, the behaviour of --wrap with static libraries is not
the same on all platforms.

-- 
   Gilles Chanteperdrix

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core