Skip to content

Instantly share code, notes, and snippets.

@user21944
Last active January 16, 2024 02:52
Show Gist options
  • Save user21944/e978482f7822f4bce8c543372ca6048d to your computer and use it in GitHub Desktop.
Save user21944/e978482f7822f4bce8c543372ca6048d to your computer and use it in GitHub Desktop.
small and efficient c startup code (crt0) and standard library, lightweight replacement for libc suitible for arch linux users around the world
#ifndef CRT_H_
#define CRT_H_
/*int main(const int argc, const char* const argv[]);*/
_Noreturn void main(void);
void* syscall3(void* arg1, void* arg2, void* arg3, int number);
#endif
.text
.global _start, syscall3
_start:
xorl %ebp, %ebp
/* popq %rdi
* movq %rsp, %rsi */
/* call main */
jmp main
/* movl %eax, %edi
* movl $60, %eax
* syscall */
syscall3:
movl %ecx, %eax
syscall
ret
@user21944
Copy link
Author

x86_64 sysv abi document says that rsp is guaranteed to be 16-byte aligned at program startup, so there is no need to manually align it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment