public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66547] New: arm-none-eabi-gcc - stack misaligned when calling va_arg function
@ 2015-06-15 23:54 matt at hpamotorsport dot com
2015-06-16 0:00 ` [Bug target/66547] " matt at hpamotorsport dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: matt at hpamotorsport dot com @ 2015-06-15 23:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66547
Bug ID: 66547
Summary: arm-none-eabi-gcc - stack misaligned when calling
va_arg function
Product: gcc
Version: 4.9.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: matt at hpamotorsport dot com
Target Milestone: ---
Created attachment 35785
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35785&action=edit
File from project
I'm working on a project that uses ChibiOS
(https://github.com/ChibiOS/ChibiOS/tree/stable_2.6.x) where I have a function
that calls a va_arg function but the stack is not aligned after the calling
function allocates it's local resources. This causes 64-bit variables (long
long as well as double) to be incorrectly placed.
The assembly generated shows that the stack pointer is moved by 116 where it
should be moved by 120 to keep the alignment to 8-bytes.
arm-none-eabi-gcc -c -mcpu=cortex-m3 -Os -ggdb -fsingle-precision-constant
-mno-unaligned-access -mabi=aapcs -mtune=cortex-m3 -save-temps
-ffunction-sections -fdata-sections -fno-common -Wall -Wextra
-Wstrict-prototypes -Wa,-alms=build/lst/performance.lst -DCORTEX_USE_FPU=FALSE
-DBOARD_HALDEX_STM32_P105_A1=1 -DOSC_HAS_64BIT -DOSC_HAS_FLOAT
-DOSC_HAS_HEARTBEAT -DSLP_HAS_USB -D__BUILD_NUMBER=`cat build-number.txt`
-DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF
.dep/performance.o.d -mthumb -DTHUMB -I.
-I../ChibiOS_2.6.7/os/ports/common/ARMCMx/CMSIS/include
-I../ChibiOS_2.6.7/os/ports/common/ARMCMx
-I../ChibiOS_2.6.7/os/ports/GCC/ARMCMx
-I../ChibiOS_2.6.7/os/ports/GCC/ARMCMx/STM32F1xx
-I../ChibiOS_2.6.7/os/kernel/include -I../ChibiOS_2.6.7/os/hal/include
-I../ChibiOS_2.6.7/os/hal/platforms/STM32F1xx
-I../ChibiOS_2.6.7/os/hal/platforms/STM32
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/GPIOv1
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/I2Cv1
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/RTCv1
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/SPIv1
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/TIMv1
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/USARTv1
-I../ChibiOS_2.6.7/os/hal/platforms/STM32/OTGv1 -I../HPA_Libraries/board
-I../ChibiOS_2.6.7/os/various -I../HPA_Libraries performance.c -o
build/obj/performance.o
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/66547] arm-none-eabi-gcc - stack misaligned when calling va_arg function
2015-06-15 23:54 [Bug c/66547] New: arm-none-eabi-gcc - stack misaligned when calling va_arg function matt at hpamotorsport dot com
@ 2015-06-16 0:00 ` matt at hpamotorsport dot com
2015-06-16 10:01 ` rearnsha at gcc dot gnu.org
2015-06-16 16:45 ` matt at hpamotorsport dot com
2 siblings, 0 replies; 4+ messages in thread
From: matt at hpamotorsport dot com @ 2015-06-16 0:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66547
--- Comment #1 from Matthew Peters <matt at hpamotorsport dot com> ---
Adding some notes.
The stack is a local stack generated with "static WORK_AREA(...)" from ChibiOS.
I've checked and the stack is aligned at the beginning of
performance_suite_thread.
I've been unable to make a test that produces the error.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/66547] arm-none-eabi-gcc - stack misaligned when calling va_arg function
2015-06-15 23:54 [Bug c/66547] New: arm-none-eabi-gcc - stack misaligned when calling va_arg function matt at hpamotorsport dot com
2015-06-16 0:00 ` [Bug target/66547] " matt at hpamotorsport dot com
@ 2015-06-16 10:01 ` rearnsha at gcc dot gnu.org
2015-06-16 16:45 ` matt at hpamotorsport dot com
2 siblings, 0 replies; 4+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2015-06-16 10:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66547
Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
I presume you are talking about the function performance_suite_thread (the only
mention of a stack adjustment by 116 bytes).
By my calculations this function does not misalign the stack.
The sub sp, sp, #116 has to be read in context with the initial push
instruction. 116 is 29 words, the push instruction pushes 9 registers (36
bytes), making for a total of 38 words (152 bytes) of data: that's an even
multiple of 8 bytes, so if SP was aligned on entry to that function it will
still be aligned once the prologue code has completed.
Note that the code reads:
performance_suite_thread:
// ABI Assertion: SP % 8 = 0
.LFB66:
.loc 1 86 0
.cfi_startproc
@ args = 0, pretend = 0, frame = 72
@ frame_needed = 0, uses_anonymous_args = 0
.LVL4:
push {r4, r5, r6, r7, r8, r9, r10, fp, lr} // 9 words
.cfi_def_cfa_offset 36
.cfi_offset 4, -36
.cfi_offset 5, -32
.cfi_offset 6, -28
.cfi_offset 7, -24
.cfi_offset 8, -20
.cfi_offset 9, -16
.cfi_offset 10, -12
.cfi_offset 11, -8
.cfi_offset 14, -4
.loc 1 115 0
ldr r3, .L37
.loc 1 86 0
sub sp, sp, #116 // + 29 words = 38 total
.cfi_def_cfa_offset 152
// ABI Assertion: SP % 8 = 0 if calls are made from this function.
Note that the .cfi_def_cfa_offset of 152 would appear to confirm this analysis:
the total change in the frame offsets is 152 bytes.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/66547] arm-none-eabi-gcc - stack misaligned when calling va_arg function
2015-06-15 23:54 [Bug c/66547] New: arm-none-eabi-gcc - stack misaligned when calling va_arg function matt at hpamotorsport dot com
2015-06-16 0:00 ` [Bug target/66547] " matt at hpamotorsport dot com
2015-06-16 10:01 ` rearnsha at gcc dot gnu.org
@ 2015-06-16 16:45 ` matt at hpamotorsport dot com
2 siblings, 0 replies; 4+ messages in thread
From: matt at hpamotorsport dot com @ 2015-06-16 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66547
--- Comment #3 from Matthew Peters <matt at hpamotorsport dot com> ---
Thanks for looking into that; you are correct.
And I feel rather stupid as, when testing to double-check your assessment, I
found that the stack was not aligned before the function starts.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-16 16:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-15 23:54 [Bug c/66547] New: arm-none-eabi-gcc - stack misaligned when calling va_arg function matt at hpamotorsport dot com
2015-06-16 0:00 ` [Bug target/66547] " matt at hpamotorsport dot com
2015-06-16 10:01 ` rearnsha at gcc dot gnu.org
2015-06-16 16:45 ` matt at hpamotorsport dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).