llext: add support for SLID-based linking

This commit introduces support for an alternate linking method in the
LLEXT subsystem, called "SLID" (short for Symbol Link Identifier),
enabled by the CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID Kconfig option.

SLID-based linking uses a unique identifier (integer) to identify
exported symbols, instead of using the symbol name as done currently.
This approach provides several benefits:
 * linking is faster because the comparison operation to determine
   whether we found the correct symbol in the export table is now an
   integer compare, instead of a string compare
 * binary size is reduced as symbol names can be dropped from the binary
 * confidentiality is improved as a side-effect, as symbol names are no
   longer present in the binary

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
This commit is contained in:
Mathieu Choplain 2024-05-06 13:03:26 +02:00 committed by Anas Nashif
commit 8aa6ae43ce
45 changed files with 981 additions and 7 deletions

View file

@ -24,6 +24,20 @@ LOG_MODULE_REGISTER(test_llext_simple);
#define LLEXT_CONST const
#endif
#ifdef CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID
#define LLEXT_FIND_BUILTIN_SYM(symbol_name) llext_find_sym(NULL, symbol_name ## _SLID)
#ifdef CONFIG_64BIT
#define printk_SLID ((const char *)0x87B3105268827052ull)
#define z_impl_ext_syscall_fail_SLID ((const char *)0xD58BC0E7C64CD965ull)
#else
#define printk_SLID ((const char *)0x87B31052ull)
#define z_impl_ext_syscall_fail_SLID ((const char *)0xD58BC0E7ull)
#endif
#else
#define LLEXT_FIND_BUILTIN_SYM(symbol_name) llext_find_sym(NULL, # symbol_name)
#endif
struct llext_test {
const char *name;
bool try_userspace;
@ -271,7 +285,7 @@ ZTEST(llext, test_pre_located)
*/
ZTEST(llext, test_printk_exported)
{
const void * const printk_fn = llext_find_sym(NULL, "printk");
const void * const printk_fn = LLEXT_FIND_BUILTIN_SYM(printk);
zassert_equal(printk_fn, printk, "printk should be an exported symbol");
}
@ -282,8 +296,9 @@ ZTEST(llext, test_printk_exported)
*/
ZTEST(llext, test_ext_syscall_fail)
{
const void * const esf_fn = llext_find_sym(NULL,
"z_impl_ext_syscall_fail");
const void * const esf_fn = LLEXT_FIND_BUILTIN_SYM(z_impl_ext_syscall_fail);
zassert_not_null(esf_fn, "est_fn should not be NULL");
zassert_is_null(*(uintptr_t **)esf_fn, NULL,
"ext_syscall_fail should be NULL");

View file

@ -80,3 +80,71 @@ tests:
- CONFIG_USERSPACE=y
- CONFIG_MODULES=y
- CONFIG_LLEXT_TEST_HELLO=m
llext.simple.readonly_slid_linking:
arch_exclude: xtensa # for now
filter: not CONFIG_MPU and not CONFIG_MMU and not CONFIG_SOC_SERIES_S32ZE
extra_configs:
- arch:arm:CONFIG_ARM_MPU=n
- CONFIG_LLEXT_STORAGE_WRITABLE=n
- CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID=y
llext.simple.readonly_mpu_slid_linking:
min_ram: 128
arch_exclude: xtensa # for now
filter: CONFIG_ARCH_HAS_USERSPACE
extra_configs:
- CONFIG_USERSPACE=y
- CONFIG_LLEXT_STORAGE_WRITABLE=n
- CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID=y
llext.simple.writable_slid_linking:
filter: not CONFIG_MPU and not CONFIG_MMU and not CONFIG_SOC_SERIES_S32ZE
extra_configs:
- arch:arm:CONFIG_ARM_MPU=n
- CONFIG_LLEXT_STORAGE_WRITABLE=y
llext.simple.modules_enabled_writable_slid_linking:
filter: not CONFIG_MPU and not CONFIG_MMU
platform_key:
- simulation
- arch
platform_exclude:
- qemu_cortex_a9 # MMU
extra_configs:
- arch:arm:CONFIG_ARM_MPU=n
- CONFIG_MODULES=y
- CONFIG_LLEXT_STORAGE_WRITABLE=y
- CONFIG_LLEXT_TEST_HELLO=m
- CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID=y
llext.simple.modules_enabled_writable_relocatable_slid_linking:
arch_exclude: arm arm64
filter: not CONFIG_MPU and not CONFIG_MMU
integration_platforms:
- qemu_xtensa
extra_configs:
- CONFIG_MODULES=y
- CONFIG_LLEXT_STORAGE_WRITABLE=y
- CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y
- CONFIG_LLEXT_TEST_HELLO=m
- CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID=y
llext.simple.modules_enabled_readonly_slid_linking:
filter: not CONFIG_MPU and not CONFIG_MMU
arch_exclude: xtensa # for now
platform_key:
- simulation
- arch
platform_exclude:
- qemu_cortex_a9 # MMU
extra_configs:
- arch:arm:CONFIG_ARM_MPU=n
- CONFIG_MODULES=y
- CONFIG_LLEXT_TEST_HELLO=m
- CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID=y
llext.simple.modules_enabled_readonly_mpu_slid_linking:
filter: CONFIG_ARCH_HAS_USERSPACE
arch_exclude: xtensa # for now
platform_key:
- simulation
- arch
extra_configs:
- CONFIG_USERSPACE=y
- CONFIG_MODULES=y
- CONFIG_LLEXT_TEST_HELLO=m
- CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID=y