I am working on a project and am getting some unaligned addresses generated. As far as I knew, gcc/g++ automatically generated aligned addresses. So, what could be the reason for unaligned addresses? Is there any flag in gcc where I can force it to generate aligned addresses?
Also, another important observation is that, mostly these unaligned addresses come from the dynamically loaded libraries.
Alignment is usually done with #pragmas in the struct definition, typically in a header file. Can you check the relevant header files to see how the structs/classes are declared?
There is a tool by intel "Pin" that is used for instrumentation for executable. This gives you data addresses and instruction addresses. And when I checked these data addresses they have alignment issues.
Can there be a better method other than checking the definition of each structure? As I don't know which structure has the problem and the code is quite big.
Memory addresses that are referred in the code, if they are aligned they should be in multiple of 2 or 4 based on kind of alignment we have. But when I see those addresses they are even odd as well. So, I don't know why that is happened, when gcc/g++ automatically aligns all data types.
It ought to be a compiler setting, but I can't find it on the Microsoft Compiler. There are some alignment options on gcc, but I can't find the one you need there either. Shocking.