Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llext: add new inspection API #85498

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

pillo79
Copy link
Collaborator

@pillo79 pillo79 commented Feb 10, 2025

Introduction

This PR introduces a new set of functions that allows applications to access internal details about the loaded extensions.
In particular, these new functions allows access to data related to the ELF file sections (and their runtime location, if they got picked up by the LLEXT loader):

  • a llext_get_region_info() function that retrieves the region header, its start address and length, given its index;
  • a llext_get_section_info() function that retrieves the ELF section header, its associated region and offset in the region, given its index;
  • a llext_section_shndx() function that returns the index of a section given its name.

Using the new APIs requires explicitly asking for this data to be kept after llext_load completes via a new load-time parameter. If keep_section_info is set in the load params, some of the structures will be retained to allow the application to retrieve the required information. This data can later be discarded by calling the llext_free_inspect_data() function.

Use case

This new API is extensively used in thesofproject/sof#9831, to remove the strict dependency of SOF from LLEXT internal structures.
An LLEXT test case that verifies that symbols in different sections map to the expected regions and memory locations are within proper bounds has also been added to the Zephyr test suite.

I would like to include this in 4.1 so the new API is available for full SOF integration testing during the freeze window.

@pillo79 pillo79 force-pushed the pr-llext-inspect-api branch from 7832db1 to e9c78e0 Compare February 10, 2025 14:05
@pillo79 pillo79 marked this pull request as ready for review February 10, 2025 15:49
@zephyrbot zephyrbot added the area: llext Linkable Loadable Extensions label Feb 10, 2025
@zephyrbot zephyrbot requested review from lyakh and teburd February 10, 2025 15:50
@pillo79 pillo79 force-pushed the pr-llext-inspect-api branch 2 times, most recently from 0f1f3db to b995e8b Compare February 11, 2025 09:19
include/zephyr/llext/inspect.h Outdated Show resolved Hide resolved
include/zephyr/llext/inspect.h Outdated Show resolved Hide resolved
tests/subsys/llext/src/test_llext.c Show resolved Hide resolved
This is required for the functions that inspect the ELF file to work
properly. The user must then call llext_free_inspection_data() before
calling llext_unload() to free the memory left allocated in the loader
and extension memory.

Signed-off-by: Luca Burelli <[email protected]>
@pillo79 pillo79 force-pushed the pr-llext-inspect-api branch from b995e8b to a4f4f35 Compare February 11, 2025 12:02
teburd
teburd previously approved these changes Feb 11, 2025
Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, though there are definitely some footguns to be found here if you aren't careful.

Add APIs to inspect the contents of an ELF file loaded as an extension.
This is useful for applications that need to access the contents of the
extension in a more fine-grained way than the existing LLEXT APIs.

Use of these APIs requires the 'keep_elf_data' option to be provided via
struct llext_load_param to the 'llext_load()' call.

Signed-off-by: Luca Burelli <[email protected]>
This patch adds a test suite for the inspection API. The test checks
that the symbols exported by the 'inspect_ext' extension are correctly
mapped inside their corresponding regions and sections.

Signed-off-by: Luca Burelli <[email protected]>
@pillo79 pillo79 force-pushed the pr-llext-inspect-api branch from a32e6bf to e693208 Compare February 11, 2025 16:52
@pillo79
Copy link
Collaborator Author

pillo79 commented Feb 11, 2025

Sorry for the noise, force pushed a change to the wrong repo 😅
Update was only a "fix" for the corner case of section 0 (which is all zeros by ELF spec anyway!).

@kartben kartben merged commit fe29c40 into zephyrproject-rtos:main Feb 13, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: llext Linkable Loadable Extensions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants