This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] MALLOC_ABI_ALIGNMENT macro + malloc-alignment param
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Olivier Hainque" <hainque at adacore dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 18 Jul 2008 11:49:37 +0200
- Subject: Re: [PATCH] MALLOC_ABI_ALIGNMENT macro + malloc-alignment param
- References: <20080627141121.GA26568@cardhu.act-europe.fr> <84fc9c000806270717s7a7f9758q8d6bdfb13a3e2cb2@mail.gmail.com> <20080627161419.GA5342@cardhu.act-europe.fr> <84fc9c000806270944q414a8e3ayea056aec7cd757a8@mail.gmail.com> <20080627213817.GA18606@cardhu.act-europe.fr> <20080701172548.GA25353@cardhu.act-europe.fr> <20080718071208.GA2084@cardhu.act-europe.fr>
On Fri, Jul 18, 2008 at 9:12 AM, Olivier Hainque <hainque@adacore.com> wrote:
> Hi Richard,
>
> Opinion on the second version sent at
>
> http://gcc.gnu.org/ml/gcc-patches/2008-07/msg00027.html
>
> ?
>
> This is a refined suggestion, with a safer general default to
> MIN (STACK_BOUNDARY, 2*BITS_PER_WORD) and a --param option, a
> nice improvement over the first candidate IMO, thanks to your
> constructive comments.
>
> FWIW, the 2*BITS_PER_WORD idea came up reading the "debug_malloc"
> AIX documentation:
>
> << By default, the malloc subroutine returns a pointer aligned on a
> 2-word boundary. This is necessary for standards conformance [...]
>>>
Which is not true. The returned memory only has to be aligned to
the maximum alignment of a standard type that fits in the memory.
So malloc (1) may return 1-byte aligned storage. On i?86 malloc (8)
may return 4-byte aligned storage.
So, there is no safe default you can set. Instead you have to derive
the alignment from the allocation size at each allocation site, or which
I'm fine with, add a --param to specify minimum alignment which default
should be 1 for correctness.
Richard.