This is the mail archive of the gcc@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: Options of fixing biggest alignment in PR target/38736


On Fri, Jan 9, 2009 at 2:22 AM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>>> For that matter, don't we have a problem on x86 GNU/Linux, where
>>> malloc returns an 8-byte alignment but attribute((aligned)) is a 16
>>> byte alignment?
>>
>> I don't think it is the same as MALLOC_ABI_ALIGNMENT.
>> attribute((aligned)) is something determined by compiler,
>> which used to be a constant.
>
> The compiler knows about malloc and new.  It should presumably assume
> that memory allocated by those operations should have some alignment.
> One might naïvely expect that the alignment of malloc would in fact by
> MALLOC_ABI_ALIGNMENT.  Perhaps MALLOC_ABI_ALIGNMENT is simply
> misnamed, or perhaps attribute((aligned)) should align to some other
> value.

We need a new attribute that lets you specify the alignment guaranteed
by a memory allocator (maybe just extend attribute malloc for this).  If
there is no such attribute on the allocator function all the compiler can
expect is that the alignment is at least MALLOC_ABI_ALIGNMENT
(if the ABI specifys it - otherwise you have to assume 1 here, a reasonable
alignment for an allocation of 1 byte).  The Ada folks requested this
(I was arguing with them that they cannot assume anything other
than 1 anyway, but ...)

>>>>> any new __attribute ((aligned (XXX))) options?
>>>>>
>>>>
>>>> I don't think we need new __attribute ((aligned (XXX))) options.
>>>
>>> Are we sure we don't need __attribute__ ((aligned(max)))?
>>>
>>
>> I don't see how it can be used safely without breaking ABI.
>
> There are many ways to align data without exposing it in the
> ABI--e.g., the alignment of a global array is not part of the ABI, in
> that nothing breaks if the alignment is increased.  Also, there are
> many programs which simply don't care about an external ABI.

I'd say if programs want to use vectorization they should use
alignof (vector_type) instead of a magic attribute((aligned(max))).
IMHO __attribute__((aligned)) should exactly be the largest alignment
required by the ABI (for i?86 this would be 4?).

Richard.

> Ian
>


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