From e55b50631cfd468a907b77cf1a512566e5e5cc72 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 11 Nov 2024 16:19:08 +0100 Subject: [PATCH] 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. (cherry picked from commit cbb6199e679c50c75d3ed090852b4993e8b06a8a) Original-Signed-off-by: Guennadi Liakhovetski GitOrigin-RevId: cbb6199e679c50c75d3ed090852b4993e8b06a8a Cr-Build-Id: 8730756689262017889 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8730756689262017889 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I1379408f927ffdd3755cc8882d95aa0aa143a757 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6037871 Tested-by: Tristan Honscheid Reviewed-by: Tristan Honscheid Tested-by: ChromeOS Prod (Robot) Commit-Queue: Tristan Honscheid --- subsys/llext/llext_link.c | 5 +---- subsys/llext/llext_load.c | 12 +++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/subsys/llext/llext_link.c b/subsys/llext/llext_link.c index 6d5e2ff23bc..7dacb112a00 100644 --- a/subsys/llext/llext_link.c +++ b/subsys/llext/llext_link.c @@ -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", diff --git a/subsys/llext/llext_load.c b/subsys/llext/llext_load.c index bd73312c085..06f4b9a2f97 100644 --- a/subsys/llext/llext_load.c +++ b/subsys/llext/llext_load.c @@ -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);