]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/nolibc: move entrypoint specifics to compiler.h
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 7 Aug 2024 21:51:41 +0000 (23:51 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Mon, 12 Aug 2024 20:21:00 +0000 (22:21 +0200)
The specific attributes for the _start entrypoint are duplicated for
each architecture.
Deduplicate it into a dedicated #define into compiler.h.

For clang compatibility, the epilogue will also need to be adapted, so
move that one, too.

Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20240807-nolibc-llvm-v2-5-c20f2f5fc7c2@weissschuh.net
Signed-off-by: Thomas Weißschuh <linux@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-mips.h
tools/include/nolibc/arch-powerpc.h
tools/include/nolibc/arch-riscv.h
tools/include/nolibc/arch-s390.h
tools/include/nolibc/arch-x86_64.h
tools/include/nolibc/compiler.h

index b23ac1f04035e07c973ff70c34c0f3cde882228c..06fdef7b291a0b276948c08fdec7858f51616546 100644 (file)
 })
 
 /* startup code */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __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                         */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 #endif /* _NOLIBC_ARCH_AARCH64_H */
index d1c19d973e55c130d27209183245709be8d32773..6180ff99ab43dff1751f9ac22b518382a0e917c7 100644 (file)
 })
 
 /* startup code */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __asm__ volatile (
                "mov r0, sp\n"          /* save stack pointer to %r0, as arg1 of _start_c */
@@ -193,7 +193,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                "mov sp, ip\n"
                "bl  _start_c\n"        /* transfer to c runtime                          */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #endif /* _NOLIBC_ARCH_ARM_H */
index 28c26a00a7625f5597020673b740b7cb40e60446..ff5afc35bbd8be0876cbd9ae6361c3a07fb2d734 100644 (file)
  * 2) The deepest stack frame should be set to zero
  *
  */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __asm__ volatile (
                "xor  %ebp, %ebp\n"       /* zero the stack frame                                */
@@ -174,7 +174,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                "call _start_c\n"         /* transfer to c runtime                               */
                "hlt\n"                   /* ensure it does not return                           */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #endif /* _NOLIBC_ARCH_I386_H */
index 3f8ef8f86c0f10c1ef38ee2bcd2fb9bea0a13317..fb519545959edf44f939093e21bb73a532d9ac9b 100644 (file)
 #endif
 
 /* startup code */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+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                          */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #endif /* _NOLIBC_ARCH_LOONGARCH_H */
index a2ee77ed2fbb2853ce8d5e8fda055c2b1fafc41e..1791a8ce58da6f72d305498957aaad489d4c143c 100644 (file)
 })
 
 /* startup code, note that it's called __start on MIPS */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector __start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void)
 {
        __asm__ volatile (
                ".set push\n"
@@ -200,7 +200,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                " nop\n"                 /* delayed slot                                   */
                ".set pop\n"
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #endif /* _NOLIBC_ARCH_MIPS_H */
index 41ebd394b90c7ace7229302960e7440927841dd6..ee2fdb8d601dcc0796e1fee89b7121dc7184a523 100644 (file)
 #endif /* !__powerpc64__ */
 
 /* startup code */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
 #ifdef __powerpc64__
 #if _CALL_ELF == 2
@@ -215,7 +215,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                "bl     _start_c\n"     /* transfer to c runtime                         */
        );
 #endif
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #endif /* _NOLIBC_ARCH_POWERPC_H */
index 1927c643c7395052ed0161179782500a245cb2f1..8827bf936212416f9fbc3da7428cb04664cbd702 100644 (file)
 })
 
 /* startup code */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __asm__ volatile (
                ".option push\n"
@@ -151,7 +151,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                "andi sp, a0, -16\n"      /* sp must be 16-byte aligned                    */
                "call _start_c\n"         /* transfer to c runtime                         */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #endif /* _NOLIBC_ARCH_RISCV_H */
index 5d60fd43f88309e099aa07efc6369fa8ab7e2a60..2ec13d8b9a2db80efa8d6cbbbd01bfa3d0059de2 100644 (file)
 })
 
 /* startup code */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __asm__ volatile (
                "lgr    %r2, %r15\n"          /* save stack pointer to %r2, as arg1 of _start_c */
@@ -147,7 +147,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                "xc     0(8,%r15), 0(%r15)\n" /* clear backchain                                */
                "brasl  %r14, _start_c\n"     /* transfer to c runtime                          */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 struct s390_mmap_arg_struct {
index 68609f42193485d015409b37af7ff91a53fc625d..65252c005a3080d61fee382efeeeb2285f0276ea 100644 (file)
  * 2) The deepest stack frame should be zero (the %rbp).
  *
  */
-void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
        __asm__ volatile (
                "xor  %ebp, %ebp\n"       /* zero the stack frame                            */
@@ -170,7 +170,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
                "call _start_c\n"         /* transfer to c runtime                           */
                "hlt\n"                   /* ensure it does not return                       */
        );
-       __builtin_unreachable();
+       __nolibc_entrypoint_epilogue();
 }
 
 #define NOLIBC_ARCH_HAS_MEMMOVE
index 1730d0454a55a66889ee0f9611b9382a9c6b10c8..3a1d5b8d4fb99595638fe3002a68939bff58d79e 100644 (file)
@@ -12,6 +12,9 @@
 #  define __nolibc_has_attribute(attr) 0
 #endif
 
+#define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
+#define __nolibc_entrypoint_epilogue() __builtin_unreachable()
+
 #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
 
 #define _NOLIBC_STACKPROTECTOR