This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] MALLOC_ABI_ALIGNMENT macro + malloc-alignment param


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]