aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--malloc/malloc.h5
-rw-r--r--misc/sys/cdefs.h10
-rw-r--r--stdlib/stdlib.h4
-rw-r--r--support/support.h5
4 files changed, 19 insertions, 5 deletions
diff --git a/malloc/malloc.h b/malloc/malloc.h
index 2df0b38050..0e8a0cf051 100644
--- a/malloc/malloc.h
+++ b/malloc/malloc.h
@@ -1,5 +1,6 @@
/* Prototypes and definition for malloc implementation.
Copyright (C) 1996-2021 Free Software Foundation, Inc.
+ Copyright The GNU Toolchain Authors.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -64,8 +65,8 @@ extern void free (void *__ptr) __THROW;
/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
extern void *memalign (size_t __alignment, size_t __size)
- __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur
- __attr_dealloc_free;
+ __THROW __attribute_malloc__ __attribute_alloc_align__ ((1))
+ __attribute_alloc_size__ ((2)) __wur __attr_dealloc_free;
/* Allocate SIZE bytes on a page boundary. */
extern void *valloc (size_t __size) __THROW __attribute_malloc__
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index c353d2ec4d..ab57d4a065 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -1,4 +1,5 @@
/* Copyright (C) 1992-2021 Free Software Foundation, Inc.
+ Copyright The GNU Toolchain Authors.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -290,6 +291,15 @@
# define __attribute_alloc_size__(params) /* Ignore. */
#endif
+/* Tell the compiler which argument to an allocation function
+ indicates the alignment of the allocation. */
+#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
+# define __attribute_alloc_align__(param) \
+ __attribute__ ((__alloc_align__ param))
+#else
+# define __attribute_alloc_align__(param) /* Ignore. */
+#endif
+
/* At some point during the gcc 2.96 development the `pure' attribute
for functions was introduced. We don't want to use it unconditionally
(although this would be possible) since it generates warnings. */
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 74c00eee73..1feb381211 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -1,4 +1,5 @@
/* Copyright (C) 1991-2021 Free Software Foundation, Inc.
+ Copyright The GNU Toolchain Authors.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -589,7 +590,8 @@ extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size)
#ifdef __USE_ISOC11
/* ISO C variant of aligned allocation. */
extern void *aligned_alloc (size_t __alignment, size_t __size)
- __THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
+ __THROW __attribute_malloc__ __attribute_alloc_align__ ((1))
+ __attribute_alloc_size__ ((2)) __wur;
#endif
/* Abort execution and generate a core-dump. */
diff --git a/support/support.h b/support/support.h
index 0ee454da6d..10a4a36848 100644
--- a/support/support.h
+++ b/support/support.h
@@ -1,5 +1,6 @@
/* Common extra functions.
Copyright (C) 2016-2021 Free Software Foundation, Inc.
+ Copyright The GNU Toolchain Authors.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -104,8 +105,8 @@ extern void *xrealloc (void *o, size_t n)
extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free
__returns_nonnull;
void *xposix_memalign (size_t alignment, size_t n)
- __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free
- __returns_nonnull;
+ __attribute_malloc__ __attribute_alloc_align__ ((1))
+ __attribute_alloc_size__ ((2)) __attr_dealloc_free __returns_nonnull;
char *xasprintf (const char *format, ...)
__attribute__ ((format (printf, 1, 2), malloc)) __attr_dealloc_free
__returns_nonnull;