http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56597
Bug #: 56597 Summary: unaligned local variable used by implicit sse instructions Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: kruglin...@gmail.com I belive that i found an issue in gcc 4.7.2 this afternoon I was compile the google angleproject - a gles2 implementation on d3d9. this project require SSE2 support to compiled, so I enable it with "-march=nocona -O3" to get this work done, finally I got the Dlls. but when I try to run a test program compiled by VC++ that use the Dlls compiled by gcc, it always crashed by "Access Violation". after some analyses, I located the crashed point is a function at "src\libGLESv2\ProgramBinary.cpp" line 2681 named "bool ProgramBinary::validateSamplers(InfoLog *infoLog)" there are some statement in it: bool ProgramBinary::validateSamplers(InfoLog *infoLog) { // if any two active samplers in a program are of different types, but refer to the same // texture image unit, and this is the current program, then ValidateProgram will fail, and // DrawArrays and DrawElements will issue the INVALID_OPERATION error. const unsigned int maxCombinedTextureImageUnits = getContext()->getMaximumCombinedTextureImageUnits(); TextureType textureUnitType[MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF]; //TextureType is an enum //MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF==20 //comment by jjwang for (unsigned int i = 0; i < MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF; ++i) { textureUnitType[i] = TEXTURE_UNKNOWN; } ... } gcc generate six sse2 "movdqa" instructions to unrolling the loop, great works! but the textureUnitType is not aligned by 32 bytes, so It crashed! movdqa xmm0,xmmword ptr ds:[67B4A7D0h] movdqa xmmword ptr [esp+10h],xmm0;<=====crashed here movdqa xmmword ptr [esp+20h],xmm0 movdqa xmmword ptr [esp+30h],xmm0 movdqa xmmword ptr [esp+40h],xmm0 movdqa xmmword ptr [esp+50h],xmm0 then I made some changes and it works perfectly! __attribute__((aligned(32))) TextureType textureUnitType[MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF]; the implicit issue like this are very hard to understand for someone never know sse2 and just want to use the Dlls project. I belive that align the "local variable" that used by implicit sse instructions is compiler's work not human's, so think about it please! sorry my poor english, thanks! 03-11-2003 jjwang