]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix(ld.so): use correct AdrOS syscall numbers instead of Linux numbers
authorTulio A M Mendes <[email protected]>
Thu, 16 Apr 2026 05:35:55 +0000 (02:35 -0300)
committerTulio A M Mendes <[email protected]>
Thu, 16 Apr 2026 05:35:55 +0000 (02:35 -0300)
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.

user/cmds/ldso/ldso.c

index e4300e560fab00c63c82d821ab3ebc3a35abc756..3330f1d0ac98614eaa01f55dccda49312f14ddb6 100644 (file)
@@ -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;