SIGBUS error.

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:

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

Please kindly suggest, thank you.
Eric

It’s normal… :slight_smile: 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…

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

Eric

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.

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

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

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.

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.

Try to use memcpy() instead of assignment…
Actually, post here the line where you got SIGBUS.

The memcpy should make no difference.

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?

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.

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.

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,

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

Oh I see, make sense now.

I defined a clsMatrix and used it in my user application, the code snippet as follows:

[code]class clsMatrix {
protected:
double *pM;
int m;
int n;

BOOL m_bAutoDelete;
//m_bAutoDeletenewbAutoDeleteTRUEbAutoDeleteFALSE

public:
clsMatrix();
clsMatrix(int m, int n, double *p = NULL, BOOL bAssign = FALSE);

~clsMatrix();

void Reset();
void Reset(int i, int j, double *p = NULL, BOOL bAssign = FALSE);

// Attributes
int GetM() { return m; }
int GetN() { return n; }
double *GetP() { return pM; }

BOOL EqualSize(clsMatrix &M) { return ((m == M.m) && (n == M.n)); }

public:
// Operators
double * operator [] (int i) { return pM+i*n; }

clsMatrix & operator = (clsMatrix &M);
clsMatrix & operator = (double *p);
clsMatrix & operator = (double x);
clsMatrix & operator += (clsMatrix &M);
clsMatrix & operator += (double *p);
clsMatrix & operator -= (clsMatrix &M);
clsMatrix & operator -= (double *p);
clsMatrix & operator *= (clsMatrix &mtrx);				//
clsMatrix & operator *= (double *p);
clsMatrix & operator *= (double a);
clsMatrix & operator /= (double a);

static void X(clsMatrix &mtrx1, clsMatrix &mtrx2, clsMatrix &mtrx);				//multiple
static void X(clsMatrix &mtrx1, clsVector &vctr2, clsVector &vctr);
static void X(clsVector &vctr1, clsMatrix &mtrx2, clsVector &vctr);
static void T(clsMatrix &mtrx1, clsMatrix &mtrx);				//transpose
static void R(clsMatrix &mtrx1, clsMatrix &mtrx);				//inverse
static void S(clsMatrix &mtrx1, int m0, int m1, int n0, int n1, clsMatrix &mtrx, int m = 0, int n = 0);
static void S(clsVector &vctr1, int m0, int m1, clsVector &vctr, int m = 0);

double e();
double e2();
double ei();

public:
BOOL LoadT(char *pszFile);
BOOL SaveT(char *pszFile);

friend class clsVector;

};

clsMatrix::clsMatrix()
{
m = n = 0;
pM = NULL;
m_bAutoDelete = FALSE;
}

the problem happens in the clsMatrix constructor, whenever a clsMatrix object is declared, the SIGBUS error occurs, unless the contructor is empty.

Eric[/code]

Well there are two things strange about this. First, why you are getting the SIGBUS.

The second is why you didn’t sequentially comment out lines in the constructor until you figured out which variable being set is causing it.

Assuming you go ahead and do this, I think the next step would either be to get an assembler listing to see if somehow bad code is being generated or step through with a debugger to see if that doesn’t explain the problem.

There is no new information in your post. You were asked to print the address of each variable to help determine if it is a alignment issue.

clsMatrix::clsMatrix()
{
std::cout << &m << std::endl;
std::cout << &n << std::endl;
std::cout << &pM << std::endl;
std::cout << &m_bAutoDelete << std::endl;
}

What type is BOOL?

Thanks. BOOL is self-defined “int”. this is the output, since another class has several member of type clsMatrix, the output generates as follows:

memory of m: 13d1f6
memory of n: 13d1fa
memory of pM: 13d1f2
memory of BOOL: 13d1fe
memory of m: 13d286
memory of n: 13d28a
memory of pM: 13d282
memory of BOOL: 13d28e
memory of m: 14a884
memory of n: 14a888
memory of pM: 14a880
memory of BOOL: 14a88c

Seems to me they are all even-aligned?