public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] riscv: align stack in clone [BZ #28702]
@ 2021-12-15 23:05 Aurelien Jarno
  2021-12-15 23:25 ` Andrew Waterman
  0 siblings, 1 reply; 2+ messages in thread
From: Aurelien Jarno @ 2021-12-15 23:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: Palmer Dabbelt, Darius Rad, Andrew Waterman, DJ Delorie, Aurelien Jarno

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] riscv: align stack in clone [BZ #28702]
  2021-12-15 23:05 [PATCH] riscv: align stack in clone [BZ #28702] Aurelien Jarno
@ 2021-12-15 23:25 ` Andrew Waterman
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Waterman @ 2021-12-15 23:25 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: libc-alpha, Palmer Dabbelt, Darius Rad, DJ Delorie

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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-15 23:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15 23:05 [PATCH] riscv: align stack in clone [BZ #28702] Aurelien Jarno
2021-12-15 23:25 ` Andrew Waterman

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).