From 9759c36d7064623bc6fc8ac630b20668d4bfde7c Mon Sep 17 00:00:00 2001 From: Sivasankaran K B Date: Tue, 14 Feb 2023 15:56:08 +0530 Subject: [PATCH] Update linux build script to run on modern tools --- extras/BUILD.md | 21 +++++++++++++++++++-- extras/linux-build.sh | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/extras/BUILD.md b/extras/BUILD.md index 0265d6f..aa2fd73 100644 --- a/extras/BUILD.md +++ b/extras/BUILD.md @@ -7,8 +7,8 @@ These were removed from the old sources as they no longer require to be built. Those sources were kept only for historic reasons. These files were re-created. There were no build scripts for Linux distros -back then. A simple translation to linux commands has been done. -Copy the scripts to the outermost directory before running. +back then. The included Linux script has been tested on very modern build +tools. Copy the scripts to the outermost directory before running. v0.1.0 @@ -51,3 +51,20 @@ v0.1.0 the definition from `ports.c` to `proto.h`. Place it below the `io_wait()` declaration there. +- \[07\] (Fix included in Linux build script) + + Modern x86-64 tools have to be instructed to produce 32bit code explicitly. + The `-m32` GCC flag and i386 ELF emulation in LD with `-melf_i386` seems + to do the trick as of now. + +- \[08\] (Fix included in Linux build script) + + Modern Linux builds of GCC produce position independent executables (PIEs) by + default. The kernel is always loaded to a fixed address. PIE generation is + disabled with the `-fno-pie` switch. + +- \[09\] (Fix included in Linux build script) + + A stack smash protector added by GCC requires handling from within the kernel. + This was never implemented in the original kernel code. This feature is + disabled with the `-fno-stack-protector` flag. \ No newline at end of file diff --git a/extras/linux-build.sh b/extras/linux-build.sh index e1ace8d..cca39fc 100644 --- a/extras/linux-build.sh +++ b/extras/linux-build.sh @@ -3,7 +3,8 @@ clear # GNU/Linux GCC Build Script for Blaze OS v0.1.0 -CFLAGS="-c -nostdinc -nostdlib -ffreestanding -march=i386 -fleading-underscore" +CFLAGS="-c -nostdinc -nostdlib -ffreestanding -march=i386 -fleading-underscore \ +-fno-pie -fno-stack-protector -m32" CFILES="kernel irq isr itext memmgr pic ports ps2" CFILECOUNT=$(echo "$CFILES" | wc -w) SRCCOUNT=$(($CFILECOUNT + 1)) @@ -32,7 +33,7 @@ for CSOURCE in ${CFILES}; do echo "4 of 6 Create kernel binary" -ld obj/idt.o obj/libk.a -T linker.ld -o obj/ldkern.o +ld -melf_i386 obj/idt.o obj/libk.a -T linker.ld -o obj/ldkern.o objcopy -R .note -R .comment -S -g -O binary obj/ldkern.o bin/kernel.bin echo "5 of 6 Create boot disk image"