From 0c28bbe3f87be6accae5fe1c6f1938102fe29d60 Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Wed, 29 Jul 2026 15:11:37 +0700 Subject: [PATCH] feat(libc): pass __PICOLIBC_ERRNO_FUNCTION to picolibc builds --- components/esp_libc/hints.yml | 4 ++++ components/esp_libc/project_include.cmake | 8 ++++++-- components/esp_libc/src/picolibc/errno.c | 5 ++--- components/esp_tee/subproject/main/common/syscall_stubs.c | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 components/esp_libc/hints.yml diff --git a/components/esp_libc/hints.yml b/components/esp_libc/hints.yml new file mode 100644 index 00000000000..e1261234fe1 --- /dev/null +++ b/components/esp_libc/hints.yml @@ -0,0 +1,4 @@ +- + re: "errno: TLS reference in ([^ ]+\\.a)\\([^)]*\\) mismatches non-TLS definition" + hint: "The library '{}' accessed errno as a TLS symbol, which is incompatible with CONFIG_LIBC_NEWLIB=y (errno via __errno()). Contact the library maintainer to rebuild it with the latest ESP-IDF, or pass -D__PICOLIBC_ERRNO_FUNCTION=__errno if the library is built outside ESP-IDF. Alternatively keep CONFIG_LIBC_PICOLIBC=y, which still provides the TLS errno symbol for older prebuilts." + match_to_output: True diff --git a/components/esp_libc/project_include.cmake b/components/esp_libc/project_include.cmake index 28c70ee0cf9..8bed57a5d9f 100644 --- a/components/esp_libc/project_include.cmake +++ b/components/esp_libc/project_include.cmake @@ -58,6 +58,10 @@ if(CONFIG_IDF_TOOLCHAIN_GCC) idf_toolchain_remove_flags(COMPILE_OPTIONS "-mdisable-hardware-atomics") endif() + idf_toolchain_remove_flags(COMPILE_OPTIONS "-specs=.*picolibc.*") + idf_toolchain_remove_flags(COMPILE_OPTIONS "-D__STDC_WANT_LIB_EXT1__=0") + # TODO GCC-495:remove + idf_toolchain_remove_flags(COMPILE_OPTIONS "-D__PICOLIBC_ERRNO_FUNCTION=__errno") if(CONFIG_LIBC_PICOLIBC) # TODO GCC-464: # The original picolibc.specs file cannot be used directly in the build @@ -69,11 +73,11 @@ if(CONFIG_IDF_TOOLCHAIN_GCC) # --gc-sections option. get_picolibc_specs_path(picolibc_specs_path) idf_toolchain_add_flags(COMPILE_OPTIONS "\"-specs=${picolibc_specs_path}\"") + # TODO GCC-495:remove + idf_toolchain_add_flags(COMPILE_OPTIONS "-D__PICOLIBC_ERRNO_FUNCTION=__errno") if(LIBC_PICOLIBC_NEWLIB_COMPATIBILITY) idf_toolchain_add_flags(COMPILE_OPTIONS "-D__STDC_WANT_LIB_EXT1__=0") endif() - else() - idf_toolchain_remove_flags(COMPILE_OPTIONS "-specs=.*picolibc.*") endif() if(CONFIG_LIBC_NEWLIB_NANO_FORMAT) diff --git a/components/esp_libc/src/picolibc/errno.c b/components/esp_libc/src/picolibc/errno.c index 67479c0ed7f..1f70a6abaaf 100644 --- a/components/esp_libc/src/picolibc/errno.c +++ b/components/esp_libc/src/picolibc/errno.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,11 +12,10 @@ * 'errno' is defined in the TDATA section. The linker script ensures that * it is positioned at the beginning of the TDATA segment. */ +#undef errno __thread int errno __attribute__((section(".tdata.errno"))) = 0; -#if CONFIG_LIBC_PICOLIBC_NEWLIB_COMPATIBILITY int *__errno(void) { return &errno; } -#endif diff --git a/components/esp_tee/subproject/main/common/syscall_stubs.c b/components/esp_tee/subproject/main/common/syscall_stubs.c index 5e667f2ebee..560dd01ee87 100644 --- a/components/esp_tee/subproject/main/common/syscall_stubs.c +++ b/components/esp_tee/subproject/main/common/syscall_stubs.c @@ -113,6 +113,7 @@ void IRAM_ATTR syscall_exit_tee(void) * 'errno' is defined in the TDATA section. The linker script ensures that * it is positioned at the beginning of the TDATA segment. */ +#undef errno __thread int errno __attribute__((section(".tdata.errno"))) = 0; int *__errno(void)