https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70451

            Bug ID: 70451
           Summary: x86 over align struct
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: ubizjak at gmail dot com
  Target Milestone: ---
            Target: x86

[hjl@gnu-6 gcc]$ cat /tmp/a.i 
typedef struct xxx 
{
  unsigned long long a1;
  unsigned long long a2;
  unsigned long long a3;
  unsigned long long a4;
} xxx;

xxx b;
[hjl@gnu-6 gcc]$ gcc -S /tmp/a.i
[hjl@gnu-6 gcc]$ cat a.s
        .file   "a.i"
        .comm   b,32,32
        .ident  "GCC: (GNU) 5.3.1 20160212 (Red Hat 5.3.1-4)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 gcc]$ ./xgcc -B./ -S /tmp/a.i 
[hjl@gnu-6 gcc]$ cat a.s 
        .arch armv8-a+fp+simd
        .file   "a.i"
        .comm   b,32,8
        .ident  "GCC: (GNU) 6.0.0 20160304 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 gcc]$ cat a.s
        .text
        .file   "/tmp/a.i"
        .type   b,@object               # @b
        .comm   b,32,8

        .ident  "clang version 3.7.0 (tags/RELEASE_370/final)"
        .section        ".note.GNU-stack","",@progbits
[hjl@gnu-6 gcc]$ 

According to x86 psABIs, b should be aligned at 8 bytes, not 32 bites.
There are 2 issues:

1. Waste of space to align b to 32 bytes.
2. Since malloc/new only returns 8-byte aligned memory (i386) or 16-byte
aligned memory (x86-64), pointer to xxx from malloc/new won't be 32-byte
aligned.

With SSE/AVX optimization for memcpy/memset, I get segfault on unaligned
memory with pointer from malloc/new since alignment is incorrect.

Reply via email to