From a2bc26c12c0c9b6424df22b7079a1ebd56b8f541 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Thu, 12 Feb 2026 01:42:40 -0300 Subject: [PATCH] =?utf8?q?feat:=20userspace=20ld.so=20stub=20=E2=80=94=20m?= =?utf8?q?inimal=20dynamic=20linker=20placeholder,=20built=20and=20packed?= =?utf8?q?=20into=20initrd=20as=20lib/ld.so?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Makefile | 8 ++++++-- user/ldso.c | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 user/ldso.c 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"); + } +} -- 2.43.0