This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new fb2b61ccbf7 libs/libc/tls: disable TLS_EMUTLS by default on
DEFAULT_SMALL
fb2b61ccbf7 is described below
commit fb2b61ccbf76bba2fae327da54bef7ba46ab0ed8
Author: Swatantra Yadav <[email protected]>
AuthorDate: Thu Nov 19 16:06:48 2026 +0530
libs/libc/tls: disable TLS_EMUTLS by default on DEFAULT_SMALL
PR #20723 added CONFIG_TLS_EMUTLS with 'default y'. To support LTO,
tools/Config.mk passes '-u __wrap___emutls_get_address' and
'-u __wrap___emutls_register_common', unconditionally forcing
tls_emutls.o and its dependencies (realloc, memmove, semaphores) into
every linked image, even when __thread variables are never used.
On memory-constrained targets (CONFIG_DEFAULT_SMALL=y), this wastes
up to ~1.5 KB of Flash. For example, on nucleo-f302r8 (DEFAULT_SMALL=y,
LTO_FULL=y):
CONFIG_TLS_EMUTLS=y: 23208 B Flash, 1160 B SRAM
CONFIG_TLS_EMUTLS=n: 21752 B Flash, 1120 B SRAM
Difference: -1456 B Flash (-6.7%).
This patch changes CONFIG_TLS_EMUTLS to default to !DEFAULT_SMALL,
saving Flash across small configurations while keeping emulated TLS
enabled by default on standard configurations. Targets requiring
per-thread __thread emulation can still explicitly enable it in their
defconfig.
Related to #20414
Fixes flash bloat reported in #20723
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swatantra Yadav <[email protected]>
---
Documentation/guides/concurrency/thread_local_storage.rst | 2 +-
boards/arm/stm32g4/nucleo-g431rb/configs/nsh/defconfig | 1 -
libs/libc/tls/Kconfig | 7 +++++--
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/Documentation/guides/concurrency/thread_local_storage.rst
b/Documentation/guides/concurrency/thread_local_storage.rst
index 5dd94fa1176..3db3738f400 100644
--- a/Documentation/guides/concurrency/thread_local_storage.rst
+++ b/Documentation/guides/concurrency/thread_local_storage.rst
@@ -44,6 +44,6 @@ Then you can see ``--disable-tls`` in the output, which means
that your compiler
In this case, you can still use the thread local relative keyword, but it
would be implemented by libgcc's emutls.
-NuttX's libc provides its own version (``CONFIG_TLS_EMUTLS``, set for the GCC
and clang toolchains when libgcc is the builtin library,
``CONFIG_BUILTIN_TOOLCHAIN``; the sim has it with GCC and the GNU linker, as on
Linux and MinGW), and the link sends the calls to ``__emutls_get_address()``
there with ``--wrap``. A libgcc built with the single thread model (``Thread
model: single`` above) keeps one copy of each variable for the whole program;
with the libc version, each thread gets its o [...]
+NuttX's libc provides its own version (``CONFIG_TLS_EMUTLS``, set for the GCC
and clang toolchains when libgcc is the builtin library,
``CONFIG_BUILTIN_TOOLCHAIN``; the sim has it with GCC and the GNU linker, as on
Linux and MinGW), and the link sends the calls to ``__emutls_get_address()``
there with ``--wrap``. A libgcc built with the single thread model (``Thread
model: single`` above) keeps one copy of each variable for the whole program;
with the libc version, each thread gets its o [...]
The image, the modules and the programs of a kernel build are linked with
``--wrap``; code loaded at run time finds the libc version in the system symbol
table (``CONFIG_EXECFUNCS_SYSTEM_SYMTAB``).
diff --git a/boards/arm/stm32g4/nucleo-g431rb/configs/nsh/defconfig
b/boards/arm/stm32g4/nucleo-g431rb/configs/nsh/defconfig
index 450de652923..c1e74ecbffc 100644
--- a/boards/arm/stm32g4/nucleo-g431rb/configs/nsh/defconfig
+++ b/boards/arm/stm32g4/nucleo-g431rb/configs/nsh/defconfig
@@ -9,7 +9,6 @@
# CONFIG_DISABLE_PTHREAD is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
-# CONFIG_TLS_EMUTLS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="nucleo-g431rb"
CONFIG_ARCH_BOARD_COMMON=y
diff --git a/libs/libc/tls/Kconfig b/libs/libc/tls/Kconfig
index 97ec20f5848..40561fdbe51 100644
--- a/libs/libc/tls/Kconfig
+++ b/libs/libc/tls/Kconfig
@@ -28,7 +28,7 @@ menu "Thread Local Storage (TLS)"
config TLS_EMUTLS
bool "Per-thread copies of emulated TLS variables"
- default y
+ default !DEFAULT_SMALL
depends on BUILTIN_TOOLCHAIN
depends on (ARCH_TOOLCHAIN_GNU && !ARCH_TOOLCHAIN_ARMCLANG &&
!ARCH_TOOLCHAIN_GHS && !ARCH_SIM) || (ARCH_SIM && SIM_TOOLCHAIN_GCC &&
!HOST_MACOS && !WINDOWS_NATIVE)
---help---
@@ -42,7 +42,10 @@ config TLS_EMUTLS
--wrap.
With LTO every program links this code (about 800 bytes on
- Cortex-M). A board that has no space for it can disable it:
then
+ Cortex-M). On memory-constrained targets (DEFAULT_SMALL=y),
+ it is disabled by default to save flash and avoid pulling
+ emulation routines into minimal images. A board that has no
+ space for it can disable it: then
all threads share one copy of each __thread variable, as with
libgcc.