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

Tim Northover via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 14 15:31:49 PDT 2015


>> It's impossible to do otherwise (and maintain our cunning lazy
>> initialization). Other places are using std::cout as an ostream, which
>> has an ABI-required alignment of (at least) 8.

First, Joerg pointed out on IRC that my statement above was in error
and the ABI-alignment of "char cout[LOTS]" is actually 16, which means
that on AMD64 only we could have skipped the aligned attribute. I
don't think that affects what we do here though.

> I'm a bit confused about where the bug actually is though. As I
> understand it, the alignment attribute specifies the minimum
> alignment, and the cunning char array trick actually imposes a 16-byte
> ABI alignment.

So the AMD64 ABI alignment should override the attribute? I think
Dmitri has a good point that that's not how GCC interprets it (even
the documentation seems to allow under-aligning non-struct variables).
But even if so the bug would be in Clang 3.6[*] for emitting that
declaration into libc++.so with only 8 bytes alignment.

We'd also still have the issue that we probably shouldn't overalign
externally visible globals on ELF, even if the AMD64 ABI came to the
rescue in this one case.

My summary position is:
1. We need to stop over-aligning externally visible globals on ELF.
Ideally only if they're going into a shared library, but I don't think
that info is available.
2. "align 8" is correct for a "__attribute__((aligned(8))) char
arr[LOTS]" declaration.

Cheers.

Tim.

[*] Or LLVM. Or the linker. Depending on who you ask.



More information about the cfe-dev mailing list