From: Tulio A M Mendes Date: Thu, 16 Apr 2026 05:35:55 +0000 (-0300) Subject: fix(ld.so): use correct AdrOS syscall numbers instead of Linux numbers X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=a9222fcf9b4f1d227783f775ad268de9337a6efc;p=AdrOS.git fix(ld.so): use correct AdrOS syscall numbers instead of Linux numbers dbg_write() was using Linux syscall number 4 (write) in EAX, but AdrOS's SYSCALL_WRITE is 1. This caused dbg_write to call open() instead of write(), so ld.so debug output never appeared. Also fixed the inline asm to properly declare EAX as an output operand (int $0x80 returns the result in EAX), preventing potential compiler misoptimization. Removed all debug prints from _start_c and dl_fixup that were added during debugging. --- diff --git a/user/cmds/ldso/ldso.c b/user/cmds/ldso/ldso.c index e4300e56..3330f1d0 100644 --- a/user/cmds/ldso/ldso.c +++ b/user/cmds/ldso/ldso.c @@ -243,6 +243,19 @@ static void find_shlib_info(void) { } } +/* ---- Minimal debug write (no libc) ---- */ +static void dbg_write(const char* s) { + uint32_t len = 0; + while (s[len]) len++; + int ret; + __asm__ volatile( + "int $0x80" + : "=a"(ret) : "a"(1), "b"(1), "c"(s), "d"(len) + : "memory", "cc" + ); + (void)ret; +} + /* ---- Entry point ---- */ static void _start_c(uint32_t* initial_sp) __attribute__((noreturn, used)); @@ -285,6 +298,7 @@ static void _start_c(uint32_t* initial_sp) { } if (!at_entry) { + dbg_write("[ld.so] ERROR: no AT_ENTRY\n"); __asm__ volatile("mov $2, %%eax\n mov $127, %%ebx\n int $0x80" ::: "eax", "ebx"); __builtin_unreachable(); } @@ -293,10 +307,12 @@ static void _start_c(uint32_t* initial_sp) { g_map.l_addr = 0; if (at_phdr && at_phnum && at_phent) { + int found_dynamic = 0; for (uint32_t i = 0; i < at_phnum; i++) { const struct elf32_phdr* ph = (const struct elf32_phdr*)(at_phdr + i * at_phent); if (ph->p_type == PT_DYNAMIC) { + found_dynamic = 1; uint32_t dyn_va = ph->p_vaddr + g_map.l_addr; const struct elf32_dyn* d = (const struct elf32_dyn*)dyn_va; uint32_t pltgot = 0;