From 7faa974542cf8e6d39c1c89350a48f7f3b3f364f Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sat, 21 Oct 2017 17:13:40 +0100 Subject: [PATCH] Fixed linker and switched it to use clang directly instead of lld. --- linker.ld | 50 ++++++++++++++++++++++++-------------------------- makefile | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/linker.ld b/linker.ld index 32182c7..91ac91c 100644 --- a/linker.ld +++ b/linker.ld @@ -1,32 +1,30 @@ -OUTPUT_FORMAT(elf32-i386) -ENTRY (start) +/* http://wiki.osdev.org/Bare_Bones#Linking_the_Kernel */ +ENTRY(_start) -SECTIONS{ - . = 0x00100000; +SECTIONS +{ + . = 1M; - .text :{ - code = .; _code = .; __code = .; - *(.text) - *(.rodata) - } + .text BLOCK(4K) : ALIGN(4K) + { + *(.multiboot) + *(.text) + } - .rodata ALIGN (0x1000) : { - *(.rodata) - } + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } - .data ALIGN (0x1000) : { - data = .; _data = .; __data = .; - *(.data) - start_ctors = .; *(.ctors) end_ctors = .; - start_dtors = .; *(.dtors) end_dtors = .; - } + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } - .bss : { - sbss = .; - bss = .; _bss = .; __bss = .; - *(COMMON) - *(.bss) - ebss = .; - } - end = .; _end = .; __end = .; } diff --git a/makefile b/makefile index 8f10686..601d953 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ all: kernel kernel: bootloader - nim cc --cc:clang --clang.linkerexe=ld.lld --gc:none --deadCodeElim:on --cpu:i386 --os:standalone --passC:"-ffreestanding -nostdlib --target=i686-pc-none-elf -march=i686" --passL:"-m elf_i386 -T linker.ld boot.o" kernel.nim + nim cc --cc:clang --clang.linkerexe=clang --gc:none --deadCodeElim:on -d:StandaloneHeapSize=4096 --cpu:i386 --os:standalone --passC:"-ffreestanding -nostdlib --target=i686-pc-none-elf -march=i686" --passL:"-target i386 -nostdlib -T linker.ld boot.o" kernel.nim bootloader: nasm -felf32 boot.s -o boot.o