Skip to content

Commit 502f131

Browse files
committed
resolved the undefined reference issues by improving the build system's file discovery
1. Fix linker.ld - Kernel Symbols : Added the missing kernel_start = .; symbol at the beginning of the SECTIONS block (at 1MB). This resolves the undefined reference to kernel_start error in kernel.c . - Layout Integrity : Verified the standard 32-bit ELF layout with the .multiboot section correctly placed at the start of the .text block for GRUB compatibility. 2. Robust File Discovery in Makefile - Find Command : Replaced the limited $(wildcard ...) pattern with $(shell find $(SRC_DIR) -name "*.c") and $(shell find $(SRC_DIR) -name "*.s") . - Deep Directory Support : The previous wildcard only searched up to 3 levels deep, which caused it to miss critical files like src/arch/pit.c (providing timer_get_ticks ), src/arch/gdt.c (providing gdt_init ), and src/cpu/isr.c (providing isr_init and register_interrupt_handler ). - Object Mapping : This change ensures that every source file in the repository, regardless of depth, is correctly compiled into the build/ directory and linked into kernel.bin . 3. Warning Suppression - Noexecstack : Maintained the -Wl,-z,noexecstack flag in LDFLAGS to suppress the deprecated executable stack warning and improve security.
1 parent e305cf8 commit 502f131

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ BUILD_DIR := build
1212
MODEL_BLOB := $(firstword $(wildcard assets/smollm-135m.gguf) $(wildcard assets/SmolLM2-135M-Instruct-Q4_K_M.gguf))
1313
MODEL_OBJ := $(BUILD_DIR)/model.o
1414

15-
ASM_SRCS := $(wildcard $(SRC_DIR)/*.s $(SRC_DIR)/*/*.s $(SRC_DIR)/*/*/*.s)
16-
C_SRCS := $(filter-out $(SRC_DIR)/drivers/vga.c, $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*/*.c $(SRC_DIR)/*/*/*.c))
15+
ASM_SRCS := $(shell find $(SRC_DIR) -name "*.s")
16+
C_SRCS := $(filter-out $(SRC_DIR)/drivers/vga.c, $(shell find $(SRC_DIR) -name "*.c"))
1717

1818
ASM_OBJS := $(patsubst $(SRC_DIR)/%.s,$(BUILD_DIR)/%.o,$(ASM_SRCS))
1919
C_OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(C_SRCS))

linker.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ENTRY(_start)
33
SECTIONS
44
{
55
. = 1M;
6+
kernel_start = .;
67

78
.text BLOCK(4K) : ALIGN(4K)
89
{

0 commit comments

Comments
 (0)