public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vitaly Kuzmichev <vkuzmichev@mvista.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] ARM: Align stack to 8 bytes
Date: Tue, 22 Jun 2010 18:47:01 +0400	[thread overview]
Message-ID: <4C20CCE5.9000100@mvista.com> (raw)
In-Reply-To: <1276625891-22206-1-git-send-email-vkuzmichev@mvista.com>

I would like to add some explanations:

This is the issue gone from GCC behavior on VLA allocation. I did a
simple test with VLA, and the following snippet from its ASM listing may
clarify the root cause of issue:

VLA allocation start.
R1 is initialized by the length of VLA.
>80080030:       e281300f        add     r3, r1, #15     ; 0xf
>80080034:       e2033f7e        and     r3, r3, #504    ; 0x1f8
Align VLA size.

>80080038:       e1a0500d        mov     r5, sp
Save SP to recover it when VLA becomes needless.

>8008003c:       e04dd003        sub     sp, sp, r3
Allocate R3 bytes on stack.

>80080040:       e1a0300d        mov     r3, sp
Store VLA address in R3.

>80080044:       e1a0c1a3        lsr     ip, r3, #3
>80080048:       e1a0218c        lsl     r2, ip, #3
Here VLA address is aligned by 8 bytes.

If SP is either 0xYYYYYYY4 or 0xZZZZZZZC, r2 will lose significant digit
and will become 0xYYYYYYY0/0xZZZZZZZ8 (VLA=SP-4). It will less than SP,
so the next 'push' (alias to STMDB) will decrement SP by 4 and will
store register at the top of the stack, so this will overwrite first 4
bytes of VLA.


On 06/15/2010 10:18 PM, Vitaly Kuzmichev wrote:
> The ARM ABI requires that the stack be aligned to 8 bytes as it is noted
> in Procedure Call Standard for the ARM Architecture:
> http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/index.html
> 
> Unaligned SP also causes the problem with variable-length arrays
> allocation when VLA address becomes less than stack pointer during
> aligning of this address, so the next 'push' in the stack overwrites
> first 4 bytes of VLA.
> 
> Signed-off-by: Vitaly Kuzmichev <vkuzmichev@mvista.com>

  reply	other threads:[~2010-06-22 14:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-15 10:52 [U-Boot] [PATCH] ARM1136: Align stack to 8 bytes Vitaly Kuzmichev
2010-06-15 11:16 ` Martin Krause
2010-06-15 13:16   ` Vitaly Kuzmichev
2010-06-15 18:18     ` [U-Boot] [PATCH v2] ARM: " Vitaly Kuzmichev
2010-06-22 14:47       ` Vitaly Kuzmichev [this message]
2010-06-22 20:20       ` Wolfgang Denk
2010-07-05  8:56         ` Minkyu Kang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C20CCE5.9000100@mvista.com \
    --to=vkuzmichev@mvista.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox