Skip to content

Commit 38722ec

Browse files
pillo79carlescufi
authored andcommitted
llext: add wrapper to EXPORT_SYMBOL / LL_EXTENSION_SYMBOL
This patch adds an indirection level moving the current code from inside the EXPORT_SYMBOL and LL_EXTENSION_SYMBOL macros to private Z_* macros. This is done to allow for the official APIs to properly expand more complex arguments, such as the DT function-like macros. Signed-off-by: Luca Burelli <[email protected]>
1 parent ca5f24e commit 38722ec

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

include/zephyr/llext/symbol.h

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,52 +87,70 @@ 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) \
90+
/** @cond ignore */
91+
#ifdef LL_EXTENSION_BUILD
92+
/* Extension build: add exported symbols to llext table */
93+
#define Z_LL_EXTENSION_SYMBOL(x) \
10194
static const struct llext_const_symbol \
10295
Z_GENERIC_SECTION(".exported_sym") __used \
10396
x ## _sym = { \
10497
.name = STRINGIFY(x), .addr = (const void *)&x, \
10598
}
10699
#else
107-
#define LL_EXTENSION_SYMBOL(x)
100+
/* No-op when not building an extension */
101+
#define Z_LL_EXTENSION_SYMBOL(x)
108102
#endif
103+
/** @endcond */
109104

110105
/**
111-
* @brief Export a constant symbol to extensions
106+
* @brief Exports a symbol from an extension to the base image
112107
*
113-
* Takes a symbol (function or object) by symbolic name and adds the name
114-
* and address of the symbol to a table of symbols that may be referenced
115-
* by extensions.
108+
* This macro can be used in extensions to add a symbol (function or object)
109+
* to the extension's exported symbol table, so that it may be referenced by
110+
* the base image.
116111
*
117-
* @param x Symbol to export to extensions
112+
* When not building an extension, this macro is a no-op.
113+
*
114+
* @param x Extension symbol to export to the base image
118115
*/
116+
#define LL_EXTENSION_SYMBOL(x) Z_LL_EXTENSION_SYMBOL(x)
117+
118+
/** @cond ignore */
119119
#if defined(LL_EXTENSION_BUILD)
120-
#define EXPORT_SYMBOL(x) LL_EXTENSION_SYMBOL(x)
120+
/* Extension build: EXPORT_SYMBOL maps to LL_EXTENSION_SYMBOL */
121+
#define Z_EXPORT_SYMBOL(x) Z_LL_EXTENSION_SYMBOL(x)
121122
#elif defined(CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID)
122-
#define EXPORT_SYMBOL(x) \
123+
/* SLID-enabled LLEXT application: export symbols, names in separate section */
124+
#define Z_EXPORT_SYMBOL(x) \
123125
static const char Z_GENERIC_SECTION("llext_exports_strtab") __used \
124126
x ## _sym_name[] = STRINGIFY(x); \
125127
static const STRUCT_SECTION_ITERABLE(llext_const_symbol, x ## _sym) = { \
126128
.name = x ## _sym_name, .addr = (const void *)&x, \
127129
}
128130
#elif defined(CONFIG_LLEXT)
129-
#define EXPORT_SYMBOL(x) \
131+
/* LLEXT application: export symbols */
132+
#define Z_EXPORT_SYMBOL(x) \
130133
static const STRUCT_SECTION_ITERABLE(llext_const_symbol, x ## _sym) = { \
131134
.name = STRINGIFY(x), .addr = (const void *)&x, \
132135
}
133136
#else
134-
#define EXPORT_SYMBOL(x)
137+
/* No extension support in this build */
138+
#define Z_EXPORT_SYMBOL(x)
135139
#endif
140+
/** @endcond */
141+
142+
/**
143+
* @brief Export a constant symbol from the current build
144+
*
145+
* Takes a symbol (function or object) by symbolic name and adds the name
146+
* and address of the symbol to a table of symbols that may be referenced
147+
* by extensions or by the base image, depending on the current build type.
148+
*
149+
* When @c CONFIG_LLEXT is not enabled, this macro is a no-op.
150+
*
151+
* @param x Symbol to export
152+
*/
153+
#define EXPORT_SYMBOL(x) Z_EXPORT_SYMBOL(x)
136154

137155
/**
138156
* @}

0 commit comments

Comments
 (0)