elf: support loading PIE executables

This commit is contained in:
Qwinci
2025-01-13 16:15:58 +02:00
parent ae2f69d3b8
commit 4e98bcf99d
+5 -1
View File
@@ -153,6 +153,10 @@ int elf_load(vnode_t *vnode, void *base, void **entry, char **interpreter, auxv6
if (headerok(&header) == false)
return ENOEXEC;
if (!base && header.type == ELF_SHARED) {
base = (void *)0x400000;
}
auxv64->null.type = AT_NULL;
auxv64->phdr.type = AT_PHDR;
auxv64->phnum.type = AT_PHNUM;
@@ -161,7 +165,7 @@ int elf_load(vnode_t *vnode, void *base, void **entry, char **interpreter, auxv6
auxv64->phnum.val = header.phcount;
auxv64->phent.val = header.phsize;
auxv64->entry.val = header.entry;
auxv64->entry.val = header.entry + (uintptr_t)base;
*entry = (void *)(header.entry + (uintptr_t)base);
__assert(header.phsize == sizeof(elfph64_t));