armv7-m memcpy usage fault
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Won't Fix
|
Low
|
Terry Guo |
Bug Description
Hello,
the memcpy causes usage fault on Cortex M3 when UNALIGN_TRP is set in CCR.
Test case:
#include <string.h>
int main(void)
{
memcpy((void *)0x200050d0, (void *)0xa0ffe7b6, 42);
return 1;
}
Cross ARM Compiler
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mno-unaligned-
Cross ARM C Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mno-unaligned-
memcpy asm:
00009902: bne.n 0x9998 <memcpy+160>
00009904: subs r2, #64 ; 0x40
00009906: bcc.n 0x9950 <memcpy+88>
-->>>00009908: ldr r3, [r1, #0] ; ldr from 0xa0ffe7b6, unaligned fault
0000990a: str r3, [r0, #0]
0000990c: ldr r3, [r1, #4]
Changed in gcc-arm-embedded: | |
assignee: | nobody → Terry Guo (terry.guo) |
I did some inspection and the reason for this error is following:
arm-none-eabi-gcc -mcpu=cortex-m3 by default assumes that the unaligned access is enabled. The macro __ARM_FEATURE_ UNALIGNED is set. The source code in newlib machine/ arm/memcpy- armv7m. S is built with this macro. The result is weird. It is bug and it is not bug.
I think there should be mentioned in the readme.txt to NOT TO SET UNALIGN_TRP in CCR. Anyway, the GDB with UNALIGN_TRP behaves strange. I was unable to get stack list, debugger reported read from non existent addresses etc. I have disabled UNALIGN_TRP bit and it works now fine.
Best
Martin