From: Tulio A M Mendes Date: Thu, 12 Feb 2026 04:42:40 +0000 (-0300) Subject: feat: userspace ld.so stub — minimal dynamic linker placeholder, built and packed... X-Git-Url: https://projects.tadryanom.me/docs/static/gitweb.css?a=commitdiff_plain;h=a2bc26c12c0c9b6424df22b7079a1ebd56b8f541;p=AdrOS.git feat: userspace ld.so stub — minimal dynamic linker placeholder, built and packed into initrd as lib/ld.so --- diff --git a/.gitignore b/.gitignore index 359e9a7..d541280 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ build/ *.log *.elf *.a +*.so # ISO staging: keep config, ignore generated kernel binaries iso/boot/*.bin diff --git a/Makefile b/Makefile index 404e863..a12f42c 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ ifeq ($(ARCH),x86) LS_ELF := user/ls.elf MKDIR_ELF := user/mkdir.elf RM_ELF := user/rm.elf + LDSO_ELF := user/ld.so INITRD_IMG := initrd.img MKINITRD := tools/mkinitrd endif @@ -170,8 +171,11 @@ $(MKDIR_ELF): user/mkdir.c user/linker.ld $(RM_ELF): user/rm.c user/linker.ld @i686-elf-gcc -m32 -I include -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/linker.ld -o $(RM_ELF) user/rm.c user/errno.c -$(INITRD_IMG): $(MKINITRD) $(USER_ELF) $(ECHO_ELF) $(SH_ELF) $(CAT_ELF) $(LS_ELF) $(MKDIR_ELF) $(RM_ELF) - @./$(MKINITRD) $(INITRD_IMG) $(USER_ELF):bin/init.elf $(ECHO_ELF):bin/echo.elf $(SH_ELF):bin/sh $(CAT_ELF):bin/cat $(LS_ELF):bin/ls $(MKDIR_ELF):bin/mkdir $(RM_ELF):bin/rm +$(LDSO_ELF): user/ldso.c user/linker.ld + @i686-elf-gcc -m32 -I include -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/linker.ld -o $(LDSO_ELF) user/ldso.c + +$(INITRD_IMG): $(MKINITRD) $(USER_ELF) $(ECHO_ELF) $(SH_ELF) $(CAT_ELF) $(LS_ELF) $(MKDIR_ELF) $(RM_ELF) $(LDSO_ELF) + @./$(MKINITRD) $(INITRD_IMG) $(USER_ELF):bin/init.elf $(ECHO_ELF):bin/echo.elf $(SH_ELF):bin/sh $(CAT_ELF):bin/cat $(LS_ELF):bin/ls $(MKDIR_ELF):bin/mkdir $(RM_ELF):bin/rm $(LDSO_ELF):lib/ld.so run: iso @rm -f serial.log qemu.log diff --git a/user/ldso.c b/user/ldso.c new file mode 100644 index 0000000..7a22637 --- /dev/null +++ b/user/ldso.c @@ -0,0 +1,22 @@ +/* Minimal userspace dynamic linker stub (ld.so). + * Currently a no-op: receives control from the kernel ELF loader + * and immediately jumps to the real program entry point. + * + * The kernel places the program entry address at the top of the + * user stack (below argc) as an auxiliary value. + * + * Future work: parse PT_DYNAMIC, relocate GOT/PLT, resolve symbols. */ + +void _start(void) __attribute__((noreturn, section(".text.start"))); + +void _start(void) { + /* The kernel's ELF loader doesn't yet pass AT_ENTRY via auxv, + * so for now this stub simply halts. When the kernel is extended + * to pass the real entry point (e.g. via auxv or a register), + * this stub will jump there. + * + * Placeholder: infinite NOP loop (cannot hlt in ring 3). */ + for (;;) { + __asm__ volatile("nop"); + } +}