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

            Bug ID: 88437
           Summary: Excessive struct alignment on x86_64
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwerner at chromium dot org
  Target Milestone: ---

Compile the following test file for the x86_64 target:

 struct {
  void *a;
  void *b;
 } mystruct __attribute__((__section__(".data.mystruct"));

Then run objdump -x on the output file. The .data.mystruct section will have an
alignment of 2**4, even though the largest member of the struct only requires
an alignment of 2**3. GCC always seems to align structures to the whole struct
size, at least to a maximum of 2**5.

This behavior seems questionable at best, and it is inconsistent from all other
architectures (I tested i686 and aarch64, both of which always only align to
the largest member). I assume it may be intended as a cache line
optimization(?), but it affects code size very negatively, so it should at
least be up to the user and not hardcoded by architecture. I couldn't find any
flag in the documentation to disable this. It even occurs with -Os even though
that's meant to strongly favor size over other optimizations.

Reply via email to