From 7eb1d3d57d2d0c0484935199503de97815ea243c Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sun, 10 Mar 2024 04:23:29 +0000 Subject: [PATCH] llext: elf.h: fix wrong 32 bits length of elf64_rela fields Fixes commit a9a82d557c72 ("llext: use elf_rela_t instead of elf_rel_t") Also switch sign of (unused?) `r_addend` to unsigned. https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.reloc.html Issue found thanks to the following warnings when compiling in 64bits: ``` /__w/zephyr/zephyr/include/zephyr/llext/elf.h:349:29: error: right shift count >= width of type [-Werror=shift-count-overflow] 349 | #define ELF64_R_SYM(i) ((i) >> 32) ``` The name `elf64_word` was admittedly confusing. Signed-off-by: Marc Herbert --- include/zephyr/llext/elf.h | 4 ++-- subsys/llext/llext.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/zephyr/llext/elf.h b/include/zephyr/llext/elf.h index a9fd8f86a94..dd2482b2466 100644 --- a/include/zephyr/llext/elf.h +++ b/include/zephyr/llext/elf.h @@ -338,8 +338,8 @@ struct elf64_rel { struct elf64_rela { elf64_addr r_offset; - elf64_word r_info; - elf64_word r_addend; + elf64_xword r_info; + elf64_sxword r_addend; }; /** @brief Relocation symbol from r_info diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 309048e4568..a6ed1e4ac86 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -746,9 +746,10 @@ static int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local name = llext_string(ldr, ext, LLEXT_MEM_STRTAB, sym.st_name); - LOG_DBG("relocation %d:%d info %x (type %d, sym %d) offset %zd sym_name " + LOG_DBG("relocation %d:%d info %zx (type %zd, sym %zd) offset %zd sym_name " "%s sym_type %d sym_bind %d sym_ndx %d", - i, j, rel.r_info, ELF_R_TYPE(rel.r_info), ELF_R_SYM(rel.r_info), + i, j, (size_t)rel.r_info, (size_t)ELF_R_TYPE(rel.r_info), + (size_t)ELF_R_SYM(rel.r_info), (size_t)rel.r_offset, name, ELF_ST_TYPE(sym.st_info), ELF_ST_BIND(sym.st_info), sym.st_shndx); @@ -784,9 +785,9 @@ static int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local name, ELF_ST_TYPE(sym.st_info), ELF_ST_BIND(sym.st_info), sym.st_shndx, (size_t)rel.r_offset, shdr.sh_link); - LOG_INF("writing relocation symbol %s type %d sym %d at addr 0x%lx " + LOG_INF("writing relocation symbol %s type %zd sym %zd at addr 0x%lx " "addr 0x%lx", - name, ELF_R_TYPE(rel.r_info), ELF_R_SYM(rel.r_info), + name, (size_t)ELF_R_TYPE(rel.r_info), (size_t)ELF_R_SYM(rel.r_info), op_loc, link_addr); /* relocation */