http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50569

--- Comment #7 from Mikael Pettersson <mikpe at it dot uu.se> 2011-11-04 
15:31:25 UTC ---
Created attachment 25716
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25716
reduced test case

This reduced test case causes an alignment fault when compiled with gcc 4.7 or
4.6 on sparc64-linux and armv5tel-linux-gnueabi, but not when compiled with gcc
4.5 or older.  On sparc64-linux the alignment fault results in a fatal SIGBUS,
on armv5tel-linux-gnueabi the fault can be fixed up by the kernel but that
incurs massive runtime overhead.

The core of the test case is the following:

struct event {
    struct {
        unsigned int sec;
    } sent __attribute__((packed));
};

void __attribute__((noinline,noclone)) frob_entry(char *buf)
{
    struct event event;

    __builtin_memcpy(&event, buf, sizeof(event));
    if (event.sent.sec < 64) {
        event.sent.sec = -1U;
        __builtin_memcpy(buf, &event, sizeof(event));
    }
}

With gcc 4.6/4.7 the __builtin_memcpy() calls result in plain int-sized loads
and stores on a misaligned address.  Removing '__attribute__((packed))' from
the 'sent' struct avoids the bug.  Removing the 'struct {...} sent' wrapper
around the 'unsigned int sec' but keeping '__attribute__((packed))' also avoids
the bug.

Reply via email to