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 <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
Guennadi Liakhovetski 2024-12-05 15:16:30 +01:00 committed by Benjamin Cabé
parent b3d8766126
commit acbd183b72

View file

@ -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;
}