From acbd183b72865d372dc94c32a9bdc07dd0e51906 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 5 Dec 2024 15:16:30 +0100 Subject: [PATCH] llext: fix .bss on heap With writable LLEXT but without pre-assigned section addresses .bss section offset in its ELF header will not match .bss eventual location as it's allocated on the heap. Use llext_loaded_sect_ptr() to get a correct address in both cases. Signed-off-by: Guennadi Liakhovetski --- arch/xtensa/core/elf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/core/elf.c b/arch/xtensa/core/elf.c index 0ce9885eed6..04dac478215 100644 --- a/arch/xtensa/core/elf.c +++ b/arch/xtensa/core/elf.c @@ -124,9 +124,11 @@ void arch_elf_relocate_local(struct llext_loader *ldr, struct llext *ext, const if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) { elf_shdr_t *shdr = llext_peek(ldr, ldr->hdr.e_shoff + sym->st_shndx * ldr->hdr.e_shentsize); + + /* shdr->sh_addr is NULL when not built for a specific address */ sh_addr = shdr->sh_addr && (!ldr_parm->section_detached || !ldr_parm->section_detached(shdr)) ? - shdr->sh_addr : (uintptr_t)llext_peek(ldr, shdr->sh_offset); + shdr->sh_addr : (uintptr_t)llext_loaded_sect_ptr(ldr, ext, sym->st_shndx); } else { sh_addr = ldr->sects[LLEXT_MEM_TEXT].sh_addr; }