diff mbox series

riscv: align stack in clone [BZ #28702]

Message ID 20211215230537.433533-1-aurelien@aurel32.net
State Committed
Commit d2e594d71509faf36cf851a69370db34a4f5fa65
Headers show
Series riscv: align stack in clone [BZ #28702] | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Aurelien Jarno Dec. 15, 2021, 11:05 p.m. UTC
The RISC-V ABI [1] mandates that "the stack pointer shall be aligned to
a 128-bit boundary upon procedure entry". This as not the case in clone.

This fixes the misc/tst-misalign-clone-internal and
misc/tst-misalign-clone tests.

Fixes bug 28702.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc
---
 sysdeps/unix/sysv/linux/riscv/clone.S | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andrew Waterman Dec. 15, 2021, 11:25 p.m. UTC | #1
I had thought it was the caller's responsibility to provide a properly
aligned stack, but I see that the x86-64 and aarch64 ports have been
similarly patched recently.  So, LGTM.


On Wed, Dec 15, 2021 at 3:06 PM Aurelien Jarno <aurelien@aurel32.net> wrote:
>
> The RISC-V ABI [1] mandates that "the stack pointer shall be aligned to
> a 128-bit boundary upon procedure entry". This as not the case in clone.
>
> This fixes the misc/tst-misalign-clone-internal and
> misc/tst-misalign-clone tests.
>
> Fixes bug 28702.
>
> [1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc
> ---
>  sysdeps/unix/sysv/linux/riscv/clone.S | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S
> index 12f91a20d3..161e83c7e3 100644
> --- a/sysdeps/unix/sysv/linux/riscv/clone.S
> +++ b/sysdeps/unix/sysv/linux/riscv/clone.S
> @@ -32,6 +32,9 @@
>         .text
>  LEAF (__clone)
>
> +       /* Align stack to a 128-bit boundary as per RISC-V ABI.  */
> +       andi            a1,a1,ALMASK
> +
>         /* Sanity check arguments.  */
>         beqz            a0,L (invalid)  /* No NULL function pointers.  */
>         beqz            a1,L (invalid)  /* No NULL stack pointers.  */
> --
> 2.33.0
>
diff mbox series

Patch

diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S
index 12f91a20d3..161e83c7e3 100644
--- a/sysdeps/unix/sysv/linux/riscv/clone.S
+++ b/sysdeps/unix/sysv/linux/riscv/clone.S
@@ -32,6 +32,9 @@ 
 	.text
 LEAF (__clone)
 
+	/* Align stack to a 128-bit boundary as per RISC-V ABI.  */
+	andi		a1,a1,ALMASK
+
 	/* Sanity check arguments.  */
 	beqz		a0,L (invalid)	/* No NULL function pointers.  */
 	beqz		a1,L (invalid)	/* No NULL stack pointers.  */