mirror of
https://github.com/torvalds/linux.git
synced 2024-10-23 05:30:55 +00:00
tools/nolibc: x86_64: shrink _start with _start_c
move most of the _start operations to _start_c(), include the stackprotector initialization. Signed-off-by: Zhangjin Wu <falcon@tinylab.org> Signed-off-by: Willy Tarreau <w@1wt.eu>
This commit is contained in:
parent
2ab446336b
commit
539287d751
|
@ -8,6 +8,7 @@
|
||||||
#define _NOLIBC_ARCH_X86_64_H
|
#define _NOLIBC_ARCH_X86_64_H
|
||||||
|
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
|
#include "crt.h"
|
||||||
|
|
||||||
/* Syscalls for x86_64 :
|
/* Syscalls for x86_64 :
|
||||||
* - registers are 64-bit
|
* - registers are 64-bit
|
||||||
|
@ -153,9 +154,6 @@
|
||||||
_ret; \
|
_ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
char **environ __attribute__((weak));
|
|
||||||
const unsigned long *_auxv __attribute__((weak));
|
|
||||||
|
|
||||||
/* startup code */
|
/* startup code */
|
||||||
/*
|
/*
|
||||||
* x86-64 System V ABI mandates:
|
* x86-64 System V ABI mandates:
|
||||||
|
@ -166,26 +164,11 @@ const unsigned long *_auxv __attribute__((weak));
|
||||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||||
{
|
{
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
#ifdef _NOLIBC_STACKPROTECTOR
|
"xor %ebp, %ebp\n" /* zero the stack frame */
|
||||||
"call __stack_chk_init\n" /* initialize stack protector */
|
"mov %rsp, %rdi\n" /* save stack pointer to %rdi, as arg1 of _start_c */
|
||||||
#endif
|
"and $-16, %rsp\n" /* %rsp must be 16-byte aligned before call */
|
||||||
"pop %rdi\n" /* argc (first arg, %rdi) */
|
"call _start_c\n" /* transfer to c runtime */
|
||||||
"mov %rsp, %rsi\n" /* argv[] (second arg, %rsi) */
|
"hlt\n" /* ensure it does not return */
|
||||||
"lea 8(%rsi,%rdi,8),%rdx\n" /* then a NULL then envp (third arg, %rdx) */
|
|
||||||
"mov %rdx, environ\n" /* save environ */
|
|
||||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
|
||||||
"mov %rdx, %rax\n" /* search for auxv (follows NULL after last env) */
|
|
||||||
"0:\n"
|
|
||||||
"add $8, %rax\n" /* search for auxv using rax, it follows the */
|
|
||||||
"cmp -8(%rax), %rbp\n" /* ... NULL after last env (rbp is zero here) */
|
|
||||||
"jnz 0b\n"
|
|
||||||
"mov %rax, _auxv\n" /* save it into _auxv */
|
|
||||||
"and $-16, %rsp\n" /* x86 ABI : esp must be 16-byte aligned before call */
|
|
||||||
"call main\n" /* main() returns the status code, we'll exit with it. */
|
|
||||||
"mov %eax, %edi\n" /* retrieve exit code (32 bit) */
|
|
||||||
"mov $60, %eax\n" /* NR_exit == 60 */
|
|
||||||
"syscall\n" /* really exit */
|
|
||||||
"hlt\n" /* ensure it does not return */
|
|
||||||
);
|
);
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user