summaryrefslogtreecommitdiff
path: root/kjarna_runtime
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2024-02-24 15:18:40 +0000
committerAda Christine <adachristine18@gmail.com>2024-02-24 15:18:40 +0000
commit0f3866a4dad84860e135855766c77e5a82737686 (patch)
tree97e7bac72928ca6affc362577214646f942ad4d7 /kjarna_runtime
parenta61b9d1c9ee85ec08ff3b8a61e80dc33e71f3472 (diff)
bad reloc code silly me
Diffstat (limited to 'kjarna_runtime')
-rw-r--r--kjarna_runtime/Makefile3
-rw-r--r--kjarna_runtime/dynamic_x86_64.c4
-rw-r--r--kjarna_runtime/main.c3
-rw-r--r--kjarna_runtime/start_x86_64.S54
4 files changed, 33 insertions, 31 deletions
diff --git a/kjarna_runtime/Makefile b/kjarna_runtime/Makefile
index caffc79..03ac8b0 100644
--- a/kjarna_runtime/Makefile
+++ b/kjarna_runtime/Makefile
@@ -16,7 +16,8 @@ CFLAGS += -fPIC -fvisibility=hidden -mgeneral-regs-only
LDSCRIPT := kc.ld
CRT_OBJS := start_x86_64.o dynamic_x86_64.o elf64.o
-LIB_OBJS := kjarna.o memcmp.o memcpy.o memmove.o memset.o string.o
+LIB_OBJS := kjarna.o memcmp.o memcpy.o memmove.o memset.o string.o \
+ stdio.o
APP_OBJS := main.o
OBJS := $(CRT_OBJS) $(LIB_OBJS) $(APP_OBJS)
diff --git a/kjarna_runtime/dynamic_x86_64.c b/kjarna_runtime/dynamic_x86_64.c
index 3d85582..02538ec 100644
--- a/kjarna_runtime/dynamic_x86_64.c
+++ b/kjarna_runtime/dynamic_x86_64.c
@@ -129,9 +129,9 @@ static void do_rela(char *base, Elf64_Rela *rela)
void kc_dynamic_reloc(char *base, struct elf64_relatab *rela)
{
- // perform the actual relocation
+ size_t entries = rela->size / rela->entsize;
- for (size_t i = 0; rela->entries && (i < rela->size); i += rela->entsize)
+ for (size_t i = 0; rela->entries && (i < entries); i++)
{
do_rela(base, &rela->entries[i]);
}
diff --git a/kjarna_runtime/main.c b/kjarna_runtime/main.c
index 248958b..dc00f4a 100644
--- a/kjarna_runtime/main.c
+++ b/kjarna_runtime/main.c
@@ -1,11 +1,12 @@
#include <unistd.h>
+#include <stdio.h>
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
- write(1, "hello, runtime world!\r\n", -1);
+ fputs("hello, runtime world!\n", stdout);
while (1);
diff --git a/kjarna_runtime/start_x86_64.S b/kjarna_runtime/start_x86_64.S
index 1db92a4..19db34f 100644
--- a/kjarna_runtime/start_x86_64.S
+++ b/kjarna_runtime/start_x86_64.S
@@ -21,7 +21,7 @@ _start:
pop %rdi
mov %rsp, %rbp
and $-0x10, %rsp
- call kjarna_entry
+ call kjarna_entry
mov %rbp, %rsp
pop %rbp
ret
@@ -33,31 +33,31 @@ _start:
.global _rtld_link
.type _rtld_link, @function
_rtld_link:
- push %rbp
- mov %rsp, %rbp
- push %r9
- push %r8
- push %rcx
- push %rdx
- push %rsi
- push %rdi
- mov 8(%rbp), %rdi
- mov 16(%rbp), %rsi
- push %rbp
- mov %rsp, %rbp
- and $-0x10, %rsp
- call kc_dynamic_link
- mov %rbp, %rsp
- pop %rbp
- pop %rdi
- pop %rsi
- pop %rdx
- pop %rcx
- pop %r8
- pop %r9
- mov %rbp, %rsp
- pop %rbp
- add $0x10, %rsp
- jmp *(%rax)
+ push %rbp
+ mov %rsp, %rbp
+ push %r9
+ push %r8
+ push %rcx
+ push %rdx
+ push %rsi
+ push %rdi
+ mov 8(%rbp), %rdi
+ mov 16(%rbp), %rsi
+ push %rbp
+ mov %rsp, %rbp
+ and $-0x10, %rsp
+ call kc_dynamic_link
+ mov %rbp, %rsp
+ pop %rbp
+ pop %rdi
+ pop %rsi
+ pop %rdx
+ pop %rcx
+ pop %r8
+ pop %r9
+ mov %rbp, %rsp
+ pop %rbp
+ add $0x10, %rsp
+ jmp *(%rax)
.size _rtld_link, . - _rtld_link