From 9fc26804fb5cdd6c1826c4afc3af4eefce74c429 Mon Sep 17 00:00:00 2001 From: Daniel Apperloo Date: Fri, 3 May 2024 01:55:49 +0000 Subject: [PATCH] linker: decouple KERNEL_WHOLE_ARCHIVE from LLEXT Dynamic code execution applications not using LLEXT for "extension" loading are subject to the same linker optimization symbol resolution issue described in commit 321e395 (in summary, libkernel.a syscalls not used directly by the application result in weak symbol resolution of their z_mrsh_ wrapper). To support usecases where an application is using alternative methods to load and execute code calling syscalls (likely from userspace) or is using a mechanism where the linker may not be aware, the configuration option has been decoupled from CONFIG_LLEXT (who is now a selector) to KERNEL_WHOLE_ARCHIVE. Signed-off-by: Daniel Apperloo --- CMakeLists.txt | 2 +- kernel/Kconfig | 6 ++++++ subsys/llext/Kconfig | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b589ac43159..2fa2d371c4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -906,7 +906,7 @@ foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) add_dependencies(${zephyr_lib} zephyr_generated_headers) endforeach() -if(CONFIG_LLEXT) +if(CONFIG_KERNEL_WHOLE_ARCHIVE) set(WHOLE_ARCHIVE_LIBS ${ZEPHYR_LIBS_PROPERTY} kernel) else() set(WHOLE_ARCHIVE_LIBS ${ZEPHYR_LIBS_PROPERTY}) diff --git a/kernel/Kconfig b/kernel/Kconfig index af51267edbf..767c04f94fe 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -1020,6 +1020,12 @@ config THREAD_LOCAL_STORAGE help This option enables thread local storage (TLS) support in kernel. +config KERNEL_WHOLE_ARCHIVE + bool + help + This option forces every object file in the libkernel.a archive + to be included, rather than searching the archive for required object files. + endmenu rsource "Kconfig.device" diff --git a/subsys/llext/Kconfig b/subsys/llext/Kconfig index c96017c79c9..085ef775569 100644 --- a/subsys/llext/Kconfig +++ b/subsys/llext/Kconfig @@ -4,6 +4,7 @@ menuconfig LLEXT bool "Linkable loadable extensions" select CACHE_MANAGEMENT if DCACHE + select KERNEL_WHOLE_ARCHIVE help Enable the linkable loadable extension subsystem