From f93a0d9ff2e5aa338605d9ed14db5dcd57a628d6 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 14 Oct 2025 09:55:00 +0200 Subject: [PATCH] fix(esp_libc/cmake): add vfs as requirement if CONFIG_VFS_SUPPORT_IO is enabled The esp_libc relies on the stdio implementation of the vfs component if CONFIG_VFS_SUPPORT_IO is enabled. This is not an issue in cmakev1 because if the vfs component is not included in the project build, its configuration is not available, and CONFIG_VFS_SUPPORT_IO is not set. However, in cmakev2, the configuration for all components is available, and the presence of some component configuration options does not necessarily mean that the component is included in the project build. When esp_libc is compiled without the vfs dependency but with CONFIG_VFS_SUPPORT_IO enabled, the libc initialization will encounter a panic due to a NULL pointer dereference (fp->_flags) in __swsetup_r, as fopen in esp_libc_init_global_stdio will return NULL. --- components/esp_libc/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/esp_libc/CMakeLists.txt b/components/esp_libc/CMakeLists.txt index 3c354f2932..9aaebf5825 100644 --- a/components/esp_libc/CMakeLists.txt +++ b/components/esp_libc/CMakeLists.txt @@ -77,10 +77,18 @@ else() list(APPEND ldfragments src/picolibc/libc.lf) endif() +set(priv_reqs soc spi_flash) + +if(IDF_BUILD_V2) + if(CONFIG_VFS_SUPPORT_IO) + list(APPEND priv_reqs vfs) + endif() +endif() + idf_component_register(SRCS "${srcs}" INCLUDE_DIRS platform_include PRIV_INCLUDE_DIRS priv_include - PRIV_REQUIRES soc spi_flash + PRIV_REQUIRES "${priv_reqs}" LDFRAGMENTS "${ldfragments}") # Toolchain libraries require code defined in this component