ld: implement support for exposing ld functions to loaded executables

This commit is contained in:
2026-05-30 10:17:43 +01:00
parent ce52afe5b4
commit 08abe467ea
12 changed files with 425 additions and 59 deletions
+7 -3
View File
@@ -1,6 +1,6 @@
#include "elf.h"
#include <mango/log.h>
#include <magenta/log.h>
#include <stdint.h>
#include <stdio.h>
@@ -13,11 +13,13 @@ uintptr_t dl_runtime_resolve(struct elf_image *img, unsigned long sym_id)
= (elf_rela_t *)((virt_addr_t)img->e_base
+ img->e_rel_offset[ELF_RT_PLTREL]);
elf_rela_t *rela_sym = &rela[sym_id];
#if 0
kern_tracef(
"rela %u -> .dynsym %u, .got %u",
sym_id,
ELF64_R_SYM(rela_sym->r_info),
slot_id);
#endif
sym_id = ELF64_R_SYM(rela_sym->r_info);
/* the first three entries in the GOT are not symbols. */
slot_id += 3;
@@ -34,18 +36,20 @@ uintptr_t dl_runtime_resolve(struct elf_image *img, unsigned long sym_id)
= (virt_addr_t *)((virt_addr_t)img->e_base + img->e_got_plt);
const char *sym_name = (const char *)img->e_base + img->e_strtab
+ sym[sym_id].st_name;
#if 0
kern_tracef(
"%s: request for symbol %u: %s",
img->e_leaf.l_name,
sym_id,
sym_name);
#endif
#if 0
virt_addr_t sym_addr = elf_image_find_linked_symbol(img, sym_name);
#else
virt_addr_t sym_addr = find_global_symbol(sym_name);
#endif
kern_tracef("symbol %s = %zx", sym_name, sym_addr);
kern_tracef("slot %s = %zx", sym_name, &got[slot_id]);
// kern_logf("symbol %s = %zx", sym_name, sym_addr);
// kern_tracef("slot %s = %zx", sym_name, &got[slot_id]);
got[slot_id] = sym_addr;
return sym_addr;
}