From b2114eaf761e950fd18c95851f7d9c312fb2c448 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 23 Aug 2024 10:20:22 +0200 Subject: [PATCH] llext: fix flag evaluation for section grouping When deciding which sections to group together, only the low 3 section attribute bits are relevant, ignore the rest. Signed-off-by: Guennadi Liakhovetski --- include/zephyr/llext/elf.h | 2 ++ subsys/llext/llext_load.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/zephyr/llext/elf.h b/include/zephyr/llext/elf.h index b0477416a43386..ca9f498a49ac0f 100644 --- a/include/zephyr/llext/elf.h +++ b/include/zephyr/llext/elf.h @@ -212,6 +212,8 @@ struct elf64_shdr { #define SHF_ALLOC 0x2 /**< Section is present in memory */ #define SHF_EXECINSTR 0x4 /**< Section contains executable instructions */ +#define SHF_BASIC_TYPE_MASK (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR) + /** * @brief Symbol table entry(32-bit) */ diff --git a/subsys/llext/llext_load.c b/subsys/llext/llext_load.c index de3cdd6402b96f..fcc26210ebcfc7 100644 --- a/subsys/llext/llext_load.c +++ b/subsys/llext/llext_load.c @@ -253,8 +253,10 @@ static int llext_map_sections(struct llext_loader *ldr, struct llext *ext) memcpy(region, shdr, sizeof(*region)); } else { /* Make sure this section is compatible with the region */ - if (shdr->sh_flags != region->sh_flags) { - LOG_ERR("Unsupported section flags for %s (region %d)", + if ((shdr->sh_flags & SHF_BASIC_TYPE_MASK) != + (region->sh_flags & SHF_BASIC_TYPE_MASK)) { + LOG_ERR("Unsupported section flags %#x / %#x for %s (region %d)", + (uint32_t)shdr->sh_flags, (uint32_t)region->sh_flags, name, mem_idx); return -ENOEXEC; }