diff --git a/libsel4utils/src/process.c b/libsel4utils/src/process.c index aafafd64..a6be66f7 100644 --- a/libsel4utils/src/process.c +++ b/libsel4utils/src/process.c @@ -271,9 +271,22 @@ int sel4utils_spawn_process_v(sel4utils_process_t *process, vka_t *vka, vspace_t int error; int envc = 0; char *envp[] = {}; + Elf_Phdr *phdr = process->elf_phdrs; uintptr_t initial_stack_pointer = (uintptr_t) process->thread.stack_top - sizeof(seL4_Word); + /* If PT_PHDR exists in the program headers, assign PT_NULL to it. + * This is because muslc libc searches for PT_PHDR and if found, + * it assumes it's part of the ELF image and relocates the entire + * subsequent program header segments according to PT_PHDR's base. This is + * wrong and will trigger mapping errors. + */ + for (int i = 0; i < process->num_elf_phdrs; i++, phdr++) { + if (phdr->p_type == PT_PHDR) { + phdr->p_type = PT_NULL; + } + } + /* Copy the elf headers */ uintptr_t at_phdr; error = sel4utils_stack_write(vspace, &process->vspace, vka, process->elf_phdrs,