Skip to content

Commit 741c5b5

Browse files
pillo79kartben
authored andcommitted
llext: rework debug code in llext_link
This removes 'return' statements affecting code flow from debug code in llext_link(). Also, all valid relocations are tried before returning an error, so that the user can see all the errors (most likely missing symbols) at once. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent a3089c1 commit 741c5b5

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

subsys/llext/llext_link.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ int llext_link(struct llext_loader *ldr, struct llext *ext, const struct llext_l
409409
elf_rela_t rel = {0};
410410
elf_word rel_cnt = 0;
411411
const char *name;
412+
int link_err = 0;
412413
int i, ret;
413414

414415
for (i = 0; i < ext->sect_cnt; ++i) {
@@ -510,52 +511,52 @@ int llext_link(struct llext_loader *ldr, struct llext *ext, const struct llext_l
510511
return ret;
511512
}
512513

513-
#ifdef CONFIG_LLEXT_LOG_LEVEL
514-
if (CONFIG_LLEXT_LOG_LEVEL >= LOG_LEVEL_INF) {
515-
uintptr_t link_addr;
516-
uintptr_t op_loc =
517-
llext_get_reloc_instruction_location(ldr, ext,
518-
shdr->sh_info,
519-
&rel);
520-
elf_sym_t sym;
521-
522-
ret = llext_read_symbol(ldr, ext, &rel, &sym);
523-
524-
if (ret != 0) {
525-
return ret;
526-
}
514+
#if CONFIG_LLEXT_LOG_LEVEL > LOG_LEVEL_INF /* also gets skipped without CONFIG_LOG */
515+
uintptr_t link_addr;
516+
uintptr_t op_loc = llext_get_reloc_instruction_location(ldr, ext,
517+
shdr->sh_info,
518+
&rel);
519+
elf_sym_t sym;
520+
const char *inv_str = "";
527521

522+
ret = llext_read_symbol(ldr, ext, &rel, &sym);
523+
if (ret == 0) {
528524
name = llext_symbol_name(ldr, ext, &sym);
525+
ret = llext_lookup_symbol(ldr, ext, &link_addr, &rel, &sym,
526+
name, shdr);
527+
} else {
528+
name = "<unknown>";
529+
}
529530

530-
ret = llext_lookup_symbol(ldr, ext, &link_addr, &rel, &sym, name,
531-
shdr);
532-
533-
if (ret != 0) {
534-
LOG_ERR("Could not find symbol %s!", name);
535-
return ret;
536-
}
537-
538-
LOG_DBG("relocation %d:%d info %#zx (type %zd, sym %zd) offset %zd"
539-
" sym_name %s sym_type %d sym_bind %d sym_ndx %d",
540-
i, j, (size_t)rel.r_info, (size_t)ELF_R_TYPE(rel.r_info),
541-
(size_t)ELF_R_SYM(rel.r_info), (size_t)rel.r_offset,
542-
name, ELF_ST_TYPE(sym.st_info),
543-
ELF_ST_BIND(sym.st_info), sym.st_shndx);
544-
545-
LOG_DBG("writing relocation type %d at %#lx with symbol %s (%#lx)",
546-
(int)ELF_R_TYPE(rel.r_info), op_loc, name, link_addr);
531+
if (ret != 0) {
532+
inv_str = "(invalid) ";
533+
memset(&sym, 0, sizeof(sym));
534+
link_addr = 0;
547535
}
548-
#endif /* CONFIG_LLEXT_LOG_LEVEL */
549536

537+
LOG_DBG("%srelocation %d:%d info %#zx (type %zd, sym %zd) offset %zd"
538+
" sym_name %s sym_type %d sym_bind %d sym_ndx %d",
539+
inv_str, i, j, (size_t)rel.r_info, (size_t)ELF_R_TYPE(rel.r_info),
540+
(size_t)ELF_R_SYM(rel.r_info), (size_t)rel.r_offset,
541+
name, ELF_ST_TYPE(sym.st_info),
542+
ELF_ST_BIND(sym.st_info), sym.st_shndx);
550543

551-
/* relocation */
544+
LOG_DBG("%swriting relocation type %d at %#lx with symbol %s (%#lx)",
545+
inv_str, (int)ELF_R_TYPE(rel.r_info), op_loc, name, link_addr);
546+
#endif /* CONFIG_LLEXT_LOG_LEVEL > LOG_LEVEL_INF */
547+
548+
/* relocation, collect first error */
552549
ret = arch_elf_relocate(ldr, ext, &rel, shdr);
553-
if (ret != 0) {
554-
return ret;
550+
if (link_err == 0) {
551+
link_err = ret;
555552
}
556553
}
557554
}
558555

556+
if (link_err != 0) {
557+
return link_err;
558+
}
559+
559560
#ifdef CONFIG_CACHE_MANAGEMENT
560561
/* Make sure changes to memory regions are flushed to RAM */
561562
for (i = 0; i < LLEXT_MEM_COUNT; ++i) {

0 commit comments

Comments
 (0)