llext: disable LL_EXTENSION_SYMBOL when not building an llext

The LL_EXTENSION_SYMBOL macro is used to export a symbol to the base
image. When CONFIG_LLEXT is not defined, or the file is being compiled
outside of an llext, the macro is not useful and would leave orphan
sections in the final image instead.

This patch adds the LL_EXTENSION_BUILD definition to the llext build
process, and uses it to stub out the symbol-defining macro when not
building an llext.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2024-06-12 18:32:49 +02:00 committed by Alberto Escolar
commit baa3b6a5ba
2 changed files with 5 additions and 0 deletions

View file

@ -5394,6 +5394,7 @@ function(add_llext_target target_name)
target_compile_definitions(${llext_lib_target} PRIVATE
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>
LL_EXTENSION_BUILD
)
target_compile_options(${llext_lib_target} PRIVATE
${zephyr_filtered_flags}

View file

@ -114,12 +114,16 @@ struct llext_symtable {
*
* @param x Extension symbol to export to the base image
*/
#if defined(CONFIG_LLEXT) && defined(LL_EXTENSION_BUILD)
#define LL_EXTENSION_SYMBOL(x) \
static const struct llext_const_symbol \
Z_GENERIC_SECTION(".exported_sym") __used \
x ## _sym = { \
.name = STRINGIFY(x), .addr = (const void *)&x, \
}
#else
#define LL_EXTENSION_SYMBOL(x)
#endif
/**
* @}