Re: Alignment question, sparc-centric

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* David Miller <davem@xxxxxxxxxxxxx> [070602 22:09]:
> Types must be aligned on their natural size, and GCC can assume
> this everywhere you reference such types unless you use the
> "packed" GCC attribute.

And even with packed, the struct itself must be naturally aligned
(unless itself is in a packed struct, if course).
Funny example (I think from some dhcp-client):
Make a packed struct with an 32 bit value on a 4*n+2 address,
and (illegally[1] since it's the wrong alignment) cast a char pointer
to an 4*m+2 address. Then the 32 bit value will be at an double even
address. But as gcc may optimize for a 4*m address of the struct,
it will even optimize a memcpy for that field away, replacing it with
loads of the (only presumed) double-even addresses before and after
and code to combine them. Thus you get a bus error for accessing a
32 bit value at an double-even address, because the struct it was in
was not.

Hochachtungsvoll,
	Bernhard R. Link

[1] for proper values of "illegal". I guess that will only be
something triggering undefined behaviour, not any other meaning
of illegal.
-
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Development]     [DCCP]     [Linux ARM Development]     [Linux]     [Photo]     [Yosemite Help]     [Linux ARM Kernel]     [Linux SCSI]     [Linux x86_64]     [Linux Hams]

  Powered by Linux