Closed rahatzamancse closed 3 years ago
Me too. Please fix @pritamzope
It's because the kernel is of 32 bit(i386) not 64 bit. The size of multiboot header is different on different architectures. so compile and links the kernel as 32 bit(i386) options. also we are using gcc for linking, use ld for linking. Here's the modified script contents.(Tested on Ubuntu_x86_64, WSL with gcc-5, 6, 7, 8):
as --32 boot.s -o boot.o
gcc -m32 -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
ld -m elf_i386 -T linker.ld kernel.o boot.o -o MyOS.bin -nostdlib
grub-file --is-x86-multiboot MyOS.bin
mkdir -p isodir/boot/grub cp MyOS.bin isodir/boot/MyOS.bin cp grub.cfg isodir/boot/grub/grub.cfg grub-mkrescue -o MyOS.iso isodir
qemu-system-x86_64 -cdrom MyOS.iso
According to the
run.sh
file inkernel_1
folder, when running this command:gcc -T linker.ld -o MyOS.bin -ffreestanding -O2 -nostdlib kernel.o boot.o -lgcc
I get the following error:/usr/bin/ld: boot.o: relocation R_X86_64_32 against '.multiboot' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: final link failed: nonrepresentable section on output collect2: error: ld returned 1 exit status