Commit graph

17 commits

Author SHA1 Message Date
Guennadi Liakhovetski 6246caa643 llext: (cosmetic) rename a variable to match its role
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>
2023-11-15 14:17:08 +00:00
Guennadi Liakhovetski 6058512b06 llext: use provided size for more generic code
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>
2023-11-15 14:17:08 +00:00
Guennadi Liakhovetski 68b4898b7e llext: skip first dummy symbol table entry
The first entry in the symbol table is empty, skip it.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2023-11-15 14:17:08 +00:00
Guennadi Liakhovetski a88facacaa llext: clarify the use of loop variables, simplify code
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>
2023-11-15 14:17:08 +00:00
Guennadi Liakhovetski 0bf08e5775 llext: use llext_peek() for section pointers
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>
2023-11-10 10:40:26 +01:00
Guennadi Liakhovetski ce4cdac3c0 llext: add llext_peek()
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>
2023-11-10 10:40:26 +01:00
Guennadi Liakhovetski a9a82d557c llext: use elf_rela_t instead of elf_rel_t
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>
2023-11-09 18:21:27 +01:00
Guennadi Liakhovetski f0527b5571 llext: add a weak arch_elf_relocate() stub
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>
2023-11-09 18:21:27 +01:00
Guennadi Liakhovetski ade72c2b3a llext: remove a superfluous variable initialisation
ret in llext_load() is always assigned before use, remove its
redundant initialisation.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2023-11-09 18:21:27 +01:00
Tom Burdick 982cc794e3 llext: Make the shell list command output nicer
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>
2023-11-08 10:07:50 +01:00
Tom Burdick 6d651e37a3 llext: Track module memory usage
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>
2023-11-08 10:07:50 +01:00
Guennadi Liakhovetski 5064df0500 llext: copy complete string sections while parsing ELF
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>
2023-10-27 10:51:49 +02:00
Guennadi Liakhovetski 23472509d3 llext: refactor section copying
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>
2023-10-27 10:51:49 +02:00
Flavio Ceolin 2d5b781e99 llext: Fix wrong check
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>
2023-10-20 15:20:35 +02:00
Tom Burdick c678f25bc1 llext: Fix a bug in section linking
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>
2023-10-13 16:47:02 +01:00
Kai Meinhard 33494d4ea2 LLEXT: Make max size in shell configurable
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>
2023-10-03 15:17:39 +01:00
Tom Burdick 41e0a4a371 llext: Linkable loadable extensions
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>
2023-09-29 20:50:38 -04:00