mirror of https://github.com/flysand7/ciabatta.git
Fix build scripts, align some code, make a workable test
This commit is contained in:
parent
b5e4824060
commit
f2be833f82
1
build.sh
1
build.sh
|
@ -10,6 +10,7 @@ clang -fPIC -nostdlib -I "include" -g "src/ciabatta.c" -c -o "bin/ciabatta.o"
|
||||||
rm "$LIB_FILE" 2> /dev/null
|
rm "$LIB_FILE" 2> /dev/null
|
||||||
|
|
||||||
if [ "$1" != "-shared" ]; then
|
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"
|
llvm-ar -q "lib/ciabatta.a" "bin/crt_ctors.o" "bin/crt_entry.o" "bin/ciabatta.o"
|
||||||
else
|
else
|
||||||
clang -fPIC -nostdlib -shared -o "lib/ciabatta.so" "bin/ciabatta.o"
|
clang -fPIC -nostdlib -shared -o "lib/ciabatta.so" "bin/ciabatta.o"
|
||||||
|
|
|
@ -24,7 +24,7 @@ _start:
|
||||||
pop rsi
|
pop rsi
|
||||||
mov rdx, qword [rsp]
|
mov rdx, qword [rsp]
|
||||||
;; Align stack to 16, push junk and stack ptr
|
;; Align stack to 16, push junk and stack ptr
|
||||||
and rsi, ~0xf
|
and rsp, ~0xf
|
||||||
push rax
|
push rax
|
||||||
push rsp
|
push rsp
|
||||||
;; Push fini and init sections
|
;; Push fini and init sections
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
|
|
||||||
|
|
||||||
|
int __stack_chk_fial() {
|
||||||
|
// TODO: implement proper stack protector support
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void __libc_start_main(
|
void __libc_start_main(
|
||||||
int (*main)(int, char**, char**),
|
int (*main)(int, char**, char**),
|
||||||
int argc, char **argv,
|
int argc, char **argv,
|
||||||
|
@ -7,5 +13,7 @@ void __libc_start_main(
|
||||||
void (*rtld_fini)(void),
|
void (*rtld_fini)(void),
|
||||||
void *stack_end
|
void *stack_end
|
||||||
) {
|
) {
|
||||||
|
static char string[] = "Hello, world!\n";
|
||||||
|
syscall_write(STDOUT_FILENO, string, sizeof string);
|
||||||
syscall_exit(0);
|
syscall_exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
|
|
||||||
#if os_is_linux()
|
#if os_is_linux()
|
||||||
|
|
||||||
|
#define STDIN_FILENO 0
|
||||||
|
#define STDOUT_FILENO 1
|
||||||
|
#define STDERR_FILENO 2
|
||||||
|
|
||||||
#define SYS_read 0
|
#define SYS_read 0
|
||||||
#define SYS_write 1
|
#define SYS_write 1
|
||||||
#define SYS_open 2
|
#define SYS_open 2
|
||||||
|
|
Loading…
Reference in New Issue