tags:

views:

63

answers:

3

We are on HPUX and my code is in C++. We am getting "BUS_ADRALN - Invalid address alignment" in my executable on a function call. What does this error means? Same function is working many times then suddenly its giving core dump. in GDB when i try to print the object values it says not in context. Any clue where to check?

Thanks in Advance.

+2  A: 

Most processors (not x86 and friends.. the blacksheep of the family lol) require accesses to certain elements to be aligned on multiples of bytes. I.e. if you read an integer from address 0x04 that is okay, but if you try to do the same from 0x03 you will cause an interrupt to be thrown.

This is because it's easier to implement the load/store hardware if it's always on a multiple of the data size with which you're working.

Since HP-UX runs only on RISC processors, which typically have such constraints, you should see here -> http://en.wikipedia.org/wiki/Data_structure_alignment#RISC.

Billy ONeal
Thanks for response. In my case my function is returning a char. its not failing every time.I will check your wiki link.
Hemant
@Hermant: I'd not be checking the return value, that's usually passed in a register. I'd be checking the arguments to the function.
Billy ONeal
my function is taking no arguments. call is likeif ( abcd->foo() == 'X' ) //do somethingelse //else part
Hemant
+1  A: 

Actually HP-UX has its own great forum on ITRC and some HP staff members are very helpful. I just took a look at the same topic you are asking and here are some results. For example the similar problem was caused actually by a bad input parameter. I strongly advise you first to read answers to similar question and if necessary to post your question there.

By the way it is likely that you will be asked to post results of these gdb commands:

(gdb) bt
(gdb) info reg
(gdb) disas $pc-16*8 $pc+16*4
skwllsp
thanks i will check hp Forum.
Hemant
+2  A: 

You are having a data alignment problem. This is likely caused by trying to read or write through a bad pointer of some kind.

A data alignment problem is when the address a pointer is pointing at isn't 'aligned' properly. For example, some architectures (the old Cray 2 for example) require that any attempt to read anything other than a single character from memory only occur through a pointer in which the last 3 bits of the pointer's value are 0. If any of the last 3 bits are 1, the hardware will generate an alignment fault which will result in the kind of problem you're seeing.

Most architectures are not nearly so strict, and frequently the required alignment depends on the exact type being accessed. For example, a 32 bit integer might require only the last 2 bits of the pointer to be 0, but a 64 bit float might require the last 3 bits to be 0.

Alignment problems are usually caused by the same kinds of problems that would cause a SEGFAULT or segmentation fault. Usually a pointer that isn't initialized. But it could be caused by a bad memory allocator that isn't returning pointers with the proper alignment, or by the result of pointer arithmetic on the pointer when it isn't of the correct type.

The system implementation of malloc and/or operator new are almost certainly correct or your program would be crashing way before it currently does. So I think the bad memory allocator is the least likely tree to go barking up. I would check first for an uninitialized pointer and then bad pointer arithmetic.

Omnifarious