Skip to content

Commit

Permalink
LLEXT: no repeated linking with inline relocations
Browse files Browse the repository at this point in the history
When linking and relocations are performed on the ELF object itself
with no copying, also global binding linking can break references.
Disable linking globally for such cases.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh authored and fabiobaltieri committed Nov 20, 2024
1 parent 827909b commit cbb6199
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 1 addition & 4 deletions subsys/llext/llext_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ static void llext_link_plt(struct llext_loader *ldr, struct llext *ext, elf_shdr
arch_elf_relocate_global(ldr, ext, &rela, &sym, got_offset, link_addr);
break;
case STB_LOCAL:
if (ldr_parm->relocate_local) {
arch_elf_relocate_local(ldr, ext, &rela, &sym, got_offset,
ldr_parm);
}
arch_elf_relocate_local(ldr, ext, &rela, &sym, got_offset, ldr_parm);
}

LOG_DBG("symbol %s offset %#zx r-offset %#zx .text offset %#zx stb %u",
Expand Down
12 changes: 7 additions & 5 deletions subsys/llext/llext_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,13 @@ int do_llext_load(struct llext_loader *ldr, struct llext *ext,
goto out;
}

LOG_DBG("Linking ELF...");
ret = llext_link(ldr, ext, ldr_parm);
if (ret != 0) {
LOG_ERR("Failed to link, ret %d", ret);
goto out;
if (ldr_parm->relocate_local) {
LOG_DBG("Linking ELF...");
ret = llext_link(ldr, ext, ldr_parm);
if (ret != 0) {
LOG_ERR("Failed to link, ret %d", ret);
goto out;
}
}

ret = llext_export_symbols(ldr, ext);
Expand Down

0 comments on commit cbb6199

Please sign in to comment.