From df1b1dea29405e27a86b0d74d43674e45cb557ac 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 | 10 +++++++--- components/esp_libc/src/picolibc/errno.c | 5 ++--- .../esp_tee/subproject/main/common/syscall_stubs.c | 1 + 4 files changed, 14 insertions(+), 6 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 71dba137c5c..2d1ae513416 100644 --- a/components/esp_libc/project_include.cmake +++ b/components/esp_libc/project_include.cmake @@ -11,13 +11,17 @@ if(CONFIG_IDF_TOOLCHAIN_GCC) idf_toolchain_remove_flags(COMPILE_OPTIONS "-mdisable-hardware-atomics") endif() + idf_toolchain_remove_flags(COMPILE_OPTIONS "-specs=picolibc.specs") + 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) idf_toolchain_add_flags(COMPILE_OPTIONS "-specs=picolibc.specs") - if(LIBC_PICOLIBC_NEWLIB_COMPATIBILITY) + # TODO GCC-495:remove + idf_toolchain_add_flags(COMPILE_OPTIONS "-D__PICOLIBC_ERRNO_FUNCTION=__errno") + if(CONFIG_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.specs") 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)