Re: Unaligned access question

Martin Pool
2003-09-25T02:23:11Z

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

On 25 Sep 2003, Ian Wienand <ianw@gelato.unsw.edu.au> wrote:
> Hi,
>
> This isn't directly related to kernel development, but I am a bit
> stumped as to why my test program below causes an unaligned access
> when 'i' is 7 (that is, when it tries to access across a 64 bit
> boundary of 'array'). It's counter intuitive to me, I would have
> expected it either fault on all loads (for every value of 'i') or to
> have not faulted at all.

I think adding

__attribute__ ((aligned (1)))

will make it read the structure in a way that can handle less-aligned
addresses. (Or maybe 2-byte aligned.) By default gcc assumes strong
alignment so that it can use faster operations (ld8 or something I
suppose).

As Peter said unaligned access will not necessarily trap.

--
Martin

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]