Skip to content

Commit 0aa6b1c

Browse files
lyakhhenrikbrixandersen
authored andcommitted
llext: pass the whole struct llext_load_param
To simplify LLEXT loader parameter extension pass the whole struct llext_load_param to final consumers instead of extracting individual fields from it in the caller function. Signed-off-by: Guennadi Liakhovetski <[email protected]>
1 parent d676d46 commit 0aa6b1c

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

subsys/llext/llext_link.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ static const void *llext_find_extension_sym(const char *sym_name, struct llext *
135135
return se.addr;
136136
}
137137

138-
static void llext_link_plt(struct llext_loader *ldr, struct llext *ext,
139-
elf_shdr_t *shdr, bool do_local, elf_shdr_t *tgt)
138+
static void llext_link_plt(struct llext_loader *ldr, struct llext *ext, elf_shdr_t *shdr,
139+
const struct llext_load_param *ldr_parm, elf_shdr_t *tgt)
140140
{
141141
unsigned int sh_cnt = shdr->sh_size / shdr->sh_entsize;
142142
/*
@@ -252,7 +252,7 @@ static void llext_link_plt(struct llext_loader *ldr, struct llext *ext,
252252
*(const void **)(text + got_offset) = link_addr;
253253
break;
254254
case STB_LOCAL:
255-
if (do_local) {
255+
if (ldr_parm->relocate_local) {
256256
arch_elf_relocate_local(ldr, ext, &rela, &sym, got_offset);
257257
}
258258
}
@@ -263,7 +263,7 @@ static void llext_link_plt(struct llext_loader *ldr, struct llext *ext,
263263
}
264264
}
265265

266-
int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local)
266+
int llext_link(struct llext_loader *ldr, struct llext *ext, const struct llext_load_param *ldr_parm)
267267
{
268268
uintptr_t sect_base = 0;
269269
elf_rela_t rel;
@@ -330,7 +330,7 @@ int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local)
330330
tgt = ldr->sect_hdrs + shdr->sh_info;
331331
}
332332

333-
llext_link_plt(ldr, ext, shdr, do_local, tgt);
333+
llext_link_plt(ldr, ext, shdr, ldr_parm, tgt);
334334
continue;
335335
}
336336

subsys/llext/llext_load.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static int llext_export_symbols(struct llext_loader *ldr, struct llext *ext)
527527
}
528528

529529
static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext,
530-
bool pre_located)
530+
const struct llext_load_param *ldr_parm)
531531
{
532532
size_t ent_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_entsize;
533533
size_t syms_size = ldr->sects[LLEXT_MEM_SYMTAB].sh_size;
@@ -586,7 +586,7 @@ static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext,
586586
}
587587
}
588588

589-
if (pre_located) {
589+
if (ldr_parm->pre_located) {
590590
sym_tab->syms[j].addr = (uint8_t *)sym.st_value +
591591
(ldr->hdr.e_type == ET_REL ? section_addr : 0);
592592
} else {
@@ -609,8 +609,13 @@ static int llext_copy_symbols(struct llext_loader *ldr, struct llext *ext,
609609
int do_llext_load(struct llext_loader *ldr, struct llext *ext,
610610
const struct llext_load_param *ldr_parm)
611611
{
612+
const struct llext_load_param default_ldr_parm = LLEXT_LOAD_PARAM_DEFAULT;
612613
int ret;
613614

615+
if (!ldr_parm) {
616+
ldr_parm = &default_ldr_parm;
617+
}
618+
614619
/* Zero all memory that is affected by the loading process
615620
* (see the NOTICE at the top of this file).
616621
*/
@@ -681,14 +686,14 @@ int do_llext_load(struct llext_loader *ldr, struct llext *ext,
681686
}
682687

683688
LOG_DBG("Copying symbols...");
684-
ret = llext_copy_symbols(ldr, ext, ldr_parm ? ldr_parm->pre_located : false);
689+
ret = llext_copy_symbols(ldr, ext, ldr_parm);
685690
if (ret != 0) {
686691
LOG_ERR("Failed to copy symbols, ret %d", ret);
687692
goto out;
688693
}
689694

690695
LOG_DBG("Linking ELF...");
691-
ret = llext_link(ldr, ext, ldr_parm ? ldr_parm->relocate_local : true);
696+
ret = llext_link(ldr, ext, ldr_parm);
692697
if (ret != 0) {
693698
LOG_ERR("Failed to link, ret %d", ret);
694699
goto out;

subsys/llext/llext_priv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static inline const char *llext_string(struct llext_loader *ldr, struct llext *e
6262
* Relocation (llext_link.c)
6363
*/
6464

65-
int llext_link(struct llext_loader *ldr, struct llext *ext, bool do_local);
65+
int llext_link(struct llext_loader *ldr, struct llext *ext,
66+
const struct llext_load_param *ldr_parm);
6667
void llext_dependency_remove_all(struct llext *ext);
6768

6869
#endif /* ZEPHYR_SUBSYS_LLEXT_PRIV_H_ */

0 commit comments

Comments
 (0)