summaryrefslogtreecommitdiff
path: root/kc
diff options
context:
space:
mode:
Diffstat (limited to 'kc')
-rw-r--r--kc/boot/Makefile3
-rw-r--r--kc/core/Makefile2
-rw-r--r--kc/defaults.mk8
-rw-r--r--kc/dynamic_x86_64.c13
-rw-r--r--kc/entry_x86_64.S8
-rw-r--r--kc/kc.ld2
6 files changed, 26 insertions, 10 deletions
diff --git a/kc/boot/Makefile b/kc/boot/Makefile
index 297b6df..b90f183 100644
--- a/kc/boot/Makefile
+++ b/kc/boot/Makefile
@@ -8,6 +8,9 @@ TARGET := efi.os
.DEFAULT: $(TARGET)
CPPFLAGS += -I../../api -I ../api -I../../lib
+
+CFLAGS += -fshort-wchar
+
OBJS := entry_x86_64.o reloc_x86_64.o dynamic_x86_64.o \
kc_main.o elf64.o memcmp.o memcpy.o \
memmove.o memset.o loader_paging.o
diff --git a/kc/core/Makefile b/kc/core/Makefile
index 4d373cd..394b2dc 100644
--- a/kc/core/Makefile
+++ b/kc/core/Makefile
@@ -19,7 +19,7 @@ IOBJS :=
# __attribute__((interrupt)) requires -mgeneral-regs-only
$(GOBJS): CFLAGS += -mgeneral-regs-only
-$(GOBJS): CFLAGS += -mcmodel=small -fPIC
+$(GOBJS): CFLAGS += -mcmodel=small
OBJS := $(SOBJS) $(GOBJS) $(IOBJS)
DEPS := $(patsubst %.o,%.d,$(OBJS))
diff --git a/kc/defaults.mk b/kc/defaults.mk
index 0b6c4ba..ec6dfd3 100644
--- a/kc/defaults.mk
+++ b/kc/defaults.mk
@@ -1,7 +1,9 @@
-LIBDIRS += -L$(dir $(shell $(CC) -print-libgcc-file-name))
LDSCRIPT := ../kc.ld
+
+CFLAGS += -fPIC -fvisibility=hidden -mgeneral-regs-only
+
LDFLAGS += -z max-page-size=4096 --export-dynamic -pic \
- -z separate-code -pie -Bsymbolic -shared
-LOADLIBES := -lgcc
+ -z separate-code -pie -Bsymbolic -shared \
+ -z execstack -g
diff --git a/kc/dynamic_x86_64.c b/kc/dynamic_x86_64.c
index 6b7abd7..a573283 100644
--- a/kc/dynamic_x86_64.c
+++ b/kc/dynamic_x86_64.c
@@ -9,10 +9,10 @@ void kc_dynamic_init(void *base, Elf64_Dyn *dyn)
size_t entsize;
};
- struct rela reladyn = {NULL,};
- struct rela relaplt = {NULL,};
+ struct rela reladyn = {NULL, 0, 0};
+ struct rela relaplt = {NULL, 0, 0};
- Elf64_Addr *gotplt;
+ Elf64_Addr *gotplt = NULL;
while (dyn && dyn->d_tag != DT_NULL)
{
@@ -46,8 +46,11 @@ void kc_dynamic_init(void *base, Elf64_Dyn *dyn)
// peform relocations
//
- gotplt[1] = (uintptr_t)NULL;
- gotplt[2] = (uintptr_t)kc_resolve_symbol;
+ if (gotplt)
+ {
+ gotplt[1] = (uintptr_t)NULL;
+ gotplt[2] = (uintptr_t)kc_resolve_symbol;
+ }
kc_reloc(base, relaplt.entries, relaplt.size, relaplt.entsize);
kc_reloc(base, reladyn.entries, reladyn.size, reladyn.entsize);
}
diff --git a/kc/entry_x86_64.S b/kc/entry_x86_64.S
index 8431044..c426335 100644
--- a/kc/entry_x86_64.S
+++ b/kc/entry_x86_64.S
@@ -6,14 +6,22 @@
.global kc_entry
.type kc_entry, @function
kc_entry:
+ push %rbp
push %rdi
push %rsi
+ mov %rsp, %rbp
+ and $-0x10, %rsp
lea kc_image_base(%rip), %rdi
lea _DYNAMIC(%rip), %rsi
call kc_dynamic_init
+ mov %rbp, %rsp
pop %rsi
pop %rdi
+ mov %rsp, %rbp
+ and $-0x10, %rsp
call kc_main
+ mov %rbp, %rsp
+ pop %rbp
ret
.size kc_entry, . - kc_entry
diff --git a/kc/kc.ld b/kc/kc.ld
index dbce342..97d6a2a 100644
--- a/kc/kc.ld
+++ b/kc/kc.ld
@@ -4,7 +4,7 @@ SECTIONS
{
PROVIDE_HIDDEN(kc_image_base = .);
- . = sizeof_headers;
+ . = SIZEOF_HEADERS;
.rela.plt :
{