94084c
commit 9de8011c328021f10588a8acb418daf5121d5f3d
94084c
Author: Aurelien Jarno <aurelien@aurel32.net>
94084c
Date:   Tue Dec 14 22:44:35 2021 +0100
94084c
94084c
    riscv: align stack in clone [BZ #28702]
94084c
    
94084c
    The RISC-V ABI [1] mandates that "the stack pointer shall be aligned to
94084c
    a 128-bit boundary upon procedure entry". This as not the case in clone.
94084c
    
94084c
    This fixes the misc/tst-misalign-clone-internal and
94084c
    misc/tst-misalign-clone tests.
94084c
    
94084c
    Fixes bug 28702.
94084c
    
94084c
    [1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc
94084c
    
94084c
    (cherry picked from commit d2e594d71509faf36cf851a69370db34a4f5fa65)
94084c
94084c
diff --git a/sysdeps/unix/sysv/linux/riscv/clone.S b/sysdeps/unix/sysv/linux/riscv/clone.S
94084c
index 12f91a20d3bb34f5..161e83c7e3786b8d 100644
94084c
--- a/sysdeps/unix/sysv/linux/riscv/clone.S
94084c
+++ b/sysdeps/unix/sysv/linux/riscv/clone.S
94084c
@@ -32,6 +32,9 @@
94084c
 	.text
94084c
 LEAF (__clone)
94084c
 
94084c
+	/* Align stack to a 128-bit boundary as per RISC-V ABI.  */
94084c
+	andi		a1,a1,ALMASK
94084c
+
94084c
 	/* Sanity check arguments.  */
94084c
 	beqz		a0,L (invalid)	/* No NULL function pointers.  */
94084c
 	beqz		a1,L (invalid)	/* No NULL stack pointers.  */