Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GCC ARM structure aligment

10 views
Skip to first unread message

LeonM

unread,
Oct 21, 2009, 6:22:22 AM10/21/09
to
Hello there,

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!

LeonM

unread,
Oct 21, 2009, 8:58:34 AM10/21/09
to
Just found out some additional information, it appears that if it goes
wrong, the pointer points to an address 2 words further than the
actual structure.

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?

Andrew Haley

unread,
Oct 25, 2009, 9:38:10 AM10/25/09
to
LeonM <leon...@gmail.com> wrote:

> 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.

0 new messages