Skip to content

Commit

Permalink
llext: add support for .bss directly adjacent to .data
Browse files Browse the repository at this point in the history
Zephyr places .bss into a separate section element, still if it's
immediately adjacent to writable data we can merge and allocate them
together.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh authored and nashif committed Jun 5, 2024
1 parent 90f58ca commit 3f1716b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/library_manager/llext_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,21 @@ static int llext_manager_load_module(uint32_t module_id, const struct sof_man_mo

/* Check, that .bss is within .data */
if (bss_size &&
((uintptr_t)bss_addr + bss_size < (uintptr_t)va_base_data ||
((uintptr_t)bss_addr + bss_size <= (uintptr_t)va_base_data ||
(uintptr_t)bss_addr >= (uintptr_t)va_base_data + data_size)) {
tr_err(&lib_manager_tr, ".bss %#x @ %p isn't within writable data %#x @ %p!",
bss_size, bss_addr, data_size, (void *)va_base_data);
return -EPROTO;
if ((uintptr_t)bss_addr + bss_size == (uintptr_t)va_base_data &&
!((uintptr_t)bss_addr & (PAGE_SZ - 1))) {
/* .bss directly in front of writable data and properly aligned, prepend */
va_base_data = bss_addr;
data_size += bss_size;
} else if ((uintptr_t)bss_addr == (uintptr_t)va_base_data + data_size) {
/* .bss directly behind writable data, append */
data_size += bss_size;
} else {
tr_err(&lib_manager_tr, ".bss %#x @ %p isn't within writable data %#x @ %p!",
bss_size, bss_addr, data_size, (void *)va_base_data);
return -EPROTO;
}
}

/* Copy Code */
Expand All @@ -162,8 +172,7 @@ static int llext_manager_load_module(uint32_t module_id, const struct sof_man_mo
if (ret < 0)
goto e_rodata;

memset((__sparse_force void *)ctx->segment[LIB_MANAGER_BSS].addr, 0,
ctx->segment[LIB_MANAGER_BSS].size);
memset((__sparse_force void *)bss_addr, 0, bss_size);

return 0;

Expand Down

0 comments on commit 3f1716b

Please sign in to comment.