str_cnt in llext_find_tables() is actually used to count sections,
rename it to better match that usage.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Use .sh_entsize instead of sizeof(elf_rel_t) to make code suitable
for both REL and RELA types.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Several cosmetic changes with no change in functionality:
The pos variable in multiple functions is used as a loop variable -
it's initialised before the loop starts and then it's incremented for
each loop iteration. Move it to the loop header for readability.
"return ret" is clearer than "goto out" where the "out" label does
nothing but "out: return ret" because one sees immediately that the
function is terminated at that location with no further actions
without the need to check the "out" label.
k_heap_free(heap, NULL) is valid, no need to check the address to be
freed for NULL.
Object counters can be simple (unsigned) integers, no need to make
them size_t or elf_word.
"return 0" is simpler than "return ret" because it shows the return
value immediately without the need to check what it can be at that
location.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Try to use llext_peek() for section pointers. If it's supported and
succeeds we don't need to allocate buffers.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
The only way so far to access extension images is via a memory
buffer. Since this, supposedly, will also be a rather common method,
it makes sense to add a method to access extension data quickly by
obtaining a pointer instead of copying data into local buffers. Add a
llext_peek() method for that.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
elf_rela_t contains elf_rel_t exactly and contains an additional
field at the end. Therefore pointers of that type can be used for
both types, making the code generic.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
The module linking API can be used for shared objects with no
architecture-specific relocation code. Add a weak function for such
cases.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
ret in llext_load() is always assigned before use, remove its
redundant initialisation.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Remove unnecessary newline characters from shell_print, it already adds
them. Align the table pipe characters better in the list of modules.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
The memory usage shown in the shell was 0 which is obviously incorrect.
At some point the memory allocation tracking was dropped from llext.c
mistakenly. Add it back.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
This has several advantages:
1. we don't need any hard assumptions about symbol length. The
current hard-coded limit of 32 characters might well be not true.
2. replaces a lot of code for reading those names with a single
call to a 1-line function to calculate string location.
3. eliminates the need to allocate buffers for exported symbol names
by replacing them with a simple pointer assignment.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Instead of first allocating all sections and then copying then,
create a helper function to allocate and copy a single section and
call it for all appropriate sections. We need to call this function
from another location when copying string sections.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
In llext_copy_symbols the check after llext_read
was looking the result of llext_seek operation instead
of the read.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
When relocating section symbol addresses the value where the
relocation is to be written is an offset into the section to load.
Simply rewriting it with the section address is not enough, we need
to write the address of the section with the offset into it.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
The maximum size of an extension accept by the shell
was previously a define and is now made configurable through Kconfig.
Signed-off-by: Kai Meinhard <meinhard@gessler.de>
Adds the linkable loadable extensions (llext) subsystem which provides
functionality for reading, parsing, and linking ELF encoded executable
code into a managed extension to the running elf base image.
A loader interface, and default buffer loader implementation,
make available to the llext subsystem the elf data. A simple management
API provide the ability to load and unload extensions as needed. A shell
interface for extension loading and unloading makes it easy to try.
Adds initial support for armv7 thumb built elfs with very specific
compiler flags.
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
Co-authored-by: Chen Peng1 <peng1.chen@intel.com>
Co-authored-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>