diff options
author | Bernd Schmidt <bernds@codesourcery.com> | 2011-04-11 13:19:05 +0200 |
---|---|---|
committer | Bernd Schmidt <bernds@codesourcery.com> | 2011-04-11 13:26:56 +0200 |
commit | eff2d0ba5890b517ef5bc9d0269d6149556c12c8 (patch) | |
tree | 46eb9f209a53ca39b31eeb80ed797f4c50dca105 /libc/stdlib/malloc/heap.h | |
parent | 56ea76b6bf190bffdc07aba90e4b25dfc096027b (diff) |
Fix malloc alignment
In commit 3e0a1f388, Richard tried to fix malloc alignments by using
alignof (double __attribute_aligned__(sizeof (size_t))).
This doesn't work, since attribute_aligned overrides the alignment
rather than providing a minimum. On C6X, malloc returns four-byte
aligned values rather than the necessary eight-byte alignment.
It's simpler to use a comparison and pick the bigger of the two values,
so that's what I've done.
Signed-off-by: Bernd Schmidt <bernds@codesourcery.com>
Diffstat (limited to 'libc/stdlib/malloc/heap.h')
-rw-r--r-- | libc/stdlib/malloc/heap.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libc/stdlib/malloc/heap.h b/libc/stdlib/malloc/heap.h index 30380791f..2f06ab17c 100644 --- a/libc/stdlib/malloc/heap.h +++ b/libc/stdlib/malloc/heap.h @@ -29,8 +29,10 @@ /* The heap allocates in multiples of, and aligned to, HEAP_GRANULARITY. HEAP_GRANULARITY must be a power of 2. Malloc depends on this being the same as MALLOC_ALIGNMENT. */ -#define HEAP_GRANULARITY_TYPE double __attribute_aligned__ (sizeof (size_t)) -#define HEAP_GRANULARITY (__alignof__ (HEAP_GRANULARITY_TYPE)) +#define HEAP_GRANULARITY_TYPE double __attribute_aligned__ (HEAP_GRANULARITY) +#define HEAP_GRANULARITY \ + (__alignof__ (double) > sizeof (size_t) ? __alignof__ (double) : sizeof (size_t)) + /* The HEAP_INIT macro can be used as a static initializer for a heap |