Skip to contentSkip to conversation

SIGILL when calling pthread_cleanup_push()

Xenomai-help Michael Bernhard 2 participants 8 messages Oct 3, 2011 – Oct 5, 2011

lore
Share & tools
lore
#0 lore raw

Hi

We are using Xenomai-2.5.6 together with Linux-2.6.35 on a PXA270 processor. Xenomai works fine so far. However we get SIGILL when using pthread_cleanup_push() in a RT-thread. I now tried the same over Xenomai-2.6 and the behavior is still the same.

Here's a simple example which shows the problem (for Xenomai-2.6):

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <execinfo.h>
#include <sys/mman.h>

pthread_t thread_id;

void sig_handler(int signal)
{
void *bt[32];
int nentries;

  printf("Cought signal: %d\n", signal);

nentries = backtrace(bt,sizeof(bt) / sizeof(bt[0])); backtrace_symbols_fd(bt,nentries,fileno(stdout));
}

void cancel_func(void * arg)
{
}

void * thread_func(void * arg)
{
/* When forcing a mode switch to Linux, SIGILL is not generated */
#if 0
__real_printf("Force mode switch\n");
#endif

  pthread_cleanup_push (cancel_func, NULL);
  pthread_cleanup_pop(1);

return NULL;
}

int main (int argc, char * argv[])
{
pthread_attr_t attr;
struct sched_param prio = {.sched_priority = 99};

  signal(SIGILL, sig_handler);
	
  mlockall(MCL_CURRENT | MCL_FUTURE);
	
  pthread_attr_init(&attr);
  pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
  pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
  pthread_attr_setschedparam(&attr, &prio);
	
  pthread_create(&thread_id, &attr, thread_func, NULL);

  sleep(1);
	
  pthread_join(thread_id, NULL);

return 0;
}

SIGILL is not raised, when a mode switch to Linux is forced prior to call pthread_cleanup_push(). It is also not rised when the RT-thread runs under SCHED_OTHER.

The "Undefined instruction" gets incremented in /proc/xenomai/faults.

The backtrace does not reveal much information:
Cought signal: 4
./sigill[0x89bc] /lib/libc.so.6(__default_sa_restorer_v2+0x0)[0x8bda90] /lib/libc.so.6(__sigsetjmp+0x38)[0x8bc4f8] ./sigill[0x8a44] /usr/xenomai/lib/libpthread_rt.so.1(+0x4448)[0x82c448] /lib/libpthread.so.0(+0x5b60)[0x852b60] /lib/libc.so.6(clone+0x88)[0x967c58]

What is going wrong here?

--
Michael

#1 lore raw
Quoted 8 lines · Michael Bernhard

Hi

We are using Xenomai-2.5.6 together with Linux-2.6.35 on a PXA270 processor. Xenomai works fine so far. However we get SIGILL when using pthread_cleanup_push() in a RT-thread. I now tried the same over Xenomai-2.6 and the behavior is still the same.

Here's a simple example which shows the problem (for Xenomai-2.6):

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

Signature · 1 line
					    Gilles.
#2 lore raw
Quoted 8 lines · Gilles Chanteperdrix
Quoted 7 lines · Michael Bernhard

Hi

We are using Xenomai-2.5.6 together with Linux-2.6.35 on a PXA270 processor. Xenomai works fine so far. However we get SIGILL when using pthread_cleanup_push() in a RT-thread. I now tried the same over Xenomai-2.6 and the behavior is still the same.

Quoted 5 lines
Quoted 1 line

Here's a simple example which shows the problem (for Xenomai-2.6):

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

And also: is your libc built with iwmmxt support?

Signature · 1 line
					    Gilles.
#3 lore raw
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · Gilles Chanteperdrix
Quoted 7 lines · Michael Bernhard

Hi

We are using Xenomai-2.5.6 together with Linux-2.6.35 on a PXA270 processor. Xenomai works fine so far. However we get SIGILL when using pthread_cleanup_push() in a RT-thread. I now tried the same over Xenomai-2.6 and the behavior is still the same.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Here's a simple example which shows the problem (for Xenomai-2.6):

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

And also: is your libc built with iwmmxt support?

Hi Michael,

I can not reproduce this issue on another armv5 I have, but it does not support iwmmxt. So, in order to see if the problem you have comes from iwmmxt, you should try and build a root filesystem with a soft-float toolchain, such as, for instance, the codesourcery toolchain.

Currently, iwmmxt floats are not supported with Xenomai, so, if you want to get them working, something will have to be done.

Regards.

Signature · 1 line
                                                                Gilles.
#4 lore raw
Quoted 6 lines · Gilles Chanteperdrix <gilles.chanteperdrix <at> xenomai.org> writes:
Quoted 4 lines · Gilles Chanteperdrix
Quoted 3 lines · Gilles Chanteperdrix

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

We use codesourcery toolchain arm-2010.09. The rootfs was built using PTXdist. I think, but have to verify, that NPTL is used as threading library.

Quoted 1 line
Quoted 1 line

And also: is your libc built with iwmmxt support?

I don't know, but will find out.

Quoted 7 lines

I can not reproduce this issue on another armv5 I have, but it does not support iwmmxt. So, in order to see if the problem you have comes from iwmmxt, you should try and build a root filesystem with a soft-float toolchain, such as, for instance, the codesourcery toolchain.

Currently, iwmmxt floats are not supported with Xenomai, so, if you want to get them working, something will have to be done.

In the example I gave, no floats were used. Does Xenomai needs to support iwmmxt floats also in this case? And would compiling the application with -msoft-float do the trick?

ATM, I'm busy with other things but have time to investigate tomorrow evening.

--
Michael

#5 lore raw
Quoted 18 lines · Michael Bernhard
Quoted 6 lines · Gilles Chanteperdrix <gilles.chanteperdrix <at> xenomai.org> writes:
Quoted 4 lines · Gilles Chanteperdrix
Quoted 3 lines · Gilles Chanteperdrix

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

We use codesourcery toolchain arm-2010.09. The rootfs was built using PTXdist. I think, but have to verify, that NPTL is used as threading library.

Quoted 1 line
Quoted 1 line

And also: is your libc built with iwmmxt support?

I don't know, but will find out.

Quoted 5 lines

I can not reproduce this issue on another armv5 I have, but it does not support iwmmxt. So, in order to see if the problem you have comes from iwmmxt, you should try and build a root filesystem with a soft-float toolchain, such as, for instance, the codesourcery toolchain.

Quoted 7 lines
Quoted 2 lines

Currently, iwmmxt floats are not supported with Xenomai, so, if you want to get them working, something will have to be done.

In the example I gave, no floats were used. Does Xenomai needs to support iwmmxt floats also in this case? And would compiling the application with -msoft-float do the trick?

ATM, I'm busy with other things but have time to investigate tomorrow evening.

The bug happens inside sigsetjmp, which is a routine saving the current context. So, if the libc is compiled with iwmmmxt support, and more importantly, if the kernel is compiled with iwmmxt support, sigsetjmp probably saves the floating point registers.

So another simple thing to try is to disable iwmmxt support in kernel configuration.

Signature · 1 line
					    Gilles.
#6 lore raw
Quoted 27 lines · Gilles Chanteperdrix
Quoted 18 lines · Michael Bernhard
Quoted 6 lines · Gilles Chanteperdrix<gilles.chanteperdrix<at> xenomai.org> writes:
Quoted 4 lines · Gilles Chanteperdrix
Quoted 3 lines · Gilles Chanteperdrix

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

We use codesourcery toolchain arm-2010.09. The rootfs was built using PTXdist. I think, but have to verify, that NPTL is used as threading library.

Quoted 1 line
Quoted 1 line

And also: is your libc built with iwmmxt support?

I don't know, but will find out.

Quoted 5 lines

I can not reproduce this issue on another armv5 I have, but it does not support iwmmxt. So, in order to see if the problem you have comes from iwmmxt, you should try and build a root filesystem with a soft-float toolchain, such as, for instance, the codesourcery toolchain.

Quoted 7 lines
Quoted 2 lines

Currently, iwmmxt floats are not supported with Xenomai, so, if you want to get them working, something will have to be done.

In the example I gave, no floats were used. Does Xenomai needs to support iwmmxt floats also in this case? And would compiling the application with -msoft-float do the trick?

ATM, I'm busy with other things but have time to investigate tomorrow evening.

Quoted 7 lines

The bug happens inside sigsetjmp, which is a routine saving the current context. So, if the libc is compiled with iwmmmxt support, and more importantly, if the kernel is compiled with iwmmxt support, sigsetjmp probably saves the floating point registers.

So another simple thing to try is to disable iwmmxt support in kernel configuration.

I disabled iwmmxt support in the kernel my test is now working.

However what happens to applications/libraries that are compiled with iwmmxt support when this feature is disabled in the kernel?

What has to be changed in Xenomai to have iwmmxt support?

#7 lore raw
Quoted 33 lines · Michael Bernhard
Quoted 32 lines · Gilles Chanteperdrix
Quoted 18 lines · Michael Bernhard
Quoted 6 lines · Gilles Chanteperdrix<gilles.chanteperdrix<at> xenomai.org> writes:
Quoted 4 lines · Gilles Chanteperdrix
Quoted 3 lines · Gilles Chanteperdrix

Ok. Thanks for testing xenomai 2.6 by the way. I will try the test program on an ARMv5 I have tonight. However, could you tell us a bit more about your setup? What toolchain do you use? What threading library?

We use codesourcery toolchain arm-2010.09. The rootfs was built using PTXdist. I think, but have to verify, that NPTL is used as threading library.

Quoted 1 line
Quoted 1 line

And also: is your libc built with iwmmxt support?

I don't know, but will find out.

Quoted 5 lines

I can not reproduce this issue on another armv5 I have, but it does not support iwmmxt. So, in order to see if the problem you have comes from iwmmxt, you should try and build a root filesystem with a soft-float toolchain, such as, for instance, the codesourcery toolchain.

Quoted 7 lines
Quoted 2 lines

Currently, iwmmxt floats are not supported with Xenomai, so, if you want to get them working, something will have to be done.

In the example I gave, no floats were used. Does Xenomai needs to support iwmmxt floats also in this case? And would compiling the application with -msoft-float do the trick?

ATM, I'm busy with other things but have time to investigate tomorrow evening.

The bug happens inside sigsetjmp, which is a routine saving the current context. So, if the libc is compiled with iwmmmxt support, and more importantly, if the kernel is compiled with iwmmxt support, sigsetjmp probably saves the floating point registers.

Quoted 6 lines
Quoted 2 lines

So another simple thing to try is to disable iwmmxt support in kernel configuration.

I disabled iwmmxt support in the kernel my test is now working.

However what happens to applications/libraries that are compiled with iwmmxt support when this feature is disabled in the kernel?

They will get... a SIGILL when trying to use the iwmmxt instructions.

Quoted 2 lines

What has to be changed in Xenomai to have iwmmxt support?

Support for switching iwmmxt context, and this is painful. Philippe and I worked on x86 floating points and ARM/VFP, and it took several iterations to get it working correctly. The initial port of Xenomai on PXA was done without access to real hardware, but support for a new floating point instruction set can not be done that way.

Signature · 1 line
                                                                Gilles.