aboutsummaryrefslogtreecommitdiffstats
path: root/man3/malloc.3
diff options
context:
space:
mode:
authorGreg Price <price@MIT.EDU>2013-10-24 15:42:48 -0400
committerMichael Kerrisk <mtk.manpages@gmail.com>2013-10-26 11:16:19 +1300
commit25630b27643dcb2b1a85b928a0d2bc968763dd4b (patch)
tree015d4b9295833f4145e2b68ef643f1580a179575 /man3/malloc.3
parentfa9efa8632ab422a1cfab87971005a0c92708837 (diff)
downloadman-pages-25630b27643dcb2b1a85b928a0d2bc968763dd4b.tar.gz
malloc.3: Scale back promises of alignment
It's not true that the return value is suitably aligned for "any variable"; for example, it's unsuitable for a variable like float *x __attribute__ ((__vector_size__ (32))); which requires 32-byte alignment. Types like this are defined in <avxintrin.h>, and with 16-byte alignment in <emmintrin.h> and <xmmintrin.h>, so the application programmer need not even know that a vector_size attribute has been applied. On an x86 architecture, a program that loads from or stores to a pointer with this type derived from malloc can crash because GCC generates an aligned load/store, like MOVDQA. The C99 standard (TC3, as of N1256) does say the return value is suitably aligned for "any type of object". The C11 standard (as of N1570) revises this to any type with "fundamental alignment", which means an alignment "supported by the implementation in all contexts", which I suppose tautologically includes aligning malloc/realloc return values. The actual behavior of current glibc malloc is to align to the greater of 2 * sizeof(size_t) and __alignof__ (long double), which may be one bit greater than this commit promises. Signed-off-by: Greg Price <price@mit.edu> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man3/malloc.3')
-rw-r--r--man3/malloc.36
1 files changed, 3 insertions, 3 deletions
diff --git a/man3/malloc.3 b/man3/malloc.3
index 372b503c00..84d9852479 100644
--- a/man3/malloc.3
+++ b/man3/malloc.3
@@ -131,8 +131,8 @@ The
.BR malloc ()
and
.BR calloc ()
-functions return a pointer to the allocated memory
-that is suitably aligned for any kind of variable.
+functions return a pointer to the allocated memory,
+which is suitably aligned for any built-in type.
On error, these functions return NULL.
NULL may also be returned by a successful call to
.BR malloc ()
@@ -154,7 +154,7 @@ function returns no value.
The
.BR realloc ()
function returns a pointer to the newly allocated memory, which is suitably
-aligned for any kind of variable and may be different from
+aligned for any built-in type and may be different from
.IR ptr ,
or NULL if the request fails.
If