Error assembly code generated with Os and armv6-m option
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
New
|
Undecided
|
Unassigned |
Bug Description
toolchain:
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C code as follows(also in attachment):
struct time_stamp {
unsigned int seconds : 16;
unsigned int minutes : 16;
};
unsigned int rtc_read(void)
{
unsigned int val = 0xffffffff;
struct time_stamp *ts = (struct time_stamp *)&val;
ts->minutes = 0;
/* value come from register */
ts->seconds = *(unsigned int *)0x20000000;
return val;
}
Use command:
arm-none-eabi-gcc -S -mthumb -march=armv6-m -Os error_code.c
Assembly coed:
.arch armv6-m
.file "error_code.c"
.text
.align 1
.global rtc_read
.syntax unified
.code 16
.thumb_func
.fpu softvfp
.type rtc_read, %function
rtc_read:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
movs r2, #0
sub sp, sp, #8
add r3, sp, #4
strh r2, [r3, #2]
movs r2, #128
lsls r2, r2, #22
ldr r2, [r2]
ldr r0, [sp, #4]
strh r2, [r3]
add sp, sp, #8
@ sp needed
bx lr
.size rtc_read, .-rtc_read
.ident "GCC: (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-
In assembly code, r0 was assigned befor "strh r2. [r3]". As r0 is return value, it causee ts->sencods remain 0xffff when it supposed to be value in address 0x20000000.
If -march=armv6-m change to -march=armv7-m, or use last toolchain release version(