[PATCH] introduce a MALLOC_ALIGNMENT configuration macro

Richard Guenther richard.guenther@gmail.com
Fri Jun 27 14:19:00 GMT 2008


On Fri, Jun 27, 2008 at 4:11 PM, Olivier Hainque <hainque@adacore.com> wrote:
> Hello,
>
> Unless rejected, user alignment requests have to be properly honored
> in Ada and GNAT accepts up to MAX_OFILE_ALIGNMENT (or BIGGEST_ALIGNMENT
> if MAX_OFILE_ALIGNMENT is undefined).
>
> For default allocators ("new" operator for a type without a user
> defined storage pool), special measures must be taken to ensure proper
> object alignments when the request exceeds what the underlying
> allocator offers.  This is gigi's "make_realigning_type" related
> circuitry.
>
> In most if not all cases, the operator eventually maps to the system
> "malloc", and it then becomes useful to have info on what this
> function guarantees.
>
> While BIGGEST_ALIGNMENT is an accurate approx for this purpose on many
> targets, it isn't appropriate on several others.
>
> This patch is a suggestion to introduce a "MALLOC_ALIGNMENT" optional
> target configuration macro, which defaults to BIGGEST_ALIGNMENT when
> not explicitly defined.
>
> It comes with definitions for a number of targets, empirically
> obtained by a simple program performing numerous allocations for
> different sizes and looking at the minimal alignment of the results.
>
> This bootstraps on x86-linux, fixes the associated testcases there,
> was bootstrapped and regression tested on x86_64-linux, and will
> shortly be regtested on x86 as well.
>
> Thanks in advance,

I think we need to be careful here.  Unless the ABI guarantees
a minimal alignment from malloc we cannot use "empirical" bigger
values.  Even if glibc may align to say 16bytes, the user may override
glibcs implementation with one aligning only to 4bytes if this is all
the ABI guarantees.

So, IMHO this at least asks for an optimization flag, like
--param malloc-alignment=N, not a static configuration.

Richard.

> Olivier
>
> 2008-06-28  Olivier Hainque  <hainque@adacore.com>
>
>        doc/
>        * tm.texi (MALLOC_ALIGNMENT): New macro.  The maximum
>        alignment "malloc" is guaranteed to honor on the target.
>
>        config/
>        * defaults.h (MALLOC_ALIGNMENT): Default to BIGGEST_ALIGNMENT.
>        * i386/linux.h (MALLOC_ALIGNMENT): Define.
>        * i386/cygming.h (MALLOC_ALIGNMENT): Define.
>        * i386/vxworks.h (MALLOC_ALIGNMENT): Define.
>        * rs6000/aix.h (MALLOC_ALIGNMENT): Define.
>        * mips/iris.h (MALLOC_ALIGNMENT): Define.
>
>        testsuite/
>        * gnat.dg/allocator_maxalign1.adb: New test.
>        * gnat.dg/test_allocator_maxalign2.adb: Main caller for ...
>        * gnat.dg/allocator_maxalign2.ad[bs]: New test.
>
>
>
>
>
>
>
>
>
>



More information about the Gcc-patches mailing list