This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcj/50057] [4.7 regression] misalignment of java_exception_header resulted in throwable to be null
- From: "jojelino at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 18 Jan 2012 13:28:53 +0000
- Subject: [Bug libgcj/50057] [4.7 regression] misalignment of java_exception_header resulted in throwable to be null
- Auto-submitted: auto-generated
- References: <bug-50057-4@http.gcc.gnu.org/bugzilla/>
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