diff --git a/kernel/GNUmakefile b/kernel/GNUmakefile index bd31692..3cb3e72 100644 --- a/kernel/GNUmakefile +++ b/kernel/GNUmakefile @@ -50,8 +50,7 @@ override CFLAGS += \ -fno-stack-protector \ -fno-stack-check \ -fno-lto \ - -fno-PIE \ - -fno-PIC \ + -fPIE \ -m64 \ -march=x86-64 \ -mabi=sysv \ @@ -59,8 +58,7 @@ override CFLAGS += \ -mno-mmx \ -mno-sse \ -mno-sse2 \ - -mno-red-zone \ - -mcmodel=kernel + -mno-red-zone # Internal C preprocessor flags that should not be changed by the user. override CPPFLAGS := \ @@ -71,17 +69,15 @@ override CPPFLAGS := \ # Internal linker flags that should not be changed by the user. override LDFLAGS += \ + -m elf_x86_64 \ -nostdlib \ -static \ - -m elf_x86_64 \ + -pie \ + --no-dynamic-linker \ + -z text \ -z max-page-size=0x1000 \ -T linker.ld -# Check if the linker supports -no-pie and enable it if it does. -ifeq ($(shell $(LD) --help 2>&1 | grep 'no-pie' >/dev/null 2>&1; echo $$?),0) - override LDFLAGS += -no-pie -endif - # Internal nasm flags that should not be changed by the user. override NASMFLAGS += \ -Wall \ diff --git a/kernel/linker.ld b/kernel/linker.ld index 529a4dd..cb85308 100644 --- a/kernel/linker.ld +++ b/kernel/linker.ld @@ -12,6 +12,7 @@ PHDRS text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */ rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */ data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */ + dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; /* Dynamic PHDR for relocations */ } SECTIONS @@ -40,6 +41,11 @@ SECTIONS *(.data .data.*) } :data + /* Dynamic section for relocations, both in its own PHDR and inside data PHDR */ + .dynamic : { + *(.dynamic) + } :data :dynamic + /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ /* unnecessary zeros will be written to the binary. */ /* If you need, for example, .init_array and .fini_array, those should be placed */ diff --git a/limine.cfg b/limine.cfg index 4057f86..7bfc3e6 100644 --- a/limine.cfg +++ b/limine.cfg @@ -2,9 +2,18 @@ TIMEOUT=3 # The entry name that will be displayed in the boot menu. -:Limine Barebones +:Limine Barebones (KASLR off) # We use the Limine boot protocol. PROTOCOL=limine + # Disable KASLR (it is enabled by default for relocatable kernels) + KASLR=no + # Path to the kernel to boot. boot:/// represents the partition on which limine.cfg is located. KERNEL_PATH=boot:///kernel.elf + +# Same thing, but with KASLR. +:Limine Barebones (KASLR on) + PROTOCOL=limine + + KERNEL_PATH=boot:///kernel.elf