glibc/misc/sys
Jonathan Wakely 8a9a593115 Add alloc_align attribute to memalign et al
GCC 4.9.0 added the alloc_align attribute to say that a function
argument specifies the alignment of the returned pointer. Clang supports
the attribute too. Using the attribute can allow a compiler to generate
better code if it knows the returned pointer has a minimum alignment.
See https://gcc.gnu.org/PR60092 for more details.

GCC implicitly knows the semantics of aligned_alloc and posix_memalign,
but not the obsolete memalign. As a result, GCC generates worse code
when memalign is used, compared to aligned_alloc.  Clang knows about
aligned_alloc and memalign, but not posix_memalign.

This change adds a new __attribute_alloc_align__ macro to <sys/cdefs.h>
and then uses it on memalign (where it helps GCC) and aligned_alloc
(where GCC and Clang already know the semantics, but it doesn't hurt)
and xposix_memalign. It can't be used on posix_memalign because that
doesn't return a pointer (the allocated pointer is returned via a void**
parameter instead).

Unlike the alloc_size attribute, alloc_align only allows a single
argument. That means the new __attribute_alloc_align__ macro doesn't
really need to be used with double parentheses to protect a comma
between its arguments. For consistency with __attribute_alloc_size__
this patch defines it the same way, so that double parentheses are
required.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-10-21 00:19:20 +01:00
..
auxv.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
cdefs.h Add alloc_align attribute to memalign et al 2021-10-21 00:19:20 +01:00
dir.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
file.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
ioctl.h Linux: Fix fcntl, ioctl, prctl redirects for _TIME_BITS=64 (bug 28182) 2021-08-06 09:52:00 +02:00
mman.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
param.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
queue.h [BZ #5779] 2008-03-05 05:50:39 +00:00
select.h y2038: Add support for 64-bit time on legacy ABIs 2021-06-15 10:42:11 -03:00
single_threaded.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
syslog.h Rename __LONG_DOUBLE_USES_FLOAT128 to __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI 2020-04-30 08:52:08 -05:00
sysmacros.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
uio.h Annotate additional APIs with GCC attribute access. 2021-05-06 11:01:05 -06:00
xattr.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00