Bug 40333 - g++ does not align static variables properly
Summary: g++ does not align static variables properly
Status: RESOLVED DUPLICATE of bug 37216
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-03 21:22 UTC by GCC user
Modified: 2009-08-24 06:15 UTC (History)
9 users (show)

See Also:
Host: i686-pc-cygwin
Target: i686-pc-cygwin
Build: i686-pc-cygwin
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description GCC user 2009-06-03 21:22:32 UTC
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++).
Comment 1 Andrew Pinski 2009-06-03 21:26:41 UTC

*** This bug has been marked as a duplicate of 37216 ***
Comment 2 roger pack 2009-08-24 04:38:38 UTC
(In reply to comment #0)
> The following SSE2 code crashes because the non-static global variable breaks
> the alignment of the static data section.

Is this fixed if you use 4.5.0?
Comment 3 Danny Smith 2009-08-24 06:15:39 UTC
(In reply to comment #2)
> (In reply to comment #0)
> > The following SSE2 code crashes because the non-static global variable breaks
> > the alignment of the static data section.
> 
> Is this fixed if you use 4.5.0?
> 
This is fixed with 4.5.0 and a recent binutils (Nick Clifton's patch to GAS was commuitted on 2008-09-03)
Danny