Fix build scripts, align some code, make a workable test

This commit is contained in:
flysand7 2023-07-23 02:23:39 +11:00
parent b5e4824060
commit f2be833f82
4 changed files with 74 additions and 61 deletions

View File

@ -10,6 +10,7 @@ clang -fPIC -nostdlib -I "include" -g "src/ciabatta.c" -c -o "bin/ciabatta.o"
rm "$LIB_FILE" 2> /dev/null
if [ "$1" != "-shared" ]; then
[ -f "lib/ciabatta.a" ] && rm "lib/ciabatta.a"
llvm-ar -q "lib/ciabatta.a" "bin/crt_ctors.o" "bin/crt_entry.o" "bin/ciabatta.o"
else
clang -fPIC -nostdlib -shared -o "lib/ciabatta.so" "bin/ciabatta.o"

View File

@ -24,7 +24,7 @@ _start:
pop rsi
mov rdx, qword [rsp]
;; Align stack to 16, push junk and stack ptr
and rsi, ~0xf
and rsp, ~0xf
push rax
push rsp
;; Push fini and init sections

View File

@ -1,4 +1,10 @@
int __stack_chk_fial() {
// TODO: implement proper stack protector support
return 0;
}
void __libc_start_main(
int (*main)(int, char**, char**),
int argc, char **argv,
@ -7,5 +13,7 @@ void __libc_start_main(
void (*rtld_fini)(void),
void *stack_end
) {
static char string[] = "Hello, world!\n";
syscall_write(STDOUT_FILENO, string, sizeof string);
syscall_exit(0);
}

View File

@ -1,6 +1,10 @@
#if os_is_linux()
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#define SYS_read 0
#define SYS_write 1
#define SYS_open 2