Merge branch 'fix/newlib_builds' into 'master'

Fix: newlib compatibility with libraries built with picolibc headers

Closes IDF-15962

See merge request espressif/esp-idf!51013
This commit is contained in:
Alexey Lapshin
2026-08-04 14:41:32 +04:00
4 changed files with 14 additions and 6 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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)