This is the mail archive of the
mailing list for the GCC project.
Re: GCC ARM: aligned access
- From: Matt Thomas <matt at 3am-software dot com>
- To: Joel Sherrill <joel dot sherrill at OARcorp dot com>
- Cc: Peng Fan <van dot freenix at gmail dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sun, 31 Aug 2014 17:09:11 -0700
- Subject: Re: GCC ARM: aligned access
- Authentication-results: sourceware.org; auth=none
- References: <540320F5 dot 9030501 at gmail dot com> <1cf062bd-289a-4375-ab2b-e34419d22bd3 at email dot android dot com>
On Aug 31, 2014, at 11:32 AM, Joel Sherrill <joel.sherrill@OARcorp.com> wrote:
>> I am writing some code and found that system crashed. I found it was
>> unaligned access which causes `data abort` exception. I write a piece
>> of code and objdump
>> it. I am not sure this is right or not.
>> arm-poky-linux-gnueabi-gcc -marm -mno-thumb-interwork -mabi=aapcs-linux
>> -mword-relocations -march=armv7-a -mno-unaligned-access
>> -ffunction-sections -fdata-sections -fno-common -ffixed-r9 -msoft-float
>> -pipe -O2 -c 2.c -o 2.o
>> arch is armv7-a and used '-mno-unaligned access'
> I think this is totally expected. You were passed a u8 pointer which is aligned for that type (no restrictions likely). You cast it to a type with stricter alignment requirements. The code is just flawed. Some CPUs handle unaligned accesses but not your ARM.
While armv7 and armv6 supports unaligned access, that support has to be
enabled by the underlying O/S. Not knowing the underlying environment,
I can't say whether that support is enabled. One issue we had in NetBSD
in moving to gcc4.8 was that the NetBSD/arm kernel didn't enable unaligned
access for armv CPUs. We quickly changed things so unaligned access