Jakub pointed out on gcc-patches that changing the value of
__attribute__ ((aligned)) has difficulties.

Historically this value was never intended to be fixed for all time.
For example, for the i386, it was last changed here:

Tue Jan 18 16:19:55 MET 2000  Jan Hubicka  <hubi...@freesoft.cz>

        * i386.h (BIGGEST_ALIGNMENT): Set to 128.

However, people have erroneously assumed that the value is fixed, and
they have hardcoded the value into ABIs.  We even did that ourselves
for struct _Unwind_Exception in gcc/unwind-generic.h.  The C++ ABI
says the structure needs to be double-word aligned, but our code says
this:

  /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
     Taking that literally does not make much sense generically.  Instead we
     provide the maximum alignment required by any type for the machine.  */
} __attribute__((__aligned__));

This has been the case since the structure was added in 2001.

There is a clear use for __attribute__ ((aligned)) returning the
maximal required alignment.  Something like that is required for
writing a generic memory allocation routine, one which does the right
thing for arrays in the presence of auto-vectorization optimizations.
Unfortunately we have now worked ourselves into a corner where
changing __attribute__ ((aligned)) changes the ABI.

Therefore, I propose that we do the following:

1) Introduce __attribute__ ((aligned (scalar))).  This will be
   documented as having a fixed value for each ABI.  The value will be
   guaranteed to be sufficient to hold any ordinary non-vector type.
   The default will be BIGGEST_ALIGNMENT.  The value for the
   x86/x86_64 will be 128.

2) Introduce __attribute__ ((aligned (max))).  This will be documented
   as having the largest value available for any version of the
   architecture, and thus in particular it may change if new versions
   of the architecture are released.  The value will not change based
   on command line options which do not change the ABI; that is, if it
   is possible to link together two files compiled with different set
   of command line options and expect the result to work, then those
   command line options must not change the value of this attribute.
   The value will be guaranteed to be sufficient to hold any type,
   including any vector type.  The default will be BIGGEST_ALIGNMENT.
   The value for the x86/x86_64 will (presumably) be 256.

3) Deprecate __attribute__ ((aligned)).  While it remains, it will
   have the value of __attribute__ ((aligned (scalar))).  For 4.4 it
   will remain unchanged.  For 4.5 we will warn about under control of
   -Wno-deprecated.  In 4.8 or 5.0, whichever comes first, we will
   remove it.

Ian

Reply via email to