Hi, trying to come up with a testcase we figured out what the problem could be.
When the optimizer is on and memcpy sees that it is copying a struct with double words in it, it will assume that the struct starts on an 8 byte boundary and use double word loads and stores. This is a safe assumption, as gcc will always ensure that structs containing doubles start on an 8 byte boundary when the memory is mallocced. However we managed to trick gcc by mallocing a large chunk of memory and then assigning a pointer to a user data (unsigned int user[0]) without first ensuring that the user data was 8 byte aligned. Since the structure does contain a double, this resulted in a crash in memcopy. The fix for this was to inform the compiler that this "void" pointer should be 8 byte aligned by changing the "unsigned int user[0]" to a "unsigned long long user[0]". This will cause gcc to pad this entry out to ensure that it starts on an 8 byte boundary. Does this make sense? Alex On 8/9/07, Alex Gonzalez <[EMAIL PROTECTED]> wrote: > Hi, > > I'll try to come up with a short test. > > I have narrowed it a bit more. The PVAR structure contains a long long > variable ( with a sizeof 8 and an alignof 8 for my architecture). If I > take out the long long variable, the compiler uses sdl instructions > instead of sd and the exception doesn't happen. > > Also, if I do > > static void varcopy(void *pvar1, void *pvar2) > > the compiler uses sdl and avoids the crash. > > I am compiling for n32 ABI, so the register size is 64bits. > > Any ideas? > > On 8/9/07, David Daney <[EMAIL PROTECTED]> wrote: > > Alex Gonzalez wrote: > > > Hi, > > > > > > I am seeing an address error exception caused by the gcc optimizer -O1. > > > > > > I have narrowed it down to the following function: > > > > > > static void varcopy(PVAR *pvar1, PVAR *pvar2) { > > > memcpy(pvar1,pvar2,sizeof(PVAR)); > > > } > > > > > > Being the sizeof(PVAR) 160 bytes. > > > > > > The exception is caused on an sd instruction when the input is not > > > aligned on a doubleword boundary. > > > > > > I was under the assumption that the compiler made sure that it doesn't > > > store a doubleword that is not aligned on a doubleword boundary. Is > > > this a bug in the optimizer? > > > > > > I am using a gcc mips64 cross-compiler, > > > > > > mips64-linux-gnu-gcc (GCC) 3.3-mips64linux-031001 > > > > > > Has anyone experienced this problem before? > > > > > In order to investigate we would need a self contained test case (i.e. > > the definition of PVAR must be included). Also it would be nice if you > > could try it on a current version of GCC (4.2.1 perhaps). > > > > David Daney > > >