Error assembly code generated with Os and armv6-m option

Bug #1877703 reported by liusishuang
6
This bug affects 1 person
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-7-branch revision 261907]
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
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 4
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .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-7-branch revision 261907]"

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(gcc-arm-none-eabi-9-2019-q4-major), this problem won't happen again.

Revision history for this message
liusishuang (liusishuang) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.