What does the error "BUS_ADRALN - Invalid Address Alignment" mean?

We are on HPUX and my code is in C ++. We get

BUS_ADRALN - invalid address alignment

in our executable file when the function is called. What does this error mean? The same function works many times, then suddenly throws a core dump. in GDB, when I try to print the values โ€‹โ€‹of an object, it says out of context. Any clue where to check?

+4
source share
4 answers

You have a problem with data alignment. This is probably caused by an attempt to read or write through some kind of invalid pointer.

The problem of data alignment is that the address pointed to by the pointer is not aligned properly. For example, some architectures (for example, old Cray 2) require that any attempt to read from memory anything other than one character is carried out only through a pointer in which the last 3 bits of the pointer value are 0. If any of the last 3 bits equal to 1, the hardware will generate an alignment error, which will lead to the problem you see.

Most architectures are not so strict, and often the required alignment depends on which type is used. For example, a 32-bit integer may require that only the last 2 bits of the pointer be 0, and a 64-bit floating point value may require that the last 3 bits be 0.

Alignment problems usually arise from problems of the same type that can cause a SEGFAULT or segmentation error. Usually a pointer that is not initialized. But this can be caused by a bad memory allocator that does not return pointers with the correct alignment, or the result of arithmetic of a pointer on a pointer when it is not of the correct type.

The system implementation of malloc and / or operator new almost certainly true, otherwise your program will crash earlier than at the moment. Therefore, I think that a bad memory allocator is the least likely tree to bark. First, I would check the uninitialized pointer, and then the incorrect pointer arithmetic.

As a side note, the x86 and x86_64 architectures do not have alignment requirements. But because of the way the cache lines work, and for a number of other reasons, it is often recommended for performance to align your data with a border that is equal to the size of the stored data type (that is, a 4-byte border for a 32-bit integer).

+9
source

Most processors (not x86 and friends .. blacksheep lol family) require access to certain elements, which must be aligned in multiple bytes. That is, if you are reading an integer from the address 0x04, this is normal, but if you try to do the same with 0x03, you will cause an interrupt.

This is due to the fact that it is easier to implement loading / storage equipment if it is always on a multiple of the size of the data you are working with.

Since HP-UX only works on RISC processors, which usually have such limitations, you should see here โ†’ http://en.wikipedia.org/wiki/Data_structure_alignment#RISC .

+3
source

In fact, HP-UX has its own excellent ITRC forum, and some HP staff are very helpful. I just looked at the same topic you asked, and here are some results . For example, a similar problem was caused by an actually invalid input parameter. I strongly advise you to first read the answers to a similar question and, if necessary, post your question there.

By the way, you will be asked to publish the results of these gdb commands:

 (gdb) bt (gdb) info reg (gdb) disas $pc-16*8 $pc+16*4 
+1
source

Most of these problems are caused by several upstream dependencies associated with different versions of the same library.

For example, both gnustl and stlport provide various implementations of the C ++ standard library. If you compile and link to gnustl, while one of your dependencies has been compiled and linked to stlport, then you will have a different implementation of the standard functions and classes. When your program is running, the dynamic linker will attempt to resolve all exported characters and detect known characters at incorrect offsets, which will result in a BUS_ADRALN signal.

+1
source

Source: https://habr.com/ru/post/1315656/


All Articles