mirror of
https://github.com/torvalds/linux.git
synced 2025-04-12 16:47:42 +00:00
tools/nolibc: move entrypoint specifics to compiler.h
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>
This commit is contained in:
parent
02a62b551c
commit
ef32e9b6a3
@ -142,13 +142,13 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* startup code */
|
/* 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 (
|
__asm__ volatile (
|
||||||
"mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
|
"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 */
|
"and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
|
||||||
"bl _start_c\n" /* transfer to c runtime */
|
"bl _start_c\n" /* transfer to c runtime */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
#endif /* _NOLIBC_ARCH_AARCH64_H */
|
#endif /* _NOLIBC_ARCH_AARCH64_H */
|
||||||
|
@ -185,7 +185,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* startup code */
|
/* 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 (
|
__asm__ volatile (
|
||||||
"mov r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */
|
"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"
|
"mov sp, ip\n"
|
||||||
"bl _start_c\n" /* transfer to c runtime */
|
"bl _start_c\n" /* transfer to c runtime */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _NOLIBC_ARCH_ARM_H */
|
#endif /* _NOLIBC_ARCH_ARM_H */
|
||||||
|
@ -162,7 +162,7 @@
|
|||||||
* 2) The deepest stack frame should be set to zero
|
* 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 (
|
__asm__ volatile (
|
||||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
"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 */
|
"call _start_c\n" /* transfer to c runtime */
|
||||||
"hlt\n" /* ensure it does not return */
|
"hlt\n" /* ensure it does not return */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _NOLIBC_ARCH_I386_H */
|
#endif /* _NOLIBC_ARCH_I386_H */
|
||||||
|
@ -149,14 +149,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* startup code */
|
/* 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 (
|
__asm__ volatile (
|
||||||
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
|
"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 */
|
LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned */
|
||||||
"bl _start_c\n" /* transfer to c runtime */
|
"bl _start_c\n" /* transfer to c runtime */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _NOLIBC_ARCH_LOONGARCH_H */
|
#endif /* _NOLIBC_ARCH_LOONGARCH_H */
|
||||||
|
@ -179,7 +179,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* startup code, note that it's called __start on MIPS */
|
/* 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 (
|
__asm__ volatile (
|
||||||
".set push\n"
|
".set push\n"
|
||||||
@ -200,7 +200,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
|||||||
" nop\n" /* delayed slot */
|
" nop\n" /* delayed slot */
|
||||||
".set pop\n"
|
".set pop\n"
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _NOLIBC_ARCH_MIPS_H */
|
#endif /* _NOLIBC_ARCH_MIPS_H */
|
||||||
|
@ -184,7 +184,7 @@
|
|||||||
#endif /* !__powerpc64__ */
|
#endif /* !__powerpc64__ */
|
||||||
|
|
||||||
/* startup code */
|
/* 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__
|
#ifdef __powerpc64__
|
||||||
#if _CALL_ELF == 2
|
#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 */
|
"bl _start_c\n" /* transfer to c runtime */
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _NOLIBC_ARCH_POWERPC_H */
|
#endif /* _NOLIBC_ARCH_POWERPC_H */
|
||||||
|
@ -140,7 +140,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* startup code */
|
/* 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 (
|
__asm__ volatile (
|
||||||
".option push\n"
|
".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 */
|
"andi sp, a0, -16\n" /* sp must be 16-byte aligned */
|
||||||
"call _start_c\n" /* transfer to c runtime */
|
"call _start_c\n" /* transfer to c runtime */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _NOLIBC_ARCH_RISCV_H */
|
#endif /* _NOLIBC_ARCH_RISCV_H */
|
||||||
|
@ -139,7 +139,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
/* startup code */
|
/* 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 (
|
__asm__ volatile (
|
||||||
"lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
|
"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 */
|
"xc 0(8,%r15), 0(%r15)\n" /* clear backchain */
|
||||||
"brasl %r14, _start_c\n" /* transfer to c runtime */
|
"brasl %r14, _start_c\n" /* transfer to c runtime */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct s390_mmap_arg_struct {
|
struct s390_mmap_arg_struct {
|
||||||
|
@ -161,7 +161,7 @@
|
|||||||
* 2) The deepest stack frame should be zero (the %rbp).
|
* 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 (
|
__asm__ volatile (
|
||||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
"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 */
|
"call _start_c\n" /* transfer to c runtime */
|
||||||
"hlt\n" /* ensure it does not return */
|
"hlt\n" /* ensure it does not return */
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__nolibc_entrypoint_epilogue();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NOLIBC_ARCH_HAS_MEMMOVE
|
#define NOLIBC_ARCH_HAS_MEMMOVE
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
# define __nolibc_has_attribute(attr) 0
|
# define __nolibc_has_attribute(attr) 0
|
||||||
#endif
|
#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__)
|
#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
|
||||||
|
|
||||||
#define _NOLIBC_STACKPROTECTOR
|
#define _NOLIBC_STACKPROTECTOR
|
||||||
|
Loading…
x
Reference in New Issue
Block a user