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

Bug#136659: target/9080: optimisation on sparc leads to unalligned access in memcpy

Synopsis: optimisation on sparc leads to unalligned access in memcpy

Responsible-Changed-From-To: unassigned->rth
Responsible-Changed-By: rth
Responsible-Changed-When: Sun Jan 26 10:13:38 2003
State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Sun Jan 26 10:13:38 2003
    I'm fairly sure this has been discussed before, but I can't find
    the reference right away.  The problem is known, and I consider
    the input program incorrect.
    The problem is that alignof(struct iphdr) == 4, and yet the
    given pointer to that structure is only 2 byte aligned.  This
    violates section, to wit:
            If the resulting pointer is not correctly aligned for the
            pointed-to type, the behavior is undefined.
    GCC uses this clause to infer from the type of the pointer the
    alignment that it *must* have.
    There are two solutions for this piece of code.
    One, use packed data structures, so that they are 1 byte aligned.
    In this case something like
            struct iphdr_u {
              struct iphdr h __attribute__((packed));
    followed by
    Two, don't cast to struct iphdr at all.  Instead use offsetof
    to find the proper displacement into the buffer.


Reply to: