Linker runs but does not generate output
Posted: Mon Jan 23, 2023 8:36 pm
I've been sweating bullets today over the paging (which is still a mess, though that's beside the point), but along the way ended up with a different problem entirely: the linker invocation runs without any error messages given, but it doesn't produce the kernel.elf file. I only noticed this because changes I was making were having no effect on the kernel output - the existing copy of the kernel file was being re-used, until I deleted it from the obj/ and found the installer failing.
The error messages I am getting are:
The linker script is
while the Makefile is
What puzzles me most is the lack of any sort of error message from ld.
The error messages I am getting are:
Code: Select all
make
nasm -w+all -f bin -IVerbum/src/PC-x86/nasm/fat12 Verbum/src/PC-x86/nasm/fat12/verbum.asm -o obj/verbum.bin -l obj/verbum.lst
nasm -w+all -f bin -IVerbum/src/PC-x86/nasm/fat12 Verbum/src/PC-x86/nasm/fat12/stagetwo.asm -o obj/stagetwo.bin -l obj/stagetwo.lst
aux.asm:209: warning: uninitialized space declared in .text section: zeroing [-w+zeroing]
aux.asm:23: warning: uninitialized space declared in .text section: zeroing [-w+zeroing]
aux.asm:62: warning: uninitialized space declared in .text section: zeroing [-w+zeroing]
tables.asm:88: warning: uninitialized space declared in .text section: zeroing [-w+zeroing]
nasm -w+all -f elf32 src/kstart.asm -o obj/kstart.o -l obj/kstart.lst
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -I src/include -c src/terminal.c -o obj/terminal.o
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -I src/include -c src/mem.c -o obj/mem.o
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -I src/include -c src/paging.c -o obj/paging.o
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -mgeneral-regs-only -I src/include -c src/idt.c -o obj/idt.o
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -I src/include -c src/gdt.c -o obj/gdt.o
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -I src/include -c src/acpi.c -o obj/acpi.o
i686-elf-gcc -Wall -Werror -Wpedantic -std=c2x -ffreestanding -I src/include -c src/kernel.c -o obj/kernel.o
i686-elf-ld -T linker.ld
dd if=/dev/zero of=obj/boot.img count=1440 bs=1k
1440+0 records in
1440+0 records out
1474560 bytes (1.5 MB, 1.4 MiB) copied, 0.00553826 s, 266 MB/s
mkfs.msdos -F 12 -n "ORDO" obj/boot.img
mkfs.fat 4.2 (2021-01-31)
dd if=obj/verbum.bin of=obj/boot.img count=1 conv=notrunc
1+0 records in
1+0 records out
512 bytes copied, 0.000110209 s, 4.6 MB/s
mkdir -p temp
sudo mount obj/boot.img temp
[sudo] password for schol-r-lea:
sudo cp obj/stagetwo.bin temp/STAGETWO.SYS
sudo cp obj/kernel.elf temp/KERNEL.SYS
cp: cannot stat 'obj/kernel.elf': No such file or directory
make: *** [Makefile:35: install] Error 1
Code: Select all
/* The bootloader will look at this image and start execution at the symbol
designated at the entry point. */
ENTRY(kstart)
INPUT(
obj/kernel.o
obj/terminal.o
obj/mem.o
obj/idt.o
obj/gdt.o
obj/paging.o
obj/acpi.o
)
OUTPUT(kernel.elf)
OUTPUT_FORMAT(elf32-i386)
STARTUP(obj/kstart.o)
/* Tell where the various sections of the object files will be put in the final
kernel image. */
SECTIONS
{
/* Begin putting sections at the higher half. */
. = 0xC0000000;
/* the .text section. */
.text : ALIGN(4K)
{
*(.text)
}
/* Read-only data. */
.rodata : ALIGN(4K)
{
*(.rodata)
}
/* Read-write data (initialized) */
.data : ALIGN(4K)
{
*(.data)
}
/* Read-write data (uninitialized) and stack */
.bss : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
/* hardware tables */
. = 0xC0100000;
.tables :
{
tables_base = .;
}
.boot_data BLOCK(4K) : ALIGN (4K)
{
boot_data = .;
. = . + 4K;
}
.gdt BLOCK(64K) :
{
gdt = .;
. = . + 64K;
}
.tss BLOCK(4K) : ALIGN(4K)
{
default_tss = .;
. = . + 4K;
}
.idt BLOCK(4K) : ALIGN(4K)
{
idt = .;
. = . + 4K;
}
.paging BLOCK(4K) : ALIGN(4K)
{
page_directory = .;
. = . + 4K;
page_tables = .;
. = . + (1K * 4K);
}
/* set up the kernel stack */
. = 0xC1000000;
.stack :
{
kernel_stack_base = .;
kernel_stack_top = . + 16K;
}
}
Code: Select all
ASM = nasm -w+all
COPY = dd
FORMAT = mkfs.msdos -F 12 -n "ORDO"
REIMAGE=qemu-img
SYS_INSTALL = ~/Deployments/ms-sys-2.5.3/bin/ms-sys --fat12
BOOTPATH=Verbum/src/PC-x86/nasm/fat12
BOOT = verbum
STAGE_TWO = stagetwo
DISKTARGET = boot.img
DISKSIZE = 1440
CC=i686-elf-gcc
LD=i686-elf-ld
LINK_SCRIPT=linker.ld
CFLAGS=-Wall -Werror -Wpedantic -std=c2x -ffreestanding
C_SRC=src
C_INCLUDES=-I $(C_SRC)/include
OBJPATH=obj
KERNEL=kernel
KSTART=kstart
GDT=gdt
IDT=idt
TERMINAL=terminal
MEM=mem
PAGING=paging
ACPI=acpi
install: boot stage2 link
$(COPY) if=/dev/zero of=$(OBJPATH)/$(DISKTARGET) count=$(DISKSIZE) bs=1k
$(FORMAT) $(OBJPATH)/$(DISKTARGET)
$(COPY) if=$(OBJPATH)/$(BOOT).bin of=$(OBJPATH)/$(DISKTARGET) count=1 conv=notrunc
mkdir -p temp
sudo mount $(OBJPATH)/$(DISKTARGET) temp
sudo cp $(OBJPATH)/$(STAGE_TWO).bin temp/STAGETWO.SYS
sudo cp $(OBJPATH)/$(KERNEL).elf temp/KERNEL.SYS
sudo umount temp
rmdir temp
$(REIMAGE) convert -f raw -O qcow2 $(OBJPATH)/$(DISKTARGET) ordo.qcow2
link: kstart kernel terminal mem idt acpi paging gdt
$(LD) -T $(LINK_SCRIPT)
kernel: terminal paging mem idt gdt acpi
$(CC) $(CFLAGS) $(C_INCLUDES) -c $(C_SRC)/$(KERNEL).c -o $(OBJPATH)/$(KERNEL).o
acpi: terminal
$(CC) $(CFLAGS) $(C_INCLUDES) -c $(C_SRC)/$(ACPI).c -o $(OBJPATH)/$(ACPI).o
idt: terminal
$(CC) $(CFLAGS) -mgeneral-regs-only $(C_INCLUDES) -c $(C_SRC)/$(IDT).c -o $(OBJPATH)/$(IDT).o
gdt:
$(CC) $(CFLAGS) $(C_INCLUDES) -c $(C_SRC)/$(GDT).c -o $(OBJPATH)/$(GDT).o
paging: terminal mem
$(CC) $(CFLAGS) $(C_INCLUDES) -c $(C_SRC)/$(PAGING).c -o $(OBJPATH)/$(PAGING).o
mem: terminal
$(CC) $(CFLAGS) $(C_INCLUDES) -c $(C_SRC)/$(MEM).c -o $(OBJPATH)/$(MEM).o
terminal:
$(CC) $(CFLAGS) $(C_INCLUDES) -c $(C_SRC)/$(TERMINAL).c -o $(OBJPATH)/$(TERMINAL).o
kstart:
$(ASM) -f elf32 $(C_SRC)/$(KSTART).asm -o $(OBJPATH)/$(KSTART).o -l $(OBJPATH)/$(KSTART).lst
boot:
$(ASM) -f bin -I$(BOOTPATH) $(BOOTPATH)/$(BOOT).asm -o $(OBJPATH)/$(BOOT).bin -l $(OBJPATH)/$(BOOT).lst
stage2:
$(ASM) -f bin -I$(BOOTPATH) $(BOOTPATH)/$(STAGE_TWO).asm -o $(OBJPATH)/$(STAGE_TWO).bin -l $(OBJPATH)/$(STAGE_TWO).lst