Skip to content

Commit

Permalink
changes to kernel build process
Browse files Browse the repository at this point in the history
- use a linker script while building kernel
- dump debug symbols in its own file
- strip kernel of debug symbols to reduce size
- add gdbinit to autoload commands
  • Loading branch information
viren-nadkarni committed Jun 16, 2016
1 parent aab0953 commit f452c04
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
file kernel/kernel.sym
target remote localhost:1234

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ bochs.out
# builds
*.img
*.bin
*.sym
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export CCFLAGS = -fno-builtin -m32 -Wall -nostartfiles -nostdlib -nostdinc -std=gnu99 -g -c -O0
export ASFLAGS = -f elf32
export LDFLAGS = -melf_i386 -Ttext 0x1000 --oformat binary # -T linker.ld
export LDFLAGS = -melf_i386 -Ttext 0x1000 --oformat elf32-i386 -T link.ld

export KERNEL_INCDIR = $(shell pwd)/kernel/include
export LIBC_INCDIR = $(shell pwd)/libc/include
Expand Down
4 changes: 3 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ entry.o: entry.asm
gcc $(CCFLAGS) -o $@ $< -I$(KERNEL_INCDIR) -I$(LIBC_INCDIR)

kernel.bin: entry.o kernel.o ${OBJ}
ld $(LDFLAGS) -o $@ $^ -L../build -lc
ld $(LDFLAGS) -o kernel.elf $^ -L../build -lc
objcopy --only-keep-debug kernel.elf kernel.sym
objcopy -O binary kernel.elf $@
cp $@ ../build

1 change: 1 addition & 0 deletions kernel/entry.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[bits 32]
[extern kmain]
_start:
call kmain
jmp $ ; this should happen when returning from kernel main
; shutdown?
Expand Down
35 changes: 4 additions & 31 deletions kernel/link.ld
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
/* Link.ld -- Linker script for the kernel - ensure everything goes in the */
/* Correct place. */
/* Original file taken from Bran's Kernel Development */
/* tutorials: http://www.osdever.net/bkerndev/index.php. */

ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}

.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}

.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}

end = .; _end = .; __end = .;
SECTIONS {
. = 0x1000;
.text : { * (.text); }
}

0 comments on commit f452c04

Please sign in to comment.