]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: userspace ld.so stub — minimal dynamic linker placeholder, built and packed...
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 04:42:40 +0000 (01:42 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:44:41 +0000 (23:44 -0300)
.gitignore
Makefile
user/ldso.c [new file with mode: 0644]

index 359e9a7cba04574b3a019982cf8f887423022aa5..d541280a5b39d4bb5d6dc2464bfee4fa0dd6bdd3 100644 (file)
@@ -7,6 +7,7 @@ build/
 *.log
 *.elf
 *.a
+*.so
 
 # ISO staging: keep config, ignore generated kernel binaries
 iso/boot/*.bin
index 404e8630b1e9c2fb4530f4b2b48e67242924f40a..a12f42c13324dd7b260e5cfee79ee19179e425fc 100644 (file)
--- 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 (file)
index 0000000..7a22637
--- /dev/null
@@ -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");
+    }
+}