Invalid work with floating point if stack is not aligned to 8 bytes

Bug #1542193 reported by Vitaliy Bortsov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Invalid
Undecided
Unassigned

Bug Description

I check it for RM46L852 chip, with software floating point support.

#include <stdio.h>

int main()
{
    float f = 0.000187F;
    char buf[100];
    snprintf(buf, 100, "%f %f", f, (int)(f * 1e6f));
    return 0;
}

If top of stack (at least before calling __libc_init() from my startup code) is not aligned to 8 bytes then buf will be invalid for both numbers.
If top of stack is aligned to 8 bytes then buf will be correct.

Bug is detected for v5.2 2015q4, v4.9 2015q1.
Compilation flags:
arm-none-eabi-gcc -Og -mcpu=cortex-r4f -marm -g -mfloat-abi=soft -fmessage-length=0 -fno-builtin -c -std=c99 main.cpp -o main.o

Linking flags:
arm-none-eabi-g++ -Og -mcpu=cortex-r4f -marm -g -mfloat-abi=soft -fmessage-length=0 -fno-builtin -Wl,-T,rom.lds -Wl,--gc-sections --specs=nosys.specs main.o sys_startup.o -o fw.elf

Tags: float
Revision history for this message
Vitaliy Bortsov (bortsov) wrote :
description: updated
Revision history for this message
Vitaliy Bortsov (bortsov) wrote :

Additional information.
According to ARM documentation, SP must be aligned to 8 bytes for AAPCS and ABI. See http://infocenter.arm.com/help/topic/com.arm.doc.ihi0046b/IHI0046B_ABI_Advisory_1.pdf
As I suppose code in newlib rely for 8-bytes alignment.

Is all calls in newlib done according to ARM ABI, AAPCS and 8-bytes alignment on stack? It seems that no.

Should I close this "bug"?

Revision history for this message
Tejas Belagod (belagod-tejas) wrote :

The 32-bit AAPCS mandates the SP to be aligned to 8-byte boundary for all AAPCS-conforming public interfaces. So, if the stack isn't aligned to 8-bytes, the result of the program is unpredictable. This is not a bug. Thanks.

Changed in gcc-arm-embedded:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

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