Skip navigation.
Home
The QNX Community Portal

View topic - SIGBUS error.

SIGBUS error.

For discussion of realtime and/or embedded programming.

SIGBUS error.

Postby Ericxx » Wed Aug 04, 2010 6:43 am

Hello,
I am porting an application from x86 to an arm based omap3530 target. I managed to compile the app, but when executing on the arm target, came with the following error:

Process 147475 (ugear) terminated SIGBUS code=1 fltno=5 ip=00104084(ugear@_btext
+0xa30) ref=00178b32
Bus error


Please kindly suggest, thank you.
Eric
Ericxx
Senior Member
 
Posts: 158
Joined: Mon Jun 09, 2008 1:38 pm

RE: SIGBUS error.

Postby AG » Wed Aug 04, 2010 7:58 am

It's normal... :) I would even say it's a standard issue when you port x86 application to any RISC CPU.
Read more about SIGBUS's and memory access alignment issues on RISCs...
AG
Active Member
 
Posts: 60
Joined: Tue Oct 21, 2003 5:17 am

RE: SIGBUS error.

Postby Ericxx » Fri Aug 06, 2010 4:41 pm

yep, thanks AG. I am now importing the app on X86 incrementally and try to find where caused the memory alignment issue.

Eric
Ericxx
Senior Member
 
Posts: 158
Joined: Mon Jun 09, 2008 1:38 pm

RE: SIGBUS error.

Postby mario » Fri Aug 06, 2010 6:58 pm

I will be difficult because x86 doesn`t suffer from alignment issue ( other then impact on performance depending on platfrom). I suggest you go back to the arm and use the debugger to find the instruction that is causing grief. The info you gave in your OP is actually telling you valuable information. If you run this in a debugger it will stop with the cursor right on the line that is causing the problem, assuming you are using a debug version and have the source code of the guilty code.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: SIGBUS error.

Postby Ericxx » Wed Aug 18, 2010 11:25 am

Thanks, mario. But how should I trace the error further if the cursor stops at a very simple assignment statement within a class constructor? Another problem is when i provide an empty constructor, then the app can execute without problem. Thank you.

Eric
Ericxx
Senior Member
 
Posts: 158
Joined: Mon Jun 09, 2008 1:38 pm

RE: SIGBUS error.

Postby mario » Wed Aug 18, 2010 1:34 pm

The line where the cursor stop is the cause of the problem, plain and simple. Either side of the operation is causing a misalign. For exemple

struct test {
char val; // at offset 0
short foo; // at offset 1
};

test abc;

abc.foo = 1; // could create a sigbuss
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: SIGBUS error.

Postby Ericxx » Wed Aug 18, 2010 2:08 pm

But my class contains variables of type only int and double, should be even alignment. As your example above, my SIGBUS error happens in the class constructor. Or something wrong with my definitions on the member functions in the class?
When I comment the assignment statement, then the cursor stops at the next assignment in the constructor, until i comment all the assignments in the constructor.
Ericxx
Senior Member
 
Posts: 158
Joined: Mon Jun 09, 2008 1:38 pm

RE: SIGBUS error.

Postby mario » Wed Aug 18, 2010 2:27 pm

I`m not familiar with alignement issue cause I have always worked on x86, but I think the double must aligned on a 8 bytes bondary. Unless you specified some option or gcc extension to pack the class/struct I would expect the compiler to properly align everything.

Print the adresse of int and double to check if they are aligned or not.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: SIGBUS error.

Postby AG » Tue Aug 24, 2010 1:09 pm

Try to use memcpy() instead of assignment...
Actually, post here the line where you got SIGBUS.
AG
Active Member
 
Posts: 60
Joined: Tue Oct 21, 2003 5:17 am

RE: SIGBUS error.

Postby mario » Tue Aug 24, 2010 5:41 pm

The memcpy should make no difference.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: SIGBUS error.

Postby maschoen » Tue Aug 24, 2010 6:44 pm

Mario,

I'm curious why you say so. Wouldn't you think memcpy has to do a character move in a loop on machines with alignment requirements?
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

RE: SIGBUS error.

Postby mario » Tue Aug 24, 2010 6:59 pm

if the variable "foo" is misaligned doing a memcpy( &foo, ...) will not solve the issue in the short term because when you try to read that variable you`ll get SIGBUS again. Not a viable solution.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: SIGBUS error.

Postby maschoen » Tue Aug 24, 2010 8:21 pm

Maybe so, but I don't see how. For example:

/* presume this variable is misaligned */
int x;

x = 5;

This code will fail because it involves some code like this:

movw x,#5

But if you do this:

memcpy(&x,"ab",2);

and the code to memcpy looks something like this:

mov cx,#2
mov [si],&x
mov [di],&"ab"
rep movsb

Each move is a byte move, which pretty much has to be aligned.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

RE: SIGBUS error.

Postby mario » Tue Aug 24, 2010 9:10 pm

But then how would you read it back.

memcpy( &dst, &x, 2 );
printf( "%d\n", dst ); // SIGBUS

If x is misaligned, what is to say that dst is?
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: SIGBUS error.

Postby maschoen » Tue Aug 24, 2010 9:20 pm

Mario,

I see we are talking about different things. Someone suggested to the poster a test to see if the problem was alignment. The test was to use memcpy. It was just a test, not meant to be a solution. If memcpy works, the problem is alignment. If it fails then the problem is memory protection or something similar.

Mitchell
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

Next

Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests