[parisc-linux] unaligned accesses

Randolph Chung Randolph Chung <randolph@tausq.org>
Fri, 10 Jan 2003 08:29:07 -0800


> Unfortunately this doesn't reproduce the actual problem of which I save
> the following traces (from the evms_vgscan 1.1.0: once again this was fix
> since next release):

i'm not sure i correctly parsed what you wrote... the structure you
posted is fine, but that doesn't mean it cannot cause unaligned accesses
if used incorrectly.

for a simple example:
struct foo {
    int bar;
};

this structure if placed on the stack by gcc is always int-aligned. but
you can easily generate unaligned accesses from it:

void botch(void)
{
    char buf[1024];
    struct foo x;
    struct foo *a, *b;

    a = &x;
    b = (struct foo *)buf[2];

    printf("%d\n", a->bar); /* aligned */
    printf("%d\n", b->bar); /* unaligned! */
}

in this case, the structure gives you no guarantees that things will be
aligned properly.

it's also possible to have much more involved scenarios, (e.g. with
unions of things with different alignments), where things can get messed
up.... you need to carefully look at how the code works to debug these
things. while gcc may not be bug-free in this area, it's much more
likely to be an application bug than a gcc one.

randolph
-- 
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/