This is the mail archive of the
mailing list for the GCC project.
GCC ARM: aligned access
- From: Peng Fan <van dot freenix at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 31 Aug 2014 21:19:49 +0800
- Subject: GCC ARM: aligned access
- Authentication-results: sourceware.org; auth=none
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'
typedef unsigned char u8;
int func(u8 *data)
return *(unsigned int *)data;
The objdumped asm code is:
Disassembly of section .text.func:
0: e5900000 ldr r0, [r0]
4: e12fff1e bx lr
from the asm code, we can see that 'ldr r0, [r0]' corresponding to '*(unsigned int*)data'. is this correct?
we can not guarantee that pointer data is 4bytes aligned. If pointer data is not 4bytes aligned, and aligned
access check is enabled by setting a hardware bit in arm coprocessor, then `data abort` may occur.