Skip to content

Commit

Permalink
llext: arch_elf_relocate: pass opval unmodified
Browse files Browse the repository at this point in the history
The opval argument of arch_elf_relocate() was modified by
adding the value stored at opaddr before passing it to
arch_elf_relocate(). This presumed that the addend would
always be stored as a raw value at opaddr, which is not the
case for all relocation types.

This PR modifies opval to be the absolute address of opval,
and moves the addition of the addend from llext_link_plt()
to the implementation of arch_elf_relocate().

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
  • Loading branch information
bjarki-andreasen authored and fabiobaltieri committed Mar 14, 2024
1 parent 6c6495b commit 5cac834
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions arch/arm/core/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ void arch_elf_relocate(elf_rela_t *rel, uintptr_t opaddr, uintptr_t opval)

switch (reloc_type) {
case R_ARM_ABS32:
/* Add the addend stored at opaddr to opval */
opval += *((uint32_t *)opaddr);

/* Update the absolute address of a load/store instruction */
*((uint32_t *)opaddr) = (uint32_t)opval;
break;
Expand Down
5 changes: 2 additions & 3 deletions subsys/llext/llext.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,9 @@ static int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local
}
} else if (ELF_ST_TYPE(sym.st_info) == STT_SECTION ||
ELF_ST_TYPE(sym.st_info) == STT_FUNC) {
/* Current relocation location holds an offset into the section */
/* Link address is relative to the start of the section */
link_addr = (uintptr_t)ext->mem[ldr->sect_map[sym.st_shndx]]
+ sym.st_value
+ *((uintptr_t *)op_loc);
+ sym.st_value;

LOG_INF("found section symbol %s addr 0x%lx", name, link_addr);
} else {
Expand Down

0 comments on commit 5cac834

Please sign in to comment.