The following SSE2 code crashes because the non-static global variable breaks the alignment of the static data section.
align.cpp: #include <emmintrin.h> int nonstatic_padding; static int static_padding[3]; static __attribute__((aligned(16))) __m128i sse_data; int main() { static_padding[0] = 1234; sse_data = _mm_set1_epi32(123); return 0; } The example uses SSE2 because that's how I discovered the bug and because it results in a nice crash, though I don't think it's essential at all. Results: - crashes (even when static_padding is removed) - no longer crashes when removing nonstatic_padding (even when static_padding is present) - no longer crashes when making sse_data non-static Tested with: g++-4 (GCC) 4.3.2 20080827 (beta) 2 and g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) (I know they're a bit old, but Cygwin doesn't provide more recent binaries) If you rename the file to align.c gcc compiles it correctly and the program does not crash (gcc places static variables before non-static ones, unlike g++). -- Summary: g++ does not align static variables properly Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gccsse at mailinator dot com GCC build triplet: i686-pc-cygwin GCC host triplet: i686-pc-cygwin GCC target triplet: i686-pc-cygwin http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40333