]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: alignment might change in future versions
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 26 Feb 2026 16:14:20 +0000 (08:14 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 26 Feb 2026 16:35:05 +0000 (08:35 -0800)
This follows up on a comment by Wilco Dijkstra; see:
https://sourceware.org/pipermail/libc-alpha/2026-February/174934.html
* NEWS: Mention this.
* manual/memory.texi (Malloc Examples):
Say that alignment guarantee might change for small allocations.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
NEWS
manual/memory.texi

diff --git a/NEWS b/NEWS
index c63d9d6470fa623175a49740ea796353060dd41c..46590a996caab2e2534f23148c8554407aa658e7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,12 @@ Major new features:
 
 Deprecated and removed features, and other changes affecting compatibility:
 
-  [Add deprecations, removals and changes affecting compatibility here]
+* Although malloc and related functions currently return pointers
+  aligned to alignof (max_align_t), the documentation now says future
+  versions of glibc may relax alignment requirements for small allocations.
+  For example, a future malloc (1) might return a pointer with odd
+  alignment, because no object of size 1 can have a fundamental
+  alignment greater than 1.
 
 Changes to build and runtime requirements:
 
index 935df79e9c4bfe886857a9b47641a924c5fd76f7..4f0ef51514057136c14ceb6811face0117e69272 100644 (file)
@@ -653,13 +653,17 @@ savestring (const char *ptr, size_t len)
 @end group
 @end smallexample
 
-In @theglibc{}, the block that @code{malloc} gives you is guaranteed
-to be aligned so that its address is a multiple of
+In the current release of @theglibc{}, the block that @code{malloc} gives you is
+aligned so that its address is a multiple of
 @code{alignof (max_align_t)}, so that it can hold object types
 with any fundamental alignment and without stricter alignment specifiers.
 Only rarely is any higher boundary (such as a page
 boundary) necessary; for those cases, use @code{aligned_alloc} or
 @code{posix_memalign} (@pxref{Aligned Memory Blocks}).
+Future releases of @theglibc{} may relax alignment for small allocations,
+so long as any object with fundamental alignment that fits in the small
+allocation will be properly aligned.  For example, a future @code{malloc (1)}
+might return a pointer with odd alignment.
 
 Note that the memory located after the end of the block is likely to be
 in use for something else; perhaps a block already allocated by another