Modulo operator broken on uint64_t

Bug #1633882 reported by Heiko Jakob
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Invalid
High
Unassigned

Bug Description

Modulo operator '%' seems to be broken on uint64_t.
The following code crashes the MCU and put's me into the reset handler.
Simply switching uint64_t to uint32_t and it works.

int main(void) {
    int64_t j = 0;
    for (j = 0; j < 10000; j++) {
        if (j % 1000 == 0) {
            __asm__("nop");
        }
    }
}

Compile options:
arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Os -flto -fno-exceptions -c -g -Ilibopencm3/include -Iinclude -std=c11 -MMD -MP -MF "build/Debug/GNU_ARM_NONE_EABI_5_4-Linux/src/olimexino/main.o.d" -o build/Debug/GNU_ARM_NONE_EABI_5_4-Linux/src/olimexino/main.o src/olimexino/main.c
mkdir -p dist/Debug/GNU_ARM_NONE_EABI_5_4-Linux

Linker options:
arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Os -flto -fno-exceptions -o dist/Debug/GNU_ARM_NONE_EABI_5_4-Linux/olimexino-stm32-bug build/Debug/GNU_ARM_NONE_EABI_5_4-Linux/src/olimexino/main.o -Llibopencm3/lib -lopencm3_stm32f1 -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -Tstm32/f1/stm32f103xb.ld -lgcc -nostartfiles -nostdlib -nodefaultlibs -fno-exceptions -ffunction-sections -fdata-sections -Os -flto -Wl,--gc-sections -static

Linker script was used from libopencm3 for stm32f103rbt6 (included in the example code)
I've attached a code example modulo-bug.tar.bz2

Compiler used:
Binary package gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 from launchpad.net
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]

host machine:
$ uname -a
Linux wrkst01 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) x86_64 GNU/Linux
$ cat /etc/debian_version
8.6

target machine:
Olimex Olimexino-STM32 (STM32F103RBT6)

With best Regards
Heiko Jakob

Revision history for this message
Heiko Jakob (heiko-jakob) wrote :
Changed in gcc-arm-embedded:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Andre Vieira (andre-simoesdiasvieira) wrote :

Hi Heiko,

Why are you passing -mfloat-abi=softfp? The Cortex-M3 does not support Floating-Point Extensions.

This combination of options leads to the selection of our default multilib which was build for ARMv4T which supports ARM code and this is why you are getting a ldivmod implementation in ARM mode. Which obviously will not run for a Cortex-M3.

Pass either -mfloat-abi=soft or just leave out the -mfloat-abi option altogether, which defaults to 'soft'.

Best Regards,
Andre

Changed in gcc-arm-embedded:
status: Confirmed → Invalid
Revision history for this message
Heiko Jakob (heiko-jakob) wrote : Re: [Bug 1633882] Re: Modulo operator broken on uint64_t

On 17.10.2016 12:09, Andre Vieira wrote:
> Hi Heiko,
>
> Why are you passing -mfloat-abi=softfp? The Cortex-M3 does not support
> Floating-Point Extensions.
>
> This combination of options leads to the selection of our default
> multilib which was build for ARMv4T which supports ARM code and this is
> why you are getting a ldivmod implementation in ARM mode. Which
> obviously will not run for a Cortex-M3.
>
> Pass either -mfloat-abi=soft or just leave out the -mfloat-abi option
> altogether, which defaults to 'soft'.
>
> Best Regards,
> Andre
>
> ** Changed in: gcc-arm-embedded
> Status: Confirmed => Invalid
>
Oh ! Thanks !

I didn't know that softfp ain't software emulated floating point.

With best Regards
Heiko Jakob

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.