Re: Alignement on ARM
On 05/12/2010 01:21 PM, Vincent Bernat wrote:
While I have fixed my warnings, I am still a bit astonished that such a
common code as :
sa = (struct sockaddr_in *)ifa->ifa_addr;
if (... sa->sin_addr ...) ...
can lead to a misaligned access on ARM. Maybe there is something
somewhere that ensure that struct sockaddr and struct sockaddr_ll are
always aligned correctly on a 4-byte boundary?
Because with enough casting and whatnot, any magic number can get
plugged into ifa_addr.
Look carefully at where the value that gets assigned to ifa_addr comes
from. If it truly is the address of an independent structure that's
allocated by the compiler (stack, data or code), then it's highly
unlikely to be misaligned because IIRC all structures begin on 32-bit
address boundaries. I think there's even some language in the C
standard about that. I don't think your example code will exhibit any
If ifa_addr is instead the address of something inside of another
structure, and that structure is "packed", then ifa_addr could be a
misaligned pointer because of the structure packing. And if ifa_addr is
a casted pointer from a location in a byte stream, or a calculated
value, then only $deity$ knows what you can say about it other than it's
bad, bad code. :)