From eb024b655fa78bc3e698fc0086ca362e124562c3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 4 Oct 2023 09:17:27 -0700 Subject: [PATCH] libc: Control Z_LIBC_PARTITION_EXISTS from Kconfig Instead of adding every possible subsystem which places variables in the C library memory partition in libc-hooks.h, place those conditions in the related Kconfig files and simplify the libc-hooks.h to just looking at CONFIG_NEED_LIBC_MEM_PARTITION. Signed-off-by: Keith Packard --- include/zephyr/sys/libc-hooks.h | 4 +--- kernel/Kconfig | 1 + lib/libc/Kconfig | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/zephyr/sys/libc-hooks.h b/include/zephyr/sys/libc-hooks.h index d1a1afcbf40..e00efc6de26 100644 --- a/include/zephyr/sys/libc-hooks.h +++ b/include/zephyr/sys/libc-hooks.h @@ -92,9 +92,7 @@ __syscall size_t zephyr_fwrite(const void *ZRESTRICT ptr, size_t size, extern struct k_mem_partition z_malloc_partition; #endif -#if defined(CONFIG_NEWLIB_LIBC) || (defined(CONFIG_STACK_CANARIES) && \ - !defined(CONFIG_STACK_CANARIES_TLS)) || \ -defined(CONFIG_PICOLIBC) || defined(CONFIG_NEED_LIBC_MEM_PARTITION) +#ifdef CONFIG_NEED_LIBC_MEM_PARTITION /* - All newlib globals will be placed into z_libc_partition. * - Minimal C library globals, if any, will be placed into * z_libc_partition. diff --git a/kernel/Kconfig b/kernel/Kconfig index b2dde710121..2178b041cfd 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -975,6 +975,7 @@ menu "Security Options" config STACK_CANARIES bool "Compiler stack canaries" depends on ENTROPY_GENERATOR || TEST_RANDOM_GENERATOR + select NEED_LIBC_MEM_PARTITION if !STACK_CANARIES_TLS help This option enables compiler stack canaries. diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 3bb83af5b1e..4ebf556dd5c 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -74,6 +74,7 @@ config PICOLIBC select COMMON_LIBC_ABORT select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE select LIBC_ERRNO if THREAD_LOCAL_STORAGE + select NEED_LIBC_MEM_PARTITION imply COMMON_LIBC_MALLOC depends on !NATIVE_APPLICATION depends on PICOLIBC_SUPPORTED @@ -87,6 +88,7 @@ config NEWLIB_LIBC select COMMON_LIBC_ABORT depends on !NATIVE_APPLICATION depends on NEWLIB_LIBC_SUPPORTED + select NEED_LIBC_MEM_PARTITION help Build with newlib library. The newlib library is expected to be part of the SDK in this case.