Skip to contentSkip to conversation

Undefined reference to ___wrap_pthread_mutex_lock and friends on Blackfin

Xenomai-core Terry Laurenzo 3 participants 4 messages Nov 13, 2006

lore
Share & tools
lore
#0 lore raw

Hello. I'm new to this list and new to Xenomai. I am getting the following when trying to build Xenomai 2.2.3:

-------------
cyclictest.elf2flt(.text+0x4946): In function `_pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_lock' cyclictest.elf2flt(.text+0x4970): In function _pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x49c8): In function _pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x49e8): In function _pthread_key_create':
: undefined reference to ___wrap_pthread_mutex_lock' cyclictest.elf2flt(.text+0x4a10): In function _pthread_key_create':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x4a2e): In function _pthread_key_create':
: undefined reference to `___wrap_pthread_mutex_unlock'
collect2: ld returned 1 exit status
-------------

The problem seems to be that the version of libpthread.a that I am using makes reference to the pthread_mutex_lock and pthread_mutex_unlock functions from a couple of places including pthread_key_create and pthread_key_delete.

Since the Posix testsuite programs link libpthread after libpthread_rt, these references (which are defined in libpthread_rt) cannot be resolved. I don't know if these calls are recent additions or what, but the uClibc/libpthread and libpthread_rt libraries are mutually dependent on each other.

I don't know enough about what is going on with the Xenomai Posix skin to figure out the right way to fix this problem, but the attached patch fixes the build failures by passing the --start-group linker flag, forcing ld to resolve circular references for all subsequent
object files. I know it's not great but it gets me going. You have
to rerun automake to get the changes.

Applying the patch makes it build but the testsuites for the Posix skin don't seem to work. For example, here is what I get when trying to run cyclictest:
root:/usr/xenomai/testsuite/cyclic> ./cyclictest
Xenomai Posix skin init: pthread_atfork: Unknown error -1

The native testsuites seem to function as expected.

Does anyone have any ideas what the issue is?

Here is my platform specs:
- Blackfin BF537-STAMP
- uClinux R06R1-RC2 with corresponding toolchain
- gcc4.1.0

Xenomai configure was run per the README like so:
$XENOMAI_DIR/configure --build=i686-pc-linux-gnu --host=bfinnommu-unknown-linux-gnu CC=bfin-uclinux-gcc CXX=bfin-uclinux-gcc AR=bfin-uclinux-ar LD=bfin-uclinux-ld --disable-shared

Also, it would appear that Xenomai releases post 2.2.3 will not run on an unpatched uClinux R06R1-RC2. The problem seems to be that some macros were added to the newer kernel for addressing various peripherals. Xenomai > 2.2.3 uses these macros which are not defined in this official uClinux release. It would be nice to note something to this effect in the readme.

Thanks!

Signature · 3 lines
Regards,
Terry Laurenzo
Redcode Technologies
src/testsuite/cyclic/Makefile.am +1 -1
diff -Naur xenomai-2.2.3.orig/src/testsuite/cyclic/Makefile.am xenomai-2.2.3/src/testsuite/cyclic/Makefile.am
@@ -6,7 +6,7 @@
 
 cyclictest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -DIPIPE_TRACE=1 -I$(top_srcdir)/include
 
-cyclictest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
+cyclictest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS) -Wl,--start-group
 
 cyclictest_LDADD = \
 	../../skins/posix/.libs/libpthread_rt.a -lpthread -lrt
src/testsuite/irqbench/Makefile.am +1 -1
diff -Naur xenomai-2.2.3.orig/src/testsuite/irqbench/Makefile.am xenomai-2.2.3/src/testsuite/irqbench/Makefile.am
@@ -16,7 +16,7 @@
 
 irqloop_LDFLAGS = \
 	$(XENO_POSIX_WRAPPERS) \
-	$(XENO_USER_LDFLAGS)
+	$(XENO_USER_LDFLAGS) -Wl,--start-group
 
 irqloop_LDADD = \
 	../../skins/posix/.libs/libpthread_rt.a -lpthread
src/testsuite/switchtest/Makefile.am +1 -1
diff -Naur xenomai-2.2.3.orig/src/testsuite/switchtest/Makefile.am xenomai-2.2.3/src/testsuite/switchtest/Makefile.am
@@ -6,7 +6,7 @@
 
 switchtest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -g -I$(top_srcdir)/include
 
-switchtest_LDFLAGS =  $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
+switchtest_LDFLAGS =  $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS) -Wl,--start-group
 
 switchtest_LDADD = \
 	../../skins/posix/.libs/libpthread_rt.a	-lpthread -lrt
#1 lore raw
Quoted 19 lines · Terry Laurenzo

Hello. I'm new to this list and new to Xenomai. I am getting the following when trying to build Xenomai 2.2.3:

-------------
cyclictest.elf2flt(.text+0x4946): In function `_pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_lock' cyclictest.elf2flt(.text+0x4970): In function _pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x49c8): In function _pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x49e8): In function _pthread_key_create':
: undefined reference to ___wrap_pthread_mutex_lock' cyclictest.elf2flt(.text+0x4a10): In function _pthread_key_create':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x4a2e): In function _pthread_key_create':
: undefined reference to `___wrap_pthread_mutex_unlock'
collect2: ld returned 1 exit status
-------------

Quoted 4 lines

The problem seems to be that the version of libpthread.a that I am using makes reference to the pthread_mutex_lock and pthread_mutex_unlock functions from a couple of places including pthread_key_create and pthread_key_delete.

The problem is that pthread_key_create and pthread_key_delete should use the libpthread.a versions of pthread_mutex_lock and pthread_mutex_unlock not xenomai versions. In order to avoid this, you have to do the link-edit in two stages: first do a partial link with libpthread_rt.a with the --wrap options, second a final link with libpthread.a without the --wrap options.

Quoted 14 lines

Since the Posix testsuite programs link libpthread after libpthread_rt, these references (which are defined in libpthread_rt) cannot be resolved. I don't know if these calls are recent additions or what, but the uClibc/libpthread and libpthread_rt libraries are mutually dependent on each other.

I don't know enough about what is going on with the Xenomai Posix skin to figure out the right way to fix this problem, but the attached patch fixes the build failures by passing the --start-group linker flag, forcing ld to resolve circular references for all subsequent
object files. I know it's not great but it gets me going. You have
to rerun automake to get the changes.

Quoted 5 lines

Applying the patch makes it build but the testsuites for the Posix skin don't seem to work. For example, here is what I get when trying to run cyclictest:
root:/usr/xenomai/testsuite/cyclic> ./cyclictest
Xenomai Posix skin init: pthread_atfork: Unknown error -1

Maybe pthread_atfork is not working at all on uclibc ?

Quoted 16 lines

The native testsuites seem to function as expected.

Does anyone have any ideas what the issue is?

Here is my platform specs:
- Blackfin BF537-STAMP
- uClinux R06R1-RC2 with corresponding toolchain
- gcc4.1.0

Xenomai configure was run per the README like so:
$XENOMAI_DIR/configure --build=i686-pc-linux-gnu --host=bfinnommu-unknown-linux-gnu CC=bfin-uclinux-gcc CXX=bfin-uclinux-gcc AR=bfin-uclinux-ar LD=bfin-uclinux-ld --disable-shared

Quoted 6 lines

Also, it would appear that Xenomai releases post 2.2.3 will not run on an unpatched uClinux R06R1-RC2. The problem seems to be that some macros were added to the newer kernel for addressing various peripherals. Xenomai > 2.2.3 uses these macros which are not defined in this official uClinux release. It would be nice to note something to this effect in the readme.

What macros ?

Signature · 1 line
                                                 Gilles Chanteperdrix
#2 lore raw

On Mon, 2006-11-13 at 09:58 +0100, Gilles Chanteperdrix wrote:

[...]

Quoted 9 lines
Quoted 6 lines

Also, it would appear that Xenomai releases post 2.2.3 will not run on an unpatched uClinux R06R1-RC2. The problem seems to be that some macros were added to the newer kernel for addressing various peripherals. Xenomai > 2.2.3 uses these macros which are not defined in this official uClinux release. It would be nice to note something to this effect in the readme.

What macros ?

Not related to the POSIX skin, but rather to the HAL/SAL Xenomai layers. These are MMIO register accessors which were not defined in earlier Blackfin kernel versions, including the official R06R1-RC2 release. Since I'm tracking the Blackfin CVS, I've updated the Xenomai codebase to use them, but this prevents to compile Xenomai against earlier kernels.

Signature · 1 line
Philippe.
#3 lore raw
In reply to Gilles Chanteperdrix
Quoted 25 lines · Gilles Chanteperdrix
Quoted 19 lines · Terry Laurenzo

Hello. I'm new to this list and new to Xenomai. I am getting the following when trying to build Xenomai 2.2.3:

-------------
cyclictest.elf2flt(.text+0x4946): In function `_pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_lock' cyclictest.elf2flt(.text+0x4970): In function _pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x49c8): In function _pthread_key_delete':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x49e8): In function _pthread_key_create':
: undefined reference to ___wrap_pthread_mutex_lock' cyclictest.elf2flt(.text+0x4a10): In function _pthread_key_create':
: undefined reference to ___wrap_pthread_mutex_unlock' cyclictest.elf2flt(.text+0x4a2e): In function _pthread_key_create':
: undefined reference to `___wrap_pthread_mutex_unlock'
collect2: ld returned 1 exit status
-------------

Quoted 4 lines

The problem seems to be that the version of libpthread.a that I am using makes reference to the pthread_mutex_lock and pthread_mutex_unlock functions from a couple of places including pthread_key_create and pthread_key_delete.

Quoted 6 lines

The problem is that pthread_key_create and pthread_key_delete should use the libpthread.a versions of pthread_mutex_lock and pthread_mutex_unlock not xenomai versions. In order to avoid this, you have to do the link-edit in two stages: first do a partial link with libpthread_rt.a with the --wrap options, second a final link with libpthread.a without the --wrap options.

Since this is an issue in the main build of xenomai, any suggestions on what the proper fix is? Should libpthread be linked with libpthread_rt during the main library build or just for the individual (testsuite) programs that use it? Does anyone have an example of some additions to the Automake rules to carry out this two step process?

Quoted 7 lines
Quoted 5 lines

Applying the patch makes it build but the testsuites for the Posix skin don't seem to work. For example, here is what I get when trying to run cyclictest:
root:/usr/xenomai/testsuite/cyclic> ./cyclictest
Xenomai Posix skin init: pthread_atfork: Unknown error -1

Maybe pthread_atfork is not working at all on uclibc ?

uclibc does not have a working fork, so I can't imagine that this behavior is required. I think that the problem, however, is in the way that I "solved" the build problem. Now, since libpthread is linking against the libpthread_rt wrapped version of mutex_lock and mutex_unlock, it is potentially causing problems since the internals of libpthread were supposed to link against the unwrapped versions. This will probably fix itself if the link-edit step is inserted correctly.

Thanks for the replies.
Terry