http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50057
--- Comment #4 from gee <jojelino at gmail dot com> 2012-01-18 13:28:53 UTC --- Created attachment 26365 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26365 proposed patch it fixes invalid padding that caused the bug. #include <cstddef> #define DEBUG 1 #include <cassert> #include <cstdlib> #include <cstdio> #include <iostream> typedef int* jthrowable,_Unwind_Ptr; struct alignment_test_struct { char space; char end[0] __attribute__((aligned)); }; struct java_exception_header { #define MEMBER_AT_FRONT \ _Unwind_Ptr* landingPad;\ int handlerSwitchValue; MEMBER_AT_FRONT struct _pad{MEMBER_AT_FRONT}; #undef MEMBER_AT_FRONT #define PADORZERO(x,y,z) (sizeof(x)<sizeof(y)?sizeof(y)-sizeof(x)+(z):0) char pad[PADORZERO(jthrowable,alignment_test_struct,PADORZERO(_pad,alignment_test_struct,0))]; #undef PADORZERO jthrowable __attribute__((packed)) value; int* unwindHeader; }; int main() { alignment_test_struct s; java_exception_header t; printf("%x\n",sizeof(alignment_test_struct)); int dat[]={offsetof(java_exception_header,pad),sizeof(java_exception_header::pad) ,offsetof(java_exception_header,value),sizeof(java_exception_header::value) ,offsetof(java_exception_header,unwindHeader),sizeof(java_exception_header::unwindHeader)}; printf("pad %x %x\n",dat[0],dat[1]); printf("value %x %x\n",dat[2],dat[3]); printf("header %x %x\n",dat[4],dat[5]); assert((dat[2]+dat[3])==dat[4]); return 0; } 10 pad 8 14 value 1c 4 header 20 4