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 dependencies: add support for linking between LLEXT objects #77473

Merged
merged 7 commits into from
Sep 2, 2024

Conversation

lyakh
Copy link
Collaborator

@lyakh lyakh commented Aug 23, 2024

This adds support for exporting symbols between extensions while building dependencies based on such symbol references

lyakh added a commit to lyakh/sof that referenced this pull request Aug 23, 2024
Test zephyrproject-rtos/zephyr#77473

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
lyakh added a commit to lyakh/sof that referenced this pull request Aug 23, 2024
Test zephyrproject-rtos/zephyr#77473

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
lyakh added a commit to lyakh/sof that referenced this pull request Aug 23, 2024
Test zephyrproject-rtos/zephyr#77473

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@faxe1008 faxe1008 marked this pull request as ready for review August 23, 2024 13:45
@faxe1008 faxe1008 marked this pull request as draft August 23, 2024 13:51
@faxe1008
Copy link
Collaborator

@lyakh sorry for marking this as ready for review, I misclicked in the GitHub mobile app. Apologies for the noise.

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.

Looks mostly reasonable to me, some oddities that are maybe caused by using llext_iterate when perhaps instead a different approach would avoid some strangeness

Should fix the formatting issues otherwise misra checks will fail and someone just fixed many issues in the tree related to misra styling.

include/zephyr/llext/symbol.h Outdated Show resolved Hide resolved
subsys/llext/llext_load.c Outdated Show resolved Hide resolved
@@ -111,6 +114,8 @@ struct llext {

/** Extension use counter, prevents unloading while in use */
unsigned int use_count;

struct llext *dependency[LLEXT_MAX_DEPENDENCIES];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could use a doc string

subsys/llext/llext_link.c Show resolved Hide resolved
subsys/llext/llext_link.c Show resolved Hide resolved
subsys/llext/llext_link.c Outdated Show resolved Hide resolved
subsys/llext/llext_link.c Outdated Show resolved Hide resolved
subsys/llext/llext_link.c Outdated Show resolved Hide resolved
lyakh added a commit to lyakh/sof that referenced this pull request Aug 23, 2024
Test zephyrproject-rtos/zephyr#77473

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Copy link
Collaborator

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

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

Neat piece of work!

A few comments from me, but otherwise looks pretty solid:

subsys/llext/llext_load.c Outdated Show resolved Hide resolved
include/zephyr/llext/symbol.h Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: this sounds prone to race conditions - but the whole subsystem is, anyways, as struct llext lacks a lock... This is well outside PR scope though 😄

subsys/llext/llext_link.c Outdated Show resolved Hide resolved
subsys/llext/llext_link.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@pillo79 pillo79 left a comment

Choose a reason for hiding this comment

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

Agree with all comments, I'm late to the party 🙂
Otherwise LGTM as well! 👍 Thanks!

Remove a loop counter, that isn't actually used for anything.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Currently LLEXT has two ways to export symbols:
EXPORT_SYMBOL() to exort symbols from the main firmware to extensions
LL_EXTENSION_SYMBOL() to export symbols from extensions
but it is possible to write code, that needs to export symbols
regardless of whether it is built into the main image or an
extension. And in fact there's no real need in two distinct macros -
we can use one for both cases and recognise at build time which
direction exporting is happening. This patch extends EXPORT_SYMBOL()
to also work from extensions.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Replace LL_EXTENSION_SYMBOL() with EXPORT_SYMBOL() in all tests and
samples.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
LLEXT objects can also export symbols for use by other such objects.
That means, that when linking an LLEXT object we have to look for
unresolved symbols in previously loaded objects too.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Using the immediate logging option from LLEXT modules requires
one more symbol export.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
When deciding which sections to group together, only the low 3
section attribute bits are relevant, ignore the rest.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@lyakh lyakh force-pushed the depend branch 2 times, most recently from 99679e0 to 89d27f7 Compare August 29, 2024 07:41
@lyakh lyakh marked this pull request as ready for review August 29, 2024 08:56
@zephyrbot zephyrbot added the area: Samples Samples label Aug 29, 2024
When an LLEXT object uses symbols of another such object, it depends
on it. Such dependencies have to be tracked to prevent their
accidental unloading. Ideally we should be able to track arbitrary
numbers of such dependencies, but this is a bit difficult. In this
first implementation we use a fixed-size array, currently consisting
of 8 entries.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Copy link
Collaborator

@pillo79 pillo79 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this!
Just mentioning a tiny refactor issue, maybe fix it if you ever have to rework commits.

Comment on lines +392 to +401
if (link_addr == 0) {
/* Try loaded tables */
struct llext *dep;

link_addr = (uintptr_t)llext_find_extension_sym(name, &dep);
if (link_addr) {
llext_dependency_add(ext, dep);
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very minor nit - if you ever have to refactor anything: this bit of code is added in the last commit, which only deals with dependency tracking. Similar to what happens for Xtensa, it could be split between the commit that introduces the actual lookup and the one adding tracking.

Copy link
Collaborator

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

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

LGTM.

Nit: I feel like llext_find_extension_sym would be a more fitting name for what we currently call llext_find_sym, and vice-versa... just food for thought, changing the API is not in scope for this PR 😄

@lyakh
Copy link
Collaborator Author

lyakh commented Aug 30, 2024

#77738 adds a (draft but should be already working) test for this new functionality, which will be finalised and released for review and merging once this has been merged

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.

Very nice set of changes

@@ -62,6 +62,9 @@ enum llext_mem {
struct llext_loader;
/** @endcond */

/* Maximim number of dependency LLEXTs */
#define LLEXT_MAX_DEPENDENCIES 8
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a Kconfig, not a blocker but would be good to see a follow up for

@aescolar aescolar added the DNM This PR should not be merged (Do Not Merge) label Sep 2, 2024
@aescolar
Copy link
Member

aescolar commented Sep 2, 2024

Added dnm given @lyakh's initial comment indicating this was a draft, to avoid accidental merge. Please confirm you'd like to have this merged. You (or anybody else) is welcome to remove the dnm.

@lyakh lyakh removed the DNM This PR should not be merged (Do Not Merge) label Sep 2, 2024
@lyakh
Copy link
Collaborator Author

lyakh commented Sep 2, 2024

Added dnm given @lyakh's initial comment indicating this was a draft, to avoid accidental merge. Please confirm you'd like to have this merged. You (or anybody else) is welcome to remove the dnm.

@aescolar sorry, forgot to update the PR description, done now, so, yes, this is targeted for merge

lyakh added a commit to lyakh/sof that referenced this pull request Sep 2, 2024
Test zephyrproject-rtos/zephyr#77473

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@nashif nashif merged commit dd50ff5 into zephyrproject-rtos:main Sep 2, 2024
26 of 27 checks passed
@lyakh lyakh deleted the depend branch September 3, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants