This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: arm-elf-gcc : change default data alignement depending on ARM/THUMB
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Vincent Rubiolo <vincent dot rubiolo at st dot com>
- Cc: gcc-help at gcc dot gnu dot org, crossgcc at sources dot redhat dot com, Richard dot Earnshaw at arm dot com
- Date: Thu, 21 Aug 2003 10:02:26 +0100
- Subject: Re: arm-elf-gcc : change default data alignement depending on ARM/THUMB
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> Dear all,
>
> I am trying to figure out why gcc always aligns on 4 bytes boundaries (32 bits)
> on arm-elf-gcc in an attempt to reduce code footprint. I found that GCC produces
> much bigger code than ADS (30 to 50 %) when ARM and THUMB are mixed
> (interworking enabled) on our project.
>
> It indeed seems that ARM ADS 1.2 aligns on halfwords (16 bits) when in THUMB
> mode (along with much more sophisticated rules). GCC different behavior causes
> much more padding to be inserted in structs members and, as the project I work
> on uses HW mapped registers, application crashes.
> For now, I worked around that using a compile time define to enable the
> __attribute((packed))__ on the struct(s). I would nevertheless like to know
> whether there is another solution.
>
> I am also digging into the arm.h and arm.c files (thanks to the gcc's internal
> manual) to try to change the alignment behavior.
>
> Could you give me other ideas/solutions on that point?
>
GCC defaults to the old APCS rules on structure alignment and padding,
which means that all structures are word-aligned by default. ARM ADS uses
the ATPCS rules where structures take the alignment of their most aligned
member.
You can change gcc's default for this with the compiler switch
-mstructure-size-boundary=8
but beware that this changes the ABI, so you will need to rebuild all your
code (including the libraries) with this option.
R.