Skip to content

Commit abc8cb3

Browse files
Mathieu ChoplainMaureenHelm
authored andcommitted
llext: warn when devices aren't exported and extension tries to use them
Kconfig option LLEXT_EXPORT_DEVICES can be enabled to make all device objects of an image available to LLEXTs, but it is disabled by default. If an extension tries to import devices when the base image was not built with this option, the dynamic linking equivalent of the much beloved error "Undefined symbol __device_dts_ord_XXX" is logged, but this can be quite cryptic to understand since user may be unaware of LLEXT_EXPORT_DEVICES. Detect such invalid imports and print a special message that directs users towards the appropriate Kconfig option, which should reduce the confusion. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent b6e2486 commit abc8cb3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

subsys/llext/llext_link.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ int llext_lookup_symbol(struct llext_loader *ldr, struct llext *ext, uintptr_t *
192192
LOG_ERR("Undefined symbol with no entry in "
193193
"symbol table %s, offset %zd, link section %d",
194194
name, (size_t)rel->r_offset, shdr->sh_link);
195+
196+
if (!IS_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES)) {
197+
/**
198+
* Attempting to import device objects from LLEXT but forgetting to
199+
* enable the corresponding Kconfig option will result in cryptic
200+
* dynamic linking errors. Try to detect this situation by checking
201+
* if the symbol's name starts with the prefix used to name device
202+
* objects, and print a special warning directing users towards the
203+
* missing Kconfig option in such circumstances.
204+
*/
205+
const char *const dev_prefix = STRINGIFY(DEVICE_NAME_GET(EMPTY));
206+
const int prefix_len = strlen(dev_prefix);
207+
208+
if (strncmp(name, dev_prefix, prefix_len) == 0) {
209+
LOG_WRN("(Device objects are not available for import "
210+
"because CONFIG_LLEXT_EXPORT_DEVICES is not enabled)");
211+
}
212+
}
195213
return -ENODATA;
196214
}
197215

0 commit comments

Comments
 (0)