[cfe-dev] libc++ std::cout alignment trouble (was: Re: [llvm] r240144 - [SLP] Vectorize for all-constant entries.)

Dimitry Andric via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 12:58:38 PDT 2015


On 11 Oct 2015, at 01:52, Tim Northover via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> On 10 October 2015 at 14:22, Joerg Sonnenberger via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> On Sat, Oct 10, 2015 at 02:17:38PM -0700, Michael Zolotukhin via cfe-dev wrote:
>>> it looks like you relatively recently touched code in
>>> enforceKnownAlignment. Could you please comment on whether it’s correct
>>> behavior or not?
>> 
>> This looks entirely correct to me as long as PrefAlign <= 16 for AMD64.
> 
> I'm not so sure, especially when we get to other targets that don't
> have the special AMD64 rule about objects > 16 bytes in size getting
> that alignment.
> 
> It seems that the way ELF's R_..._COPY relocations work make an
> externally visible object's alignment part of a .so's ABI whether we
> like it or not. I just don't see a way around that which allows us to
> increase it at the moment.

Yes, this is the important part.  There will be existing executables out
there, compiled by previous versions of clang, or even gcc, that have
this 'bad' alignment.  Increasing the alignment now, with no way to undo
it, will break backwards compatibility.

Another interesting data point is that in the following one-liner:

__attribute__((__aligned__(8))) char cout[160];

cout will *not* be aligned to 16 bytes, whereas the sample I posted
earlier, and the code in iostream.cpp, *will* be aligned to 16 bytes,
even though the actual declarations look quite the same.

So there is something going on in llvm that bumps up the alignment, for
some reason, related to r240144.  I would like to either revert that
behavior, or try to find a way to work around it (except from reverting
r240144, that is).

Another reason to not bump the alignment is that all versions of gcc
that I tried (up to the latest 6.0.0 trunk) emit .align 8 for std::cout.
Of course we don't want to be bug-for-bug compatible with *everything*
gcc does, but this one seems a no-brainer to me. :-)

-Dimitry

P.S.: In hindsight, specifying an explicit alignment for std::cout etc
was maybe not so handy.  But it's too late to change now, without
breaking the libc++ ABI...

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151014/b8b005c9/attachment.sig>


More information about the llvm-commits mailing list