Skip to content

Commit bd09a5c

Browse files
lyakhnashif
authored andcommitted
llext: make EXPORT_SYMBOL() universal
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 <[email protected]>
1 parent 92a7c77 commit bd09a5c

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

include/zephyr/llext/symbol.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ struct llext_symtable {
8787
};
8888

8989

90+
/**
91+
* @brief Exports a symbol from an extension to the base image
92+
*
93+
* This macro can be used in extensions to add a symbol (function or object)
94+
* to the extension's exported symbol table, so that it may be referenced by
95+
* the base image.
96+
*
97+
* @param x Extension symbol to export to the base image
98+
*/
99+
#if defined(CONFIG_LLEXT) && defined(LL_EXTENSION_BUILD)
100+
#define LL_EXTENSION_SYMBOL(x) \
101+
static const struct llext_const_symbol \
102+
Z_GENERIC_SECTION(".exported_sym") __used \
103+
x ## _sym = { \
104+
.name = STRINGIFY(x), .addr = (const void *)&x, \
105+
}
106+
#else
107+
#define LL_EXTENSION_SYMBOL(x)
108+
#endif
109+
90110
/**
91111
* @brief Export a constant symbol to extensions
92112
*
@@ -96,7 +116,9 @@ struct llext_symtable {
96116
*
97117
* @param x Symbol to export to extensions
98118
*/
99-
#if defined(CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID)
119+
#if defined(LL_EXTENSION_BUILD)
120+
#define EXPORT_SYMBOL(x) LL_EXTENSION_SYMBOL(x)
121+
#elif defined(CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID)
100122
#define EXPORT_SYMBOL(x) \
101123
static const char Z_GENERIC_SECTION("llext_exports_strtab") __used \
102124
x ## _sym_name[] = STRINGIFY(x); \
@@ -112,26 +134,6 @@ struct llext_symtable {
112134
#define EXPORT_SYMBOL(x)
113135
#endif
114136

115-
/**
116-
* @brief Exports a symbol from an extension to the base image
117-
*
118-
* This macro can be used in extensions to add a symbol (function or object)
119-
* to the extension's exported symbol table, so that it may be referenced by
120-
* the base image.
121-
*
122-
* @param x Extension symbol to export to the base image
123-
*/
124-
#if defined(CONFIG_LLEXT) && defined(LL_EXTENSION_BUILD)
125-
#define LL_EXTENSION_SYMBOL(x) \
126-
static const struct llext_const_symbol \
127-
Z_GENERIC_SECTION(".exported_sym") __used \
128-
x ## _sym = { \
129-
.name = STRINGIFY(x), .addr = (const void *)&x, \
130-
}
131-
#else
132-
#define LL_EXTENSION_SYMBOL(x)
133-
#endif
134-
135137
/**
136138
* @}
137139
*/

0 commit comments

Comments
 (0)