]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tools/nolibc: drop manual stack pointer alignment
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 16 Mar 2025 19:46:07 +0000 (20:46 +0100)
committerThomas Weißschuh <linux@weissschuh.net>
Mon, 14 Apr 2025 05:51:25 +0000 (07:51 +0200)
The stack pointer is already aligned by the kernel to a multiple of 16.
See STACK_ROUND() in fs/binfmt_elf.c.

The manual realignment is unnecessary, drop it.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250316-nolibc-sp-align-v1-1-1e1fb073ca1e@weissschuh.net
tools/include/nolibc/arch-aarch64.h
tools/include/nolibc/arch-arm.h
tools/include/nolibc/arch-i386.h
tools/include/nolibc/arch-loongarch.h
tools/include/nolibc/arch-powerpc.h
tools/include/nolibc/arch-riscv.h
tools/include/nolibc/arch-x86_64.h

index 06fdef7b291a0b276948c08fdec7858f51616546..937a348da42e1b134d9736a5a0f6920df6e4709d 100644 (file)
@@ -146,7 +146,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
 {
        __asm__ volatile (
                "mov x0, sp\n"          /* save stack pointer to x0, as arg1 of _start_c */
-               "and sp, x0, -16\n"     /* sp must be 16-byte aligned in the callee      */
                "bl  _start_c\n"        /* transfer to c runtime                         */
        );
        __nolibc_entrypoint_epilogue();
index 6180ff99ab43dff1751f9ac22b518382a0e917c7..1f66e7e5a444b2506150f0b4f4f11f296902b2bc 100644 (file)
@@ -189,8 +189,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
 {
        __asm__ volatile (
                "mov r0, sp\n"          /* save stack pointer to %r0, as arg1 of _start_c */
-               "and ip, r0, #-8\n"     /* sp must be 8-byte aligned in the callee        */
-               "mov sp, ip\n"
                "bl  _start_c\n"        /* transfer to c runtime                          */
        );
        __nolibc_entrypoint_epilogue();
index ff5afc35bbd8be0876cbd9ae6361c3a07fb2d734..7c9b38e9641831b6b08432f833365b9f6a2b2f41 100644 (file)
@@ -167,8 +167,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
        __asm__ volatile (
                "xor  %ebp, %ebp\n"       /* zero the stack frame                                */
                "mov  %esp, %eax\n"       /* save stack pointer to %eax, as arg1 of _start_c     */
-               "add  $12, %esp\n"        /* avoid over-estimating after the 'and' & 'sub' below */
-               "and  $-16, %esp\n"       /* the %esp must be 16-byte aligned on 'call'          */
                "sub  $12, %esp\n"        /* sub 12 to keep it aligned after the push %eax       */
                "push %eax\n"             /* push arg1 on stack to support plain stack modes too */
                "call _start_c\n"         /* transfer to c runtime                               */
index fb519545959edf44f939093e21bb73a532d9ac9b..5511705303ea908209d5a8be62722491c2987f82 100644 (file)
        _arg1;                                                                \
 })
 
-#if __loongarch_grlen == 32
-#define LONG_BSTRINS "bstrins.w"
-#else /* __loongarch_grlen == 64 */
-#define LONG_BSTRINS "bstrins.d"
-#endif
-
 /* startup code */
 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __asm__ volatile (
                "move          $a0, $sp\n"         /* save stack pointer to $a0, as arg1 of _start_c */
-               LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned                    */
                "bl            _start_c\n"         /* transfer to c runtime                          */
        );
        __nolibc_entrypoint_epilogue();
index ee2fdb8d601dcc0796e1fee89b7121dc7184a523..204564bbcd328ed51a804ecbbdb55d578dee132e 100644 (file)
@@ -201,7 +201,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
 
        __asm__ volatile (
                "mr     3, 1\n"         /* save stack pointer to r3, as arg1 of _start_c */
-               "clrrdi 1, 1, 4\n"      /* align the stack to 16 bytes                   */
                "li     0, 0\n"         /* zero the frame pointer                        */
                "stdu   1, -32(1)\n"    /* the initial stack frame                       */
                "bl     _start_c\n"     /* transfer to c runtime                         */
@@ -209,7 +208,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
 #else
        __asm__ volatile (
                "mr     3, 1\n"         /* save stack pointer to r3, as arg1 of _start_c */
-               "clrrwi 1, 1, 4\n"      /* align the stack to 16 bytes                   */
                "li     0, 0\n"         /* zero the frame pointer                        */
                "stwu   1, -16(1)\n"    /* the initial stack frame                       */
                "bl     _start_c\n"     /* transfer to c runtime                         */
index 8827bf936212416f9fbc3da7428cb04664cbd702..885383a86c38b186bb6eb269e670080b36c9d982 100644 (file)
@@ -148,7 +148,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
                "lla  gp, __global_pointer$\n"
                ".option pop\n"
                "mv   a0, sp\n"           /* save stack pointer to a0, as arg1 of _start_c */
-               "andi sp, a0, -16\n"      /* sp must be 16-byte aligned                    */
                "call _start_c\n"         /* transfer to c runtime                         */
        );
        __nolibc_entrypoint_epilogue();
index 1e40620a2b33da501b7e06dda2472903f7e2bfed..67305e24dbefdcd4fd1fc6fd8fdb98d74a34c2d9 100644 (file)
@@ -166,7 +166,6 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _s
        __asm__ volatile (
                "xor  %ebp, %ebp\n"       /* zero the stack frame                            */
                "mov  %rsp, %rdi\n"       /* save stack pointer to %rdi, as arg1 of _start_c */
-               "and  $-16, %rsp\n"       /* %rsp must be 16-byte aligned before call        */
                "call _start_c\n"         /* transfer to c runtime                           */
                "hlt\n"                   /* ensure it does not return                       */
        );