Skip to content

Commit cbb6199

Browse files
lyakhfabiobaltieri
authored andcommitted
LLEXT: no repeated linking with inline relocations
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 <[email protected]>
1 parent 827909b commit cbb6199

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

subsys/llext/llext_link.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ static void llext_link_plt(struct llext_loader *ldr, struct llext *ext, elf_shdr
259259
arch_elf_relocate_global(ldr, ext, &rela, &sym, got_offset, link_addr);
260260
break;
261261
case STB_LOCAL:
262-
if (ldr_parm->relocate_local) {
263-
arch_elf_relocate_local(ldr, ext, &rela, &sym, got_offset,
264-
ldr_parm);
265-
}
262+
arch_elf_relocate_local(ldr, ext, &rela, &sym, got_offset, ldr_parm);
266263
}
267264

268265
LOG_DBG("symbol %s offset %#zx r-offset %#zx .text offset %#zx stb %u",

subsys/llext/llext_load.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,13 @@ int do_llext_load(struct llext_loader *ldr, struct llext *ext,
712712
goto out;
713713
}
714714

715-
LOG_DBG("Linking ELF...");
716-
ret = llext_link(ldr, ext, ldr_parm);
717-
if (ret != 0) {
718-
LOG_ERR("Failed to link, ret %d", ret);
719-
goto out;
715+
if (ldr_parm->relocate_local) {
716+
LOG_DBG("Linking ELF...");
717+
ret = llext_link(ldr, ext, ldr_parm);
718+
if (ret != 0) {
719+
LOG_ERR("Failed to link, ret %d", ret);
720+
goto out;
721+
}
720722
}
721723

722724
ret = llext_export_symbols(ldr, ext);

0 commit comments

Comments
 (0)