Zephyr Project API 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
symbol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_LLEXT_SYMBOL_H
8#define ZEPHYR_LLEXT_SYMBOL_H
9
11#include <zephyr/toolchain.h>
12#include <stddef.h>
13#include <stdint.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
47 union {
49 const char *const name;
50
53 };
54
56 const void *const addr;
57};
58BUILD_ASSERT(sizeof(struct llext_const_symbol) == 2 * sizeof(uintptr_t));
59
69 const char *name;
70
72 void *addr;
73};
74
75
83 size_t sym_cnt;
84
87};
88
89
91#ifdef LL_EXTENSION_BUILD
92/* Extension build: add exported symbols to llext table */
93#define Z_LL_EXTENSION_SYMBOL_NAMED(sym_ident, sym_name) \
94 static const struct llext_const_symbol \
95 Z_GENERIC_SECTION(.exported_sym) __used \
96 __llext_sym_ ## sym_name = { \
97 .name = STRINGIFY(sym_name), .addr = (const void *)&sym_ident, \
98 }
99#else
100/* No-op when not building an extension */
101#define Z_LL_EXTENSION_SYMBOL_NAMED(sym_ident, sym_name)
102#endif
114#define LL_EXTENSION_SYMBOL_NAMED(sym_ident, sym_name) \
115 Z_LL_EXTENSION_SYMBOL_NAMED(sym_ident, sym_name)
116
128#define LL_EXTENSION_SYMBOL(x) Z_LL_EXTENSION_SYMBOL_NAMED(x, x)
129
131#if defined(LL_EXTENSION_BUILD)
132/* Extension build: EXPORT_SYMBOL maps to LL_EXTENSION_SYMBOL */
133#define Z_EXPORT_SYMBOL_NAMED(sym_ident, sym_name) \
134 Z_LL_EXTENSION_SYMBOL_NAMED(sym_ident, sym_name)
135#elif defined(CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID)
136/* SLID-enabled LLEXT application: export symbols, names in separate section */
137#define Z_EXPORT_SYMBOL_NAMED(sym_ident, sym_name) \
138 static const char Z_GENERIC_SECTION(llext_exports_strtab) __used \
139 __llext_sym_name_ ## sym_name[] = STRINGIFY(sym_name); \
140 static const STRUCT_SECTION_ITERABLE(llext_const_symbol, \
141 __llext_sym_ ## sym_name) = { \
142 .name = __llext_sym_name_ ## sym_name, \
143 .addr = (const void *)&sym_ident, \
144 }
145#elif defined(CONFIG_LLEXT)
146/* LLEXT application: export symbols */
147#define Z_EXPORT_SYMBOL_NAMED(sym_ident, sym_name) \
148 static const STRUCT_SECTION_ITERABLE(llext_const_symbol, \
149 __llext_sym_ ## sym_name) = { \
150 .name = STRINGIFY(sym_name), .addr = (const void *)&sym_ident, \
151 }
152#else
153/* No extension support in this build */
154#define Z_EXPORT_SYMBOL_NAMED(sym_ident, sym_name)
155#endif
169#define EXPORT_SYMBOL_NAMED(sym_ident, sym_name) \
170 Z_EXPORT_SYMBOL_NAMED(sym_ident, sym_name)
171
183#define EXPORT_SYMBOL(x) EXPORT_SYMBOL_NAMED(x, x)
184
189#ifdef __cplusplus
190}
191#endif
192
193
194#endif /* ZEPHYR_LLEXT_SYMBOL_H */
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Constant symbols are unchangeable named memory addresses.
Definition symbol.h:42
const char *const name
Name of symbol.
Definition symbol.h:49
const void *const addr
Address of symbol.
Definition symbol.h:56
const uintptr_t slid
Symbol Link Identifier.
Definition symbol.h:52
Symbols are named memory addresses.
Definition symbol.h:67
const char * name
Name of symbol.
Definition symbol.h:69
void * addr
Address of symbol.
Definition symbol.h:72
A symbol table.
Definition symbol.h:81
size_t sym_cnt
Number of symbols in the table.
Definition symbol.h:83
struct llext_symbol * syms
Array of symbols.
Definition symbol.h:86
Macros to abstract toolchain specific capabilities.