I am currently working on an ARM port of an excising software package,
and I've encountered a problem with structure alignment. After some
searching on google, I did found that this seems to happen more often,
but there seems to be no answer to the question.
I've got a structure with some integers and chars in it, nothing
special. This structure is declared in a header file, and initiated as
follows:
extern struct foo bar[] = { {1,2,3,4},{1,2,3,4}, etc
Depending on how much code I link into the resulting .elf file, bar is
sometimes correctly aligned to a word boundry, but most of the time it
is not, also, any pointer to bar points to the wrong address (since
the pointers are word aligned but the structures somehow are not)
Already tried __attribute__((aligned(32))), but that does not seem to
change anything. Also, I'd like to keep compiler and platform specific
attributes out of the code.
These are the compiler flags I use:
-g -O0 -mcpu=arm920t -mtune=arm920t -fno-builtin -mstructure-size-
boundary=32 -fpack-struct
I use GCC 4.4.1 compiled with arm-elf as target and GDB+insight to
verify the placement of the structure.
Any suggestions what to do, or where to look?
Any help would be greatly appreciated!
So, assume structure foo is located at 0x1234 (confirmed by memory
dump), then &foo points to 0x123C.
The aligned attribute does actually place the structure on the right
boundary, but the pointer is still off...
Any idea what kind of situations this could happen?
> I am currently working on an ARM port of an excising software package,
> and I've encountered a problem with structure alignment. After some
> searching on google, I did found that this seems to happen more often,
> but there seems to be no answer to the question.
> I've got a structure with some integers and chars in it, nothing
> special. This structure is declared in a header file, and initiated as
> follows:
> extern struct foo bar[] = { {1,2,3,4},{1,2,3,4}, etc
> Depending on how much code I link into the resulting .elf file, bar
> is sometimes correctly aligned to a word boundry, but most of the
> time it is not, also, any pointer to bar points to the wrong address
> (since the pointers are word aligned but the structures somehow are
> not)
> Already tried __attribute__((aligned(32))), but that does not seem
> to change anything. Also, I'd like to keep compiler and platform
> specific attributes out of the code.
> These are the compiler flags I use:
> -g -O0 -mcpu=arm920t -mtune=arm920t -fno-builtin -mstructure-size-
> boundary=32 -fpack-struct
Why are you using -fpack-struct? Are you sure you're using it
everywhere?
> I use GCC 4.4.1 compiled with arm-elf as target and GDB+insight to
> verify the placement of the structure.
> Any suggestions what to do, or where to look?
> Any help would be greatly appreciated!
Please send a test case (it musct compile and run and demonstrate the
problem) to gcc-...@gcc.gnu.org and I'll look at it there.
Andrew.